Got Questions? Get Answers.
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 3d coordinates

Subject: Rotate 3d coordinates

From: Betty Vag

Date: 7 Jun, 2011 15:44:05

Message: 1 of 12

How can I change the coordinates of a set of data so that they can come as a rotation to a given axis??

for example,i have a set of points and i want to rotate them (so that their coordinates change forever!!) about x-axis.

Subject: Rotate 3d coordinates

From: Roger Stafford

Date: 7 Jun, 2011 16:07:06

Message: 2 of 12

"Betty Vag" <betty00arg@hotmail.com> wrote in message <islh05$itn$1@newscl01ah.mathworks.com>...
> How can I change the coordinates of a set of data so that they can come as a rotation to a given axis??
>
> for example,i have a set of points and i want to rotate them (so that their coordinates change forever!!) about x-axis.
- - - - - - - - -
  Suppose P is an n by 3 array of x-y-z coordinates of points. To rotate them about the x-axis by an angle (in radians) of theta, do this:

 P = P*[cos(theta),sin(theta),0;-sin(theta),cos(theta),0;0,0,1];

Roger Stafford

Subject: Rotate 3d coordinates

From: Matt J

Date: 7 Jun, 2011 16:30:07

Message: 3 of 12

"Betty Vag" <betty00arg@hotmail.com> wrote in message <islh05$itn$1@newscl01ah.mathworks.com>...
> How can I change the coordinates of a set of data so that they can come as a rotation to a given axis??
>
> for example,i have a set of points and i want to rotate them (so that their coordinates change forever!!) about x-axis.
===============

For rotations about arbitrary axes, see

http://www.mathworks.com/matlabcentral/fileexchange/30864-3d-rotation-about-shifted-axis

Subject: Rotate 3d coordinates

From: Husam Aldahiyat

Date: 7 Jun, 2011 21:03:02

Message: 4 of 12

See if this helps:

http://www.mathworks.com/matlabcentral/fileexchange/24247-eulerfixed-angles-properties

Read the comments.

Subject: Rotate 3d coordinates

From: Betty Vag

Date: 7 Jun, 2011 22:23:05

Message: 5 of 12

"Roger Stafford" wrote in message <isliba$nd2$1@newscl01ah.mathworks.com>...
> "Betty Vag" <betty00arg@hotmail.com> wrote in message <islh05$itn$1@newscl01ah.mathworks.com>...
> > How can I change the coordinates of a set of data so that they can come as a rotation to a given axis??
> >
> > for example,i have a set of points and i want to rotate them (so that their coordinates change forever!!) about x-axis.
> - - - - - - - - -
> Suppose P is an n by 3 array of x-y-z coordinates of points. To rotate them about the x-axis by an angle (in radians) of theta, do this:
>
> P = P*[cos(theta),sin(theta),0;-sin(theta),cos(theta),0;0,0,1];
>
> Roger Stafford

I put it as you said but it gives me back the following:

Too many input arguments.

Error in ==> rotate at 45
D =
D*[cos(0,83921494),sin(0,83921494),0;-sin(0,83921494),cos(0,83921494),0;0,0,1];

what's wrong??

am I missing something???

Subject: Rotate 3d coordinates

From: Matt J

Date: 7 Jun, 2011 22:33:04

Message: 6 of 12

"Betty Vag" <betty00arg@hotmail.com> wrote in message <ism8c9$t30$1@newscl01ah.mathworks.com>...
>
> I put it as you said but it gives me back the following:
>
> Too many input arguments.
>
> Error in ==> rotate at 45
> D =
> D*[cos(0,83921494),sin(0,83921494),0;-sin(0,83921494),cos(0,83921494),0;0,0,1];
========================

You mistyped 0.83921494 as 0,83921494 making MATLAB think you are passing 2 arguments to COS and SIN.

Subject: Rotate 3d coordinates

From: Roger Stafford

Date: 7 Jun, 2011 22:35:05

Message: 7 of 12

"Betty Vag" <betty00arg@hotmail.com> wrote in message <ism8c9$t30$1@newscl01ah.mathworks.com>...
> D*[cos(0,83921494),sin(0,83921494),0;-sin(0,83921494),cos(0,83921494),0;0,0,1];
- - - - - - - - -
  You have given the sine and cosine functions two arguments. They will accept only one. Check the documentation. Perhaps you meant 0.83921494 instead.

Roger Stafford

Subject: Rotate 3d coordinates

