フィルターのクリア

angle calculation in 3D space

6 ビュー (過去 30 日間)
Iman Alsharkawi
Iman Alsharkawi 2011 年 7 月 13 日
Let's say I have a point, t1(x1 y1 z1) somewhere in space. And I have another point g1(x2 y2 z2) that lies on a plane somewhere in space. If I have the normal direction associated with that plane,and I want to calculate the angle of point t1 relative to that plane at point g1, is the following code legit? (basically finding the angle between the vector g1-t1 and the normal of the plane)And does my vector from g1 to t1 have to be normalized? Or the normal direction of the plane, for that matter?
t1 = [1 4 3];
g1 = [2 4 3];
% normal associated with g1
n1 = [-1 0 0]; %<-- does this have to be normalized??
% get vector from g1 to t1:
v1 = g1-t1;
angle = atan2(norm(cross(v1,n1)),dot(v1,n1)).*(180/pi)
Thanks!
  1 件のコメント
Iman Alsharkawi
Iman Alsharkawi 2011 年 7 月 13 日
Clearly it's been a long day for me. I think it just dawned on me that the normalization doesn't have to happen because all I care about are the directions of the vectors. But, I'd still like feedback on my method for calculating the angle.

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2011 年 7 月 13 日
Your equation looks right to me. Well, that is it looks like what Roger recommends frequently:

その他の回答 (1 件)

Jan
Jan 2011 年 7 月 13 日
You can try it:
v = [1 4 3];
n = [-1 0 0];
angle1 = atan2(norm(cross(v,n)), dot(v,n)).*(180/pi)
n = [-1000 0 0];
angle2 = atan2(norm(cross(v,n)), dot(v,n)).*(180/pi)
I did not use g1 - t1, because it is [1,0,0] by accident, which might hide problems.
Usually this kind of gunshot debugging is not reliable. But if it helps... ;-)
Take into account, that a normalization can help to control rounding errors, even if the algorithm does not demands for a normalization mathematically, e.g. if n is [1e12, 0, 0] or [1e-12, 0, 0].
  1 件のコメント
Iman Alsharkawi
Iman Alsharkawi 2011 年 7 月 13 日
=) like I said... it's been a long day... Thanks to both of you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAssembly についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by