Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Quicker way to rotate a 3 dimensional array?
Replies: 2   Last Post: Jan 28, 2013 2:31 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruno Luong

Posts: 9,240
Registered: 7/26/08
Re: Quicker way to rotate a 3 dimensional array?
Posted: Jan 28, 2013 2:31 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Phil " <matlab@test.com> wrote in message <ke4thb$s7j$1@newscl01ah.mathworks.com>...
> I've got an array that is three dimensional where the first two dimensions are relatively large numbers and the third has length 3. This third one contains x,y,z co-ordinates that I would like to rotate about the x axis. I've managed to do this using:
> tmp3 = tmp;
> k = 0;
> for i=1:height
> for j=1:width
> k = k + 1;
> tmp3(i,j,:) = reshape(tmp(i,j,:),1,3)*[1,0,0;0,cos(theta),sin(theta);0,-sin(theta),cos(theta)];
> end
> end

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

[nx ny nz] = size(temp);
temp3 = reshape(reshape(temp,[],3)*R, [nx ny 3]);

% Bruno

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2015. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.