필터 지우기
필터 지우기

angle calculation in 3D space

조회 수: 9 (최근 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 CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by