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 a 3d object

Subject: rotate a 3d object

From: David Berrow

Date: 6 Feb, 2008 19:03:02

Message: 1 of 6

I know MATLAB is supposed to store new values of an object
defined by X,Y,Z matrices when the rotate function is used
on it. I have the following code but my X,Y,Z values do
not change. I am not sure why!

ber=surf(X,Y,Z); % berg surface
k=[0 0 1]; % vector in z-direction
yi=[0 1 0]; % vector in y-direction
alpha=45
gamma=53
rotate(ber,k,alpha); %rotate berg alpha degrees about zaxis
rotate(ber,yi,gamma); %rotate berg gamma degrees about yaxis

Subject: rotate a 3d object

From: us

Date: 6 Feb, 2008 19:36:02

Message: 2 of 6

"David Berrow":
<SNIP rotating conundrum

this works fine here (r2007b/r2008a)

     [x,y,z]=peaks(16);
     sh=surfl(x,y,z);
     axis manual;
     z=[0,0,1];
for i=0:10:180
     rotate(sh,z,10);
     pause(.2);
end

what do you see?

us

Subject: rotate a 3d object

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 6 Feb, 2008 19:41:28

Message: 3 of 6

In article <fod096$aid$1@fred.mathworks.com>,
David Berrow <berrow@engr.mun.ca> wrote:
>I know MATLAB is supposed to store new values of an object
>defined by X,Y,Z matrices when the rotate function is used
>on it. I have the following code but my X,Y,Z values do
>not change. I am not sure why!

>ber=surf(X,Y,Z); % berg surface
>k=[0 0 1]; % vector in z-direction
>yi=[0 1 0]; % vector in y-direction
>alpha=45
>gamma=53
>rotate(ber,k,alpha); %rotate berg alpha degrees about zaxis
>rotate(ber,yi,gamma); %rotate berg gamma degrees about yaxis

Do you mean that if you get() the XData, YData, and ZData of
ber after you do the rotations, that you get the same values
as you do if you get() those values of ber before the rotation?

--
   "Beware of bugs in the above code; I have only proved it correct,
   not tried it." -- Donald Knuth

Subject: rotate a 3d object

From: David Berrow

Date: 7 Feb, 2008 14:53:02

Message: 4 of 6

Yes I get the exact same values of X, Y, and Z after using
the rotation function

Subject: rotate a 3d object

From: Steven Lord

Date: 7 Feb, 2008 15:03:19

Message: 5 of 6


"David Berrow" <berrow@engr.mun.ca> wrote in message
news:fod096$aid$1@fred.mathworks.com...
>I know MATLAB is supposed to store new values of an object
> defined by X,Y,Z matrices when the rotate function is used
> on it. I have the following code but my X,Y,Z values do
> not change. I am not sure why!
>
> ber=surf(X,Y,Z); % berg surface
> k=[0 0 1]; % vector in z-direction
> yi=[0 1 0]; % vector in y-direction
> alpha=45
> gamma=53
> rotate(ber,k,alpha); %rotate berg alpha degrees about zaxis
> rotate(ber,yi,gamma); %rotate berg gamma degrees about yaxis

The ROTATE function rotates the object whose handle you provide to it. That
modifies the properties _of that object_, not _the variables that were used
to create that object_. After all, those variables may no longer exist, or
you may have used an expression that is not a variable to create the object.
In order to see the modified data, you need to GET it from the object.


[x, y] = meshgrid(-1:0.1:1, -1:0.1:1);
h = surf(x, y, x+y);
pause % so you can see the original surface
rotate(h, [0 0 1], pi/4)
newx = get(h, 'XData');
newy = get(h, 'YData');
isequal(x, newx) % should return false


--
Steve Lord
slord@mathworks.com

Subject: rotate a 3d object

From: David Berrow

Date: 7 Feb, 2008 16:10:20

Message: 6 of 6

thank you i got it working now

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