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 object to align with x-y plane

Subject: Rotate 3D object to align with x-y plane

From: Marcin

Date: 19 May, 2010 06:20:22

Message: 1 of 20

Hi,

I have a set of points describing a 3D object, which has been rotated by some small angle (below 45 degrees) with respect to x,y and z axis. I want to rotate it back to align it with the x-y plane, but the problem is I don't know the angles, so I need to calculate/estimate them somehow. So the questions are:

1. how to plot the object in a mesh like manner?
2. how to calculate the angles?
3. how to rotate it when I know the angles?

Many thanks

Subject: Rotate 3D object to align with x-y plane

From: Roger Stafford

Date: 19 May, 2010 22:45:22

Message: 2 of 20

"Marcin " <mb1234@gazeta.pl> wrote in message <hsvvv6$7rl$1@fred.mathworks.com>...
> Hi,
>
> I have a set of points describing a 3D object, which has been rotated by some small angle (below 45 degrees) with respect to x,y and z axis. I want to rotate it back to align it with the x-y plane, but the problem is I don't know the angles, so I need to calculate/estimate them somehow. So the questions are:
>
> 1. how to plot the object in a mesh like manner?
> 2. how to calculate the angles?
> 3. how to rotate it when I know the angles?
>
> Many thanks

  I am not clear about what you mean when you say, "I want to rotate it back to align it with the x-y plane." Do the set of points "describing" the 3D object all lie in a plane? If so, there are many ways to rotate them so they all come to lie in the x-y plane. Any rotation axis which lies in the plane which bisects the dihedral angle between the points' plane and the x-y plane could be used. You can achieve any orientation you wish for the resulting x-y plane points. If you have a preferred final orientation for the points as they lie in the x-y plane, then I could give you a specific method for solving your problem. As it stands, the problem appears to be indeterminate if I have understood you correctly.

Roger Stafford

Subject: Rotate 3D object to align with x-y plane

From: Marcin

Date: 20 May, 2010 14:25:04

Message: 3 of 20

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ht1pm2$1v$1@fred.mathworks.com>...
> "Marcin " <mb1234@gazeta.pl> wrote in message <hsvvv6$7rl$1@fred.mathworks.com>...
> > Hi,
> >
> > I have a set of points describing a 3D object, which has been rotated by some small angle (below 45 degrees) with respect to x,y and z axis. I want to rotate it back to align it with the x-y plane, but the problem is I don't know the angles, so I need to calculate/estimate them somehow. So the questions are:
> >
> > 1. how to plot the object in a mesh like manner?
> > 2. how to calculate the angles?
> > 3. how to rotate it when I know the angles?
> >
> > Many thanks
>
> I am not clear about what you mean when you say, "I want to rotate it back to align it with the x-y plane." Do the set of points "describing" the 3D object all lie in a plane? If so, there are many ways to rotate them so they all come to lie in the x-y plane. Any rotation axis which lies in the plane which bisects the dihedral angle between the points' plane and the x-y plane could be used. You can achieve any orientation you wish for the resulting x-y plane points. If you have a preferred final orientation for the points as they lie in the x-y plane, then I could give you a specific method for solving your problem. As it stands, the problem appears to be indeterminate if I have understood you correctly.
>
> Roger Stafford

Hi Roger,

Thanks for replying. I'll try to be more precise. I have a set of coordinates in 3 dimensions (xyz triplets), which describe some object. Due to the way the coordinates have been recorded, the object might be rotated, so that it's position is not say horizontal. I need to rotate it back, but first I need to detect the angle by which to rotate.

Also, is there a nice way to plot the object in MATLAB? Is it possible to interpolate or convert the data somehow to use the patch function or surf maybe?

Thanks

Subject: Rotate 3D object to align with x-y plane

From: Matt J

Date: 20 May, 2010 15:06:04

Message: 4 of 20

