Why I'm getting a complex degree value while using "acos"?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
% To reproduce the snippet, you can use below code
XYZc = [2489011.31135707, 7440368.1011554, 17.6551714555564];
X0 = 2489018.662
X0 = 2.4890e+06
Y0 = 7440333.989
Y0 = 7.4403e+06
Z0= 10.091
Z0 = 10.0910
dir_vec1 = XYZc-[X0, Y0, Z0];
dir_mag1= norm(dir_vec1);
dir_vec2 = [0,XYZc(2),0]-[X0, Y0, Z0];
dir_mag2= norm(dir_vec2);
alpha = acosd(dir_mag2/dir_mag1)
alpha = 0.0000e+00 + 6.7868e+02i
1 件のコメント
Matt J
2023 年 6 月 10 日
I have edited your post for you to make your code output visible. It is always advisable to do this so we can see what output you are talking about.
採用された回答
Because abs(dir_mag2/dir_mag1) is greater than 1.
abs(dir_mag2/dir_mag1)
ans = 6.9710e+04
13 件のコメント
Matt J
2023 年 6 月 10 日
There is no problem to be solved. It is the correct result.
@Matt J I think it is incorrect, because I was looking for a reseanoble angle. Do you think normalization would work?
Matt J
2023 年 6 月 10 日
What I mean is, it is not Matlab's fault. It is doing what you asked, correctly. Matlab has no way of knowing, just as I do not, what you were really trying to code.
Torsten
2023 年 6 月 10 日
In a right-angled triangle, the hypotenuse is always longer than the adjacant. So if you think dir_mag2 is the length of the adjacant and dir_mag1 is the length of the hypothenuse in the triangle you consider, you must have done something wrong.
If you want the angle between dir_vec1 and dir_vec2, it would be,
acosd( dot( dir_vec1/dir_mag1 , dir_vec2/dir_mag2 ) )
Otherwise, you haven't said enough for us to guess what angle your input data is supposed to define.
Abb
2023 年 6 月 10 日
@Matt J @Torsten thanks both of you, to calify, I want to compute this angle(screenshot), based on this equation, it gets me 78 degree, but visually it looks like a smaller angle that this value?!. Maybe something wrong, do you have any idea?
% i ran this code
vec1 = XYZc-[X0, Y0, Z0];
vec2 = [0,XYZc(2),0]-[X0, Y0, Z0];
acosd(dot(vec1, vec2) / (norm(vec1)*norm(vec2)))

Looks like 78° :-)
XYZc = [2489011.31135707, 7440368.1011554, 17.6551714555564];
X0 = 2489018.662
X0 = 2.4890e+06
Y0 = 7440333.989
Y0 = 7.4403e+06
Z0= 10.091
Z0 = 10.0910
dir_vec1 = XYZc-[X0, Y0, Z0];
dir_mag1= norm(dir_vec1);
dir_vec2 = [0,XYZc(2),0]-[X0, Y0, Z0];
dir_mag2= norm(dir_vec2);
plot3([0 dir_vec1(1)]/dir_mag1,[0,dir_vec1(2)]/dir_mag1,[ 0,dir_vec1(3)]/dir_mag1)
hold on
plot3([0 dir_vec2(1)]/dir_mag2,[0,dir_vec2(2)]/dir_mag2,[ 0,dir_vec2(3)]/dir_mag2)

Matt J
2023 年 6 月 10 日
You're welcome, but please Accept-click the answer to indicate that it resolved your question.
Image Analyst
2023 年 6 月 11 日
It's not in the comments, neither his nor yours. It should be above, at the very first answer post of @Matt J
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

