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:
Rotate a cube?

Subject: Rotate a cube?

From: Nguyen Long

Date: 6 Oct, 2010 08:58:05

Message: 1 of 6

I have a cube with 8 vertexes (know exactly coordinate of each vertex).
But the problem is "How to rotate this cube around its edge or a fixed axe?"
Can you give me any hints or give me an example code for solving this problem.
Thank you.
PS: I'm the beginner in Matlab, so I really need your help

Subject: Rotate a cube?

From: Roger Stafford

Date: 7 Oct, 2010 03:17:03

Message: 2 of 6

"Nguyen Long" <nguyenlongvp@gmail.com> wrote in message <i8hdmt$lup$1@fred.mathworks.com>...
> I have a cube with 8 vertexes (know exactly coordinate of each vertex).
> But the problem is "How to rotate this cube around its edge or a fixed axe?"
> Can you give me any hints or give me an example code for solving this problem.
> Thank you.
> PS: I'm the beginner in Matlab, so I really need your help
- - - - - - - - -
  The following is a partial answer. Let W be a unit vector pointing along the positive (right-hand rule) axis of rotation, let R be a point somewhere on this axis, let P be a point to be rotated about the axis by an angle theta, and let Q be that point after rotation. Then in vector analysis you have:

 PR = P-R;
 C = cross(PR,W);
 Q = R + W*dot(PR,W) + cross(W,C)*cos(theta) + C*sin(theta);

Can you see why?

  Now apply this to the vertices of your cube.

Roger Stafford

Subject: Rotate a cube?

From: Nguyen Long

Date: 7 Oct, 2010 05:47:04

Message: 3 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i8je3f$evk$1@fred.mathworks.com>...
> "Nguyen Long" <nguyenlongvp@gmail.com> wrote in message <i8hdmt$lup$1@fred.mathworks.com>...
> > I have a cube with 8 vertexes (know exactly coordinate of each vertex).
> > But the problem is "How to rotate this cube around its edge or a fixed axe?"
> > Can you give me any hints or give me an example code for solving this problem.
> > Thank you.
> > PS: I'm the beginner in Matlab, so I really need your help
> - - - - - - - - -
> The following is a partial answer. Let W be a unit vector pointing along the positive (right-hand rule) axis of rotation, let R be a point somewhere on this axis, let P be a point to be rotated about the axis by an angle theta, and let Q be that point after rotation. Then in vector analysis you have:
>
> PR = P-R;
> C = cross(PR,W);
> Q = R + W*dot(PR,W) + cross(W,C)*cos(theta) + C*sin(theta);
>
> Can you see why?
>
> Now apply this to the vertices of your cube.
>
> Roger Stafford

What W mean?

Subject: Rotate a cube?

From: Nguyen Long

Date: 7 Oct, 2010 05:59:05

Message: 4 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i8je3f$evk$1@fred.mathworks.com>...
> "Nguyen Long" <nguyenlongvp@gmail.com> wrote in message <i8hdmt$lup$1@fred.mathworks.com>...
> > I have a cube with 8 vertexes (know exactly coordinate of each vertex).
> > But the problem is "How to rotate this cube around its edge or a fixed axe?"
> > Can you give me any hints or give me an example code for solving this problem.
> > Thank you.
> > PS: I'm the beginner in Matlab, so I really need your help
> - - - - - - - - -
> The following is a partial answer. Let W be a unit vector pointing along the positive (right-hand rule) axis of rotation, let R be a point somewhere on this axis, let P be a point to be rotated about the axis by an angle theta, and let Q be that point after rotation. Then in vector analysis you have:
>
> PR = P-R;
> C = cross(PR,W);
> Q = R + W*dot(PR,W) + cross(W,C)*cos(theta) + C*sin(theta);
>
> Can you see why?
>
> Now apply this to the vertices of your cube.
>
> Roger Stafford

Thanks. The W vector can be obtain by normalization one vector on the rotate axis, is that true? and your formula is a part of Rodrigues' rotation matrix?

Subject: Rotate a cube?

From: Roger Stafford

Date: 7 Oct, 2010 08:00:22

Message: 5 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i8je3f$evk$1@fred.mathworks.com>...
> ......
> PR = P-R;
> C = cross(PR,W);
> Q = R + W*dot(PR,W) + cross(W,C)*cos(theta) + C*sin(theta);
> .......
- - - - - - - - - -
  I'm afraid I got that rotation in the wrong direction. As it is, it is doing a left hand rotation as theta increases, rather than a right hand one. My apologies. It should read:

 PR = P-R;
 C = cross(W,PR);
 Q = R + W*dot(PR,W) + cross(C,W)*cos(theta) + C*sin(theta);

Roger Stafford

Subject: Rotate a cube?

From: Nguyen Long

Date: 7 Oct, 2010 09:56:08

Message: 6 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i8jumm$sqj$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i8je3f$evk$1@fred.mathworks.com>...
> > ......
> > PR = P-R;
> > C = cross(PR,W);
> > Q = R + W*dot(PR,W) + cross(W,C)*cos(theta) + C*sin(theta);
> > .......
> - - - - - - - - - -
> I'm afraid I got that rotation in the wrong direction. As it is, it is doing a left hand rotation as theta increases, rather than a right hand one. My apologies. It should read:
>
> PR = P-R;
> C = cross(W,PR);
> Q = R + W*dot(PR,W) + cross(C,W)*cos(theta) + C*sin(theta);
>
> Roger Stafford

But rotate anticlockwise is often used in physics and maths, rotate to the right handside is correct?

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