Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Rotation matrix

Subject: Rotation matrix

From: Widt

Date: 26 Mar, 2011 10:53:04

Message: 1 of 6

Hi.

Could someone please help me.
I have to random vectors u and v in 3d space. They have the same origin and equal length. These vectors define points on a sphere. I want to compute the matrix that rotates the vector u to the direction of the vector v and then use this matrix to rotate another random vector.
In Mathematica there is the RotationMatrix [{u,v}] that gives you the rotation matrix.
How can I accomplish this in Matlab ?

Thanks.

Subject: Rotation matrix

From: Bruno Luong

Date: 26 Mar, 2011 13:40:19

Message: 2 of 6

"Widt" wrote in message <imkgig$qiq$1@fred.mathworks.com>...
> Hi.
>
> Could someone please help me.
> I have to random vectors u and v in 3d space. They have the same origin and equal length. These vectors define points on a sphere. I want to compute the matrix that rotates the vector u to the direction of the vector v and then use this matrix to rotate another random vector.
> In Mathematica there is the RotationMatrix [{u,v}] that gives you the rotation matrix.
> How can I accomplish this in Matlab ?
>
> Thanks.

1. Take the cross product of those two vectors u and v. It gives you the rotation axis and angle (be careful on the sign convention) - help CROSS.

2. Use Rodiguez's rotation formula to build the rotation matrix (see Wikipedia for example).

Be aware that the rotation vector and matrix are NOT unique.

Bruno

Subject: Rotation matrix

From: Matt J

Date: 26 Mar, 2011 14:26:04

Message: 3 of 6

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <imkqc3$nfa$1@fred.mathworks.com>...
>
>
> 1. Take the cross product of those two vectors u and v. It gives you the rotation axis and angle (be careful on the sign convention) - help CROSS.
>
> 2. Use Rodiguez's rotation formula to build the rotation matrix (see Wikipedia for example).
================

And in fact, I posted code here recently, for constructing the rotation matrix using Rodrigues' formula


http://www.mathworks.com/matlabcentral/newsreader/view_thread/304649#825856

Subject: Rotation matrix

From: Widt

Date: 26 Mar, 2011 15:11:04

Message: 4 of 6

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <imkqc3$nfa$1@fred.mathworks.com>...
> "Widt" wrote in message <imkgig$qiq$1@fred.mathworks.com>...
> > Hi.
> >
> > Could someone please help me.
> > I have to random vectors u and v in 3d space. They have the same origin and equal length. These vectors define points on a sphere. I want to compute the matrix that rotates the vector u to the direction of the vector v and then use this matrix to rotate another random vector.
> > In Mathematica there is the RotationMatrix [{u,v}] that gives you the rotation matrix.
> > How can I accomplish this in Matlab ?
> >
> > Thanks.
>
> 1. Take the cross product of those two vectors u and v. It gives you the rotation axis and angle (be careful on the sign convention) - help CROSS.
>
> 2. Use Rodiguez's rotation formula to build the rotation matrix (see Wikipedia for example).
>
> Be aware that the rotation vector and matrix are NOT unique.
>
> Bruno

Just to make sure. I will find the angle using the dot product of u and v. The function cross only gives the vector perpendicular to u and v, right.

Thanks

Subject: Rotation matrix

From: Matt J

Date: 26 Mar, 2011 15:25:20

Message: 5 of 6

"Widt" wrote in message <imkvm8$eij$1@fred.mathworks.com>...
>
>
> Just to make sure. I will find the angle using the dot product of u and v. The function cross only gives the vector perpendicular to u and v, right.

No. cross(u,v)/norm(u)/norm(v) will give a vector perpendicular to u and v, but it will also have magnitude sin(theta) where theta is the rotation angle. So, it should be sufficient to use CROSS

Subject: Rotation matrix

From: Widt

Date: 26 Mar, 2011 21:11:04

Message: 6 of 6

"Matt J" wrote in message <iml0h0$r0n$1@fred.mathworks.com>...
> "Widt" wrote in message <imkvm8$eij$1@fred.mathworks.com>...
> >
> >
> > Just to make sure. I will find the angle using the dot product of u and v. The function cross only gives the vector perpendicular to u and v, right.
>
> No. cross(u,v)/norm(u)/norm(v) will give a vector perpendicular to u and v, but it will also have magnitude sin(theta) where theta is the rotation angle. So, it should be sufficient to use CROSS

Thank you all for your help. This is how I've done it.


function [R]=rotationmatrix(u,v)
uvangle=acos(dot(u,v));%calculate the angle between u and v
k=cross(u,v);%calculate the cross product between u and v
kx=[0 -k(1,3) k(1,2);k(1,3) 0 -k(1,1);-k(1,2) k(1,1) 0];%the cross product in matrix form
R=eye(3,3)+(kx.*sin(uvangle))+((1-cos(uvangle))*kx^2);%Calculate the rotation matrix with Rodrigues' rotation formula

I can't see using the dot product to find the angle is any worse.

Thanks.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us