From: Betty Vag

Date: 7 Jun, 2011 22:38:02

Message: 8 of 12

"Matt J" wrote in message <ism8v0$15h$1@newscl01ah.mathworks.com>...
> "Betty Vag" <betty00arg@hotmail.com> wrote in message <ism8c9$t30$1@newscl01ah.mathworks.com>...
> >
> > I put it as you said but it gives me back the following:
> >
> > Too many input arguments.
> >
> > Error in ==> rotate at 45
> > D =
> > D*[cos(0,83921494),sin(0,83921494),0;-sin(0,83921494),cos(0,83921494),0;0,0,1];
> ========================
>
> You mistyped 0.83921494 as 0,83921494 making MATLAB think you are passing 2 arguments to COS and SIN.

Thank you very much!!

Subject: Rotate 3d coordinates

From: Betty Vag

Date: 7 Jun, 2011 23:10:07

Message: 9 of 12

D*[cos(0,83921494),sin(0,83921494),0;-sin(0,83921494),cos(0,83921494),0;0,0,1];


is this giving me a rotation to the x axis or the z because my z coordinate stays as it is..?

if i want a rotation to another axis, i change just the last vector (0,0,1) or the whole equation???

Subject: Rotate 3d coordinates

From: Roger Stafford

Date: 8 Jun, 2011 00:48:05

Message: 10 of 12

"Betty Vag" <betty00arg@hotmail.com> wrote in message <ismb4f$69d$1@newscl01ah.mathworks.com>...
> D*[cos(0,83921494),sin(0,83921494),0;-sin(0,83921494),cos(0,83921494),0;0,0,1];
>
> is this giving me a rotation to the x axis or the z because my z coordinate stays as it is..?
>
> if i want a rotation to another axis, i change just the last vector (0,0,1) or the whole equation???
- - - - - - - - - - -
  You're right! What I gave you by mistake was a rotation about the z-axis. My apologies. Here are the rotation matrices for P = P*R about the three axes.

 1. About the x-axis:

  R = [1,0,0;0,cos(theta),sin(theta);0,-sin(theta),cos(theta)];
   
 2. About the y-axis:

  R = [cos(theta),0,-sin(theta);0,1,0;sin(theta),0,cos(theta)];

 3. About the z-axis:

  R = [cos(theta),sin(theta),0;-sin(theta),cos(theta),0;0,0,1];

As you can see, each is a certain permutation of the rows and columns of the previous one.

  If you have your three coordinates in columns instead of rows, you would have P = R*P where R would then be the transpose of each of the above respective matrices.

  There exists a general formula for these R matrices for an arbitrarily oriented rotation axis which I am too lazy at the moment to look up.

Roger Stafford

Subject: Rotate 3d coordinates

From: Betty Vag

Date: 8 Jun, 2011 12:28:05

Message: 11 of 12

thank you very much!!! i really appreciate your help!!! it worked really well!!!

Subject: Rotate 3d coordinates

From: Matt J

Date: 8 Jun, 2011 13:19:04

Message: 12 of 12

"Roger Stafford" wrote in message <ismgs5$k0e$1@newscl01ah.mathworks.com>...
>
> There exists a general formula for these R matrices for an arbitrarily oriented rotation axis which I am too lazy at the moment to look up.
=============

And looking it up would be unnecessary since, once again, this FEX tool provides it anyway

http://www.mathworks.com/matlabcentral/fileexchange/30864-3d-rotation-about-shifted-axis

Examples:

1. 60 degree rotations about x,y, and z-axis

[R,~]=axelrot(60,[1,0,0]);
[R,~]=axelrot(60,[0,1,0]);
[R,~]=axelrot(60,[0,0,1]);

2. 60 degree rotation about the axis [1,1,1]

>> [R,~]=AxelRot(60,[1,1,1])

R =

    0.6667 -0.3333 0.6667
    0.6667 0.6667 -0.3333
   -0.3333 0.6667 0.6667


3. 60 degree rotation about axis [1 1 1] and which passes through the point [1 2 3];


>> [R,t]=AxelRot(60,[1,1,1],[1,2,3])

R =

    0.6667 -0.3333 0.6667
    0.6667 0.6667 -0.3333
   -0.3333 0.6667 0.6667


t =

   -1.0000
    1.0000
         0


For this last one, you will want to use BSXFUN to apply the transformation, because it is affine:

Pnew=bsxfun(@plus,P*R',t')

Tags for 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