"Marcin " <mb1234@gazeta.pl> wrote in message <ht3go0$6hi$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ht1pm2$1v$1@fred.mathworks.com>...
> > "Marcin " <mb1234@gazeta.pl> wrote in message <hsvvv6$7rl$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > I have a set of points describing a 3D object, which has been rotated by some small angle (below 45 degrees) with respect to x,y and z axis. I want to rotate it back to align it with the x-y plane, but the problem is I don't know the angles, so I need to calculate/estimate them somehow. So the questions are:
> > >
> > > 1. how to plot the object in a mesh like manner?
> > > 2. how to calculate the angles?
> > > 3. how to rotate it when I know the angles?
> > >
> > > Many thanks
> >
> > I am not clear about what you mean when you say, "I want to rotate it back to align it with the x-y plane." Do the set of points "describing" the 3D object all lie in a plane? If so, there are many ways to rotate them so they all come to lie in the x-y plane. Any rotation axis which lies in the plane which bisects the dihedral angle between the points' plane and the x-y plane could be used. You can achieve any orientation you wish for the resulting x-y plane points. If you have a preferred final orientation for the points as they lie in the x-y plane, then I could give you a specific method for solving your problem. As it stands, the problem appears to be indeterminate if I have understood you correctly.
> >
> > Roger Stafford
>
> Hi Roger,
>
> Thanks for replying. I'll try to be more precise. I have a set of coordinates in 3 dimensions (xyz triplets), which describe some object. Due to the way the coordinates have been recorded, the object might be rotated, so that it's position is not say horizontal. I need to rotate it back, but first I need to detect the angle by which to rotate.
===============

The notion of "horizontal" is ambiguous for a 3D object. How are you measuring horizontality? Is a bottle "horizontal" when it is standing upright on its base (instead of tilted) or when it is lying on the floor with its long axis parallel to the ground?

Also, even if I give you a rotation that restores the object to a horizontal position (whatever that is), you don't have enough information to reconstruct how the object was oriented with respect to the horizontal plane. That is, if the x-y plane is horizontal, then I can rotate the object around the z-axis and it will still be horizontal. Do you care about recovering this part of the initial orientation?

Subject: Rotate 3D object to align with x-y plane

From: mat001

Date: 20 May, 2010 15:19:04

Message: 5 of 20

"Marcin " <mb1234@gazeta.pl> wrote in message <hsvvv6$7rl$1@fred.mathworks.com>...
> Hi,
>
> I have a set of points describing a 3D object, which has been rotated by some small angle (below 45 degrees) with respect to x,y and z axis. I want to rotate it back to align it with the x-y plane, but the problem is I don't know the angles, so I need to calculate/estimate them somehow. So the questions are:
>
> 1. how to plot the object in a mesh like manner?
> 2. how to calculate the angles?
> 3. how to rotate it when I know the angles?
>
> Many thanks

Read 3d Visulization

Subject: Rotate 3D object to align with x-y plane

From: Roger Stafford

Date: 20 May, 2010 15:41:19

Message: 6 of 20

