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.
angle calculation in 3D space
조회 수: 9 (최근 30일)
이전 댓글 표시
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!
채택된 답변
Sean de Wolski
2011년 7월 13일
Your equation looks right to me. Well, that is it looks like what Roger recommends frequently:
댓글 수: 0
추가 답변 (1개)
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].
참고 항목
카테고리
Help Center 및 File Exchange에서 Assembly에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!