help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: find the rotation matrix between two vectors


From: Junqian Gordon Xu
Subject: Re: find the rotation matrix between two vectors
Date: Wed, 28 Apr 2010 00:00:29 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100411 Lightning/1.0b1 Icedove/3.0.4

Thanks, that's great explanations.

Gordon

On 04/27/2010 10:36 AM, John Swensen wrote:

On Apr 27, 2010, at 11:12 AM, James Sherman Jr. wrote:

The most intuitive way for me is to first axis-angle representation of the 
rotation, then convert it to a quaternion.

To get axis-angle is fairly straightforward, the inner product of the two 
vectors is the cosine of the angle, and the cross-product gives the axis (just 
need to normalize).

Then, to convert to quaternion, its pretty straightforward as well, but the 
formula is found in (of many places) Axis-angle article or here.

There is also several libraries, if you can't find any for octave specifically, written 
for Matlab may work with octave.  Some are GPL even, if you are concerned about that.  
Search for "quaternion for matlab"

Hope this helps.

On Tue, Apr 27, 2010 at 7:18 AM, Junqian Gordon Xu<address@hidden>  wrote:
I'm trying to find the rotation matrix or quaternion from two unit
vectors A and B, then to apply the rotation to a third vector C.

I played with the quaternion package on octave-forge, but the
documentation is not complete and the `demoquat` does not work well
under 3.2.4.

My knowledge of quaternion is quite limited. Does anybody have any
suggestion on how to achieve this easily in octave?

Thanks
Gordon
_______________________________________________


Also, if you want the rotation matrix rather than a quaternion (even though the 
two are equivalent global representations of rotations), then you can use 
Rodrigues formula.

% Get the axis and angle
angle = acos(v1'*v2);
axis = cross(v1,v2)/norm(cross(v1,v2));

% A skew symmetric representation of the normalized axis
axis_skewed = [ 0 -axis(3) axis(2) ; axis(3) 0 -axis(1) ; -axis(2) axis(1) 0];

% Rodrigues formula for the rotation matrix
R = eye(3) + sin(angle)*axis_skewed + (1-cos(angle))*axis_skewed*axis_skewed;

Hope this helps (may sure you add error checkin for the obvious problem cases).

John
_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave




reply via email to

[Prev in Thread] Current Thread [Next in Thread]