"Marcin " <mb1234@gazeta.pl> wrote in message <ht3go0$6hi$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ht1pm2$1v$1@fred.mathworks.com>...
> > "Marcin " <mb1234@gazeta.pl> wrote in message <hsvvv6$7rl$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > I have a set of points describing a 3D object, which has been rotated by some small angle (below 45 degrees) with respect to x,y and z axis. I want to rotate it back to align it with the x-y plane, but the problem is I don't know the angles, so I need to calculate/estimate them somehow. So the questions are:
> > >
> > > 1. how to plot the object in a mesh like manner?
> > > 2. how to calculate the angles?
> > > 3. how to rotate it when I know the angles?
> > >
> > > Many thanks
> >
> > I am not clear about what you mean when you say, "I want to rotate it back to align it with the x-y plane." Do the set of points "describing" the 3D object all lie in a plane? If so, there are many ways to rotate them so they all come to lie in the x-y plane. Any rotation axis which lies in the plane which bisects the dihedral angle between the points' plane and the x-y plane could be used. You can achieve any orientation you wish for the resulting x-y plane points. If you have a preferred final orientation for the points as they lie in the x-y plane, then I could give you a specific method for solving your problem. As it stands, the problem appears to be indeterminate if I have understood you correctly.
> >
> > Roger Stafford
>
> Hi Roger,
>
> Thanks for replying. I'll try to be more precise. I have a set of coordinates in 3 dimensions (xyz triplets), which describe some object. Due to the way the coordinates have been recorded, the object might be rotated, so that it's position is not say horizontal. I need to rotate it back, but first I need to detect the angle by which to rotate.
>
> Also, is there a nice way to plot the object in MATLAB? Is it possible to interpolate or convert the data somehow to use the patch function or surf maybe?
>
> Thanks

  You must face facts, Marcin! What you are asking for, you simply cannot accomplish without more information to go on. You state that you have a set of points which "describe" a three-dimensional object, but how is anyone to tell how these points were originally oriented in space when the object was, as you say, "horizontal"? Even if the points are known to have been originally lying in a horizontal plane, (which would mean that the points are also currently colinear) that still isn't enough information to determine what rotation has been performed. Infinitely many are still possible as I have already pointed out to you at some length.

Roger Stafford

Subject: Rotate 3D object to align with x-y plane

From: Marcin

Date: 20 May, 2010 21:21:04

Message: 7 of 20

> You must face facts, Marcin! What you are asking for, you simply cannot accomplish without more information to go on. You state that you have a set of points which "describe" a three-dimensional object, but how is anyone to tell how these points were originally oriented in space when the object was, as you say, "horizontal"? Even if the points are known to have been originally lying in a horizontal plane, (which would mean that the points are also currently colinear) that still isn't enough information to determine what rotation has been performed. Infinitely many are still possible as I have already pointed out to you at some length.
>
> Roger Stafford

That's the catch. Nobody knows that, so it must be some kind of guess. I think that PCA might do in this case. Anyway, I still don't know how to plot it though. The data is an output of a 3D scan, so I should be able to use mesh/surf or similar function.

Subject: Rotate 3D object to align with x-y plane

From: Matt J

Date: 20 May, 2010 21:52:04

Message: 8 of 20

"Marcin " <mb1234@gazeta.pl> wrote in message <ht4940$b11$1@fred.mathworks.com>...

 Anyway, I still don't know how to plot it though. The data is an output of a 3D scan, so I should be able to use mesh/surf or similar function.
===============

Well then why don't you use these? SURF seems like it should work fine.

Subject: Rotate 3D object to align with x-y plane

From: Roger Stafford

Date: 20 May, 2010 22:23:04

Message: 9 of 20

"Marcin " <mb1234@gazeta.pl> wrote in message <ht4940$b11$1@fred.mathworks.com>...
> That's the catch. Nobody knows that, so it must be some kind of guess.
- - - - - -
  It is no guess, Marcin. What you have put forward is not a well-defined problem and certainly does not have a unique solution. In fact there are infinitely many solutions.

  I strongly suggest you think long and hard about information concerning the object in its so-called "horizontal" position which you haven't thought to state here. Maybe there is something you know which will make it all a very reasonable problem. As it currently stands it is meaningless.

  If I were to hand you a perfectly spherical ball and ask you to rotate it until it was horizontal, what would be your reply? Your probable response should indicate to you what kind of problem you have been presenting here to us. I am sure you can do better than that.

Roger Stafford

Subject: Rotate 3D object to align with x-y plane

From: Marcin

Date: 21 May, 2010 08:26:11

Message: 10 of 20

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <ht4au4$7ua$1@fred.mathworks.com>...
> "Marcin " <mb1234@gazeta.pl> wrote in message <ht4940$b11$1@fred.mathworks.com>...
>
> Anyway, I still don't know how to plot it though. The data is an output of a 3D scan, so I should be able to use mesh/surf or similar function.
> ===============
>
> Well then why don't you use these? SURF seems like it should work fine.

Hi Matt,

Surf requires a matrix of function values (one function value for every pair of x-y) and I don't have this information - all I have are xyz triplets, but in general case each value of say x can occur only once...

