Computing Angles from Coordinate Space

1 view (last 30 days)
Dan
Dan on 10 Dec 2014
Commented: Roger Stafford on 12 Dec 2014
Hello all,
I once again turn for you for help in solving what may very well be a simple solution.
The problem:
Given two feature vectors ( V1(x,y,z) and V2(x,y,z) ) that are expressed in meters extract a 2DOF (x,z) angle to represent the angle between V1 and v2.
What I've done so far:
I may have totally misunderstood the problem I am having and massively over complicated matters and gone down a totally incorrect path.
v = cross(X1, X2); %axis of rotation
angle = dot(X1,X2)/3; %cosine angle of rotation
angle = acos(cos(angle));
xx = v(1) * v(1);
yy = v(2) * v(2);
zz = v(3) * v(3);
heading = atan2(v(2) * sin(angle)- v(1) * v(3) * (1 - cos(angle)) , 1 - (yy + zz ) * (1 - cos(angle)));
attitude = asin(v(1) * v(2) * (1 - cos(angle)) + v(3) * sin(angle));
bank = atan2(v(1) * sin(angle)-v(2) * v(3) * (1 - cos(angle)) , 1 - (xx + zz) * (1 - cos(angle)));
Thanks
Dan
  1 Comment
Matt J
Matt J on 10 Dec 2014
You haven't said what problem you're encountering, i.e., what you don't like about the result of your current code.

Sign in to comment.

Answers (1)

Roger Stafford
Roger Stafford on 10 Dec 2014
The two lines
angle = dot(X1,X2)/3; %cosine angle of rotation
angle = acos(cos(angle));
don't make sense to me. On the first of these lines you seem to be assuming that the product of the norms of X1 and X2 is 3. Is that true? Then on the second line you take the cosine of a quantity that is presumably already the cosine of an angle and then take its arccosine again. Such operations do not give you an angle and yet you later treat it as if it were an angle.
  2 Comments
Dan
Dan on 12 Dec 2014
Hi Roger,
Thanks for your reply. As the post suggests. This is an attempt by me to solve the problem. However, I highly suspect my approach is not correct. I was hoping to have some guidance from the community. Having made an attempt myself, and knowing it isn't correct I wanted to reach out for help!
Dan
Roger Stafford
Roger Stafford on 12 Dec 2014
You can find the angle in radians between two 3D vectors, V1 and V2, this way:
ang = atan2(norm(cross(V1,V2)),dot(V1,V2));
The answer will lie between 0 and +pi. This is more accurate than using 'acos'.
As for the rest of your proposed computations, I could not tell from your code what 'heading', 'altitude', and 'bank' refer to. Perhaps you should explain the situation in ordinary English instead of matlab code to see if the latter is valid.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!