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
6 views (last 30 days)
Show older comments
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!
Accepted Answer
Sean de Wolski
on 13 Jul 2011
Your equation looks right to me. Well, that is it looks like what Roger recommends frequently:
0 Comments
More Answers (1)
Jan
on 13 Jul 2011
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].
See Also
Categories
Find more on Assembly in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!