Subject: Rotate 3D object to align with x-y plane

From: Marcin

Date: 21 May, 2010 08:31:01

Message: 11 of 20

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ht4co8$5bf$1@fred.mathworks.com>...
> "Marcin " <mb1234@gazeta.pl> wrote in message <ht4940$b11$1@fred.mathworks.com>...
> > That's the catch. Nobody knows that, so it must be some kind of guess.
> - - - - - -
> It is no guess, Marcin. What you have put forward is not a well-defined problem and certainly does not have a unique solution. In fact there are infinitely many solutions.
>
> I strongly suggest you think long and hard about information concerning the object in its so-called "horizontal" position which you haven't thought to state here. Maybe there is something you know which will make it all a very reasonable problem. As it currently stands it is meaningless.
>
> If I were to hand you a perfectly spherical ball and ask you to rotate it until it was horizontal, what would be your reply? Your probable response should indicate to you what kind of problem you have been presenting here to us. I am sure you can do better than that.
>
> Roger Stafford

You are right of course with the ball. But let's assume that it's an ellipsoid-like shape (or flattened ball), it is rotated and I want to align it with the xy plane. How would I do that?

Subject: Rotate 3D object to align with x-y plane

From: Matt J

Date: 21 May, 2010 10:31:05

Message: 12 of 20

"Marcin " <mb1234@gazeta.pl> wrote in message <ht5gc5$cl0$1@fred.mathworks.com>...

>
> You are right of course with the ball. But let's assume that it's an ellipsoid-like shape (or flattened ball), it is rotated and I want to align it with the xy plane. How would I do that?
==============

How is that any different from the case of a perfect sphere? Do you know which axis of the ellipsoid was originally parallel to the z-axis? If so, eliciting that info from you has been like pulling teeth.

Subject: Rotate 3D object to align with x-y plane

From: Marcin

Date: 21 May, 2010 10:45:19

Message: 13 of 20

> How is that any different from the case of a perfect sphere? Do you know which axis of the ellipsoid was originally parallel to the z-axis? If so, eliciting that info from you has been like pulling teeth.

I don't but any alignment with the xyz axes will do. Mind you, that the object might not be a perfect ellipsoid but it will still have some principal axes, which I want to align. I guess that I have just answered my own question - some kind of PCA should do. But I still don't know how to plot it nicely - plot3 is not good enough and I can't find anything to do the interpolation for surf/mesh to work.

Subject: Rotate 3D object to align with x-y plane

From: Matt J

Date: 21 May, 2010 10:55:07

Message: 14 of 20

"Marcin " <mb1234@gazeta.pl> wrote in message <ht5o7v$96u$1@fred.mathworks.com>...
> > How is that any different from the case of a perfect sphere? Do you know which axis of the ellipsoid was originally parallel to the z-axis? If so, eliciting that info from you has been like pulling teeth.
>
> I don't but any alignment with the xyz axes will do. Mind you, that the object might not be a perfect ellipsoid but it will still have some principal axes, which I want to align. I guess that I have just answered my own question - some kind of PCA should do. But I still don't know how to plot it nicely - plot3 is not good enough and I can't find anything to do the interpolation for surf/mesh to work.
======================

I still don't see why surf won't work as is. In doc surf, they show to plot spheres/ellipsoids given a set of surface points.

Subject: Rotate 3D object to align with x-y plane

From: Marcin

Date: 21 May, 2010 11:44:04

Message: 15 of 20

> I still don't see why surf won't work as is. In doc surf, they show to plot spheres/ellipsoids given a set of surface points.

Try to do this then:

x = (-1:.1:1); y = (-1:.1:1);
[X,Y] = meshgrid(x,y);
Z = (1-X.^2-Y.^2);
mesh(Z); % this will work fine

Rp = randperm(numel(Z));
xr = X(Rp(1:200));
yr = Y(Rp(1:200));
zr = Z(Rp(1:200));
plot3(xr,yr,zr,'.'); % this will work fine as well but doesn't look too good

