Prev: how to determine if the shortest distance from one point to a line is inside the line segment or outside
Next: help
From: Roger Stafford on 8 Jul 2010 20:09 "Natalie Sin Hwee " <sin.ng09(a)imperial.ac.uk> wrote in message <i15ge0$91n$1(a)fred.mathworks.com>... > Sorry i forgot to ask, > > If i was to apply this into 3D, > > how can i apply ang = mod( atan2( det([v1;v2]) , dot(v1,v2) ) , 2*pi ); > if e.g. > v1= [1,2,3] > v2= [4,5,6] > I tried but it says: > > ??? Error using ==> det > Matrix must be square. > > Thanks > Natalie - - - - - - - - - - As I mentioned earlier, in three dimensional space you will have to give up the notion of clockwise/counterclockwise rotation. If you have a vector on the earth pointing from earth center to Sydney, Australia and another pointing to Tokyo, there is no clockwise/counterclockwise criterion for deciding which is the "positive" way to rotate. Because of this, the usual convention is that the angle between the vectors is considered to be the smaller of the two angles in a full great circle containing two cities. Such an angle is always between 0 and pi, which is to say that it always lies in the first two quadrants. The other possible angle in the great circle of course then lies in the third or fourth quadrants, with the sum of these two being 2*pi. In three dimensions if va and vb are the vectors, the above (smaller) angle is given by: ang = atan2( norm(cross(va,vb)) , dot(va,vb) ); Notice that taking the norm of the cross product gives the first argument of atan2 a positive value, so the angle is constrained to lie in one of the first two quadrants. Roger Stafford
From: Natalie Sin Hwee on 12 Jul 2010 11:25
Dear Roger, yes you're totally right! i'm so clueless. But thanks for your awesome explanation !! ^^ Thank you once again! You're a STAR!! THank youThank you Thank you!!! Kindest regards, Natalie "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i15pav$pgl$1(a)fred.mathworks.com>... > "Natalie Sin Hwee " <sin.ng09(a)imperial.ac.uk> wrote in message <i15ge0$91n$1(a)fred.mathworks.com>... > > Sorry i forgot to ask, > > > > If i was to apply this into 3D, > > > > how can i apply ang = mod( atan2( det([v1;v2]) , dot(v1,v2) ) , 2*pi ); > > if e.g. > > v1= [1,2,3] > > v2= [4,5,6] > > I tried but it says: > > > > ??? Error using ==> det > > Matrix must be square. > > > > Thanks > > Natalie > - - - - - - - - - - > As I mentioned earlier, in three dimensional space you will have to give up the notion of clockwise/counterclockwise rotation. If you have a vector on the earth pointing from earth center to Sydney, Australia and another pointing to Tokyo, there is no clockwise/counterclockwise criterion for deciding which is the "positive" way to rotate. Because of this, the usual convention is that the angle between the vectors is considered to be the smaller of the two angles in a full great circle containing two cities. Such an angle is always between 0 and pi, which is to say that it always lies in the first two quadrants. The other possible angle in the great circle of course then lies in the third or fourth quadrants, with the sum of these two being 2*pi. > > In three dimensions if va and vb are the vectors, the above (smaller) angle is given by: > > ang = atan2( norm(cross(va,vb)) , dot(va,vb) ); > > Notice that taking the norm of the cross product gives the first argument of atan2 a positive value, so the angle is constrained to lie in one of the first two quadrants. > > Roger Stafford |