mesh(zr); % this will produce an error

All the data I have is xr,yr,zr.

Subject: Rotate 3D object to align with x-y plane

From: Matt J

Date: 21 May, 2010 12:09:04

Message: 16 of 20

"Marcin " <mb1234@gazeta.pl> wrote in message <ht5rm4$l78$1@fred.mathworks.com>...

> mesh(Z); % this will work fine
=========

If this works fine for you, then what's the problem?
surf(X,Y,Z) gives similarly good results as I've been continually saying.

Subject: Rotate 3D object to align with x-y plane

From: Marcin

Date: 21 May, 2010 12:34:06

Message: 17 of 20

> If this works fine for you, then what's the problem?
> surf(X,Y,Z) gives similarly good results as I've been continually saying.

You didn't read carefully. I don't have X,Y,Z, all I have is xr,yr,zr - the code was just an example where these 3 might come from.

Subject: Rotate 3D object to align with x-y plane

From: Steven Lord

Date: 21 May, 2010 14:07:49

Message: 18 of 20


"Marcin " <mb1234@gazeta.pl> wrote in message
news:ht5uju$35u$1@fred.mathworks.com...
>> If this works fine for you, then what's the problem?
>> surf(X,Y,Z) gives similarly good results as I've been continually saying.
>
> You didn't read carefully. I don't have X,Y,Z, all I have is xr,yr,zr -
> the code was just an example where these 3 might come from.

Look at GRIDDATAN.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Rotate 3D object to align with x-y plane

From: YILMAZ

Date: 2 Jul, 2010 07:42:06

Message: 19 of 20

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ht1pm2$1v$1@fred.mathworks.com>...
> "Marcin " <mb1234@gazeta.pl> wrote in message <hsvvv6$7rl$1@fred.mathworks.com>...
> > Hi,
> >
> > I have a set of points describing a 3D object, which has been rotated by some small angle (below 45 degrees) with respect to x,y and z axis. I want to rotate it back to align it with the x-y plane, but the problem is I don't know the angles, so I need to calculate/estimate them somehow. So the questions are:
> >
> > 1. how to plot the object in a mesh like manner?
> > 2. how to calculate the angles?
> > 3. how to rotate it when I know the angles?
> >
> > Many thanks
>
> I am not clear about what you mean when you say, "I want to rotate it back to align it with the x-y plane." Do the set of points "describing" the 3D object all lie in a plane? If so, there are many ways to rotate them so they all come to lie in the x-y plane. Any rotation axis which lies in the plane which bisects the dihedral angle between the points' plane and the x-y plane could be used. You can achieve any orientation you wish for the resulting x-y plane points. If you have a preferred final orientation for the points as they lie in the x-y plane, then I could give you a specific method for solving your problem. As it stands, the problem appears to be indeterminate if I have understood you correctly.
>
> Roger Stafford

Hi Roger;
I have a some problem with rotating my matrices. My matrices describes a rectangle. 4x10 data set. I want this rectangle to move with 30 degree angel.

For example in ms office word we create a new rectangle. After that we can rotate it 30 ° angle.

I tried to use different rules that I thinked, but I could not achieve. Can you offer me a rule?
Thanks for your help

Subject: Rotate 3D object to align with x-y plane

From: Jan Simon

Date: 2 Jul, 2010 08:09:33

Message: 20 of 20

Dear YILMAZ,

> Hi Roger;
> I have a some problem with rotating my matrices. My matrices describes a rectangle. 4x10 data set. I want this rectangle to move with 30 degree angel.
>
> For example in ms office word we create a new rectangle. After that we can rotate it 30 ° angle.
>
> I tried to use different rules that I thinked, but I could not achieve. Can you offer me a rule?

Please start a new thread for a new question.
Please show us the "different" rules you have tried before and explain, what problems occurred. It is much easier for CSSMers to fix bugs in your solution than guessing what your input data could be and what problems might have occurred.

Kind regards, Jan

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