Code covered by the BSD License  

Highlights from
rot90 in 3D

Be the first to rate this file! 4 Downloads (last 30 days) File Size: 1.59 KB File ID: #25546

rot90 in 3D

by Matt Fetterman

 

11 Oct 2009 (Updated 04 Nov 2009)

This function extends the rot90 command to 3D.

| Watch this File

File Information
Description

This function extends the rot90 command to 3D. So you can rotate a 3D matrix by 90degrees about the x-axis, y-axis, or z-axis. It is kind of hard to visualize in your head but I am pretty sure it works correctly. There is a test matrix included in the comments for the file.

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
15 Oct 2009 Jan Simon

Help text exist, but not at the usual position. No H1-line, no check of inputs. The 3rd argument of ROT90 is optional, so a user might expect this for ROT90_3D also. The calculations are valid, but not efficient due to using loops. E.g. for M=ROT90_3D(X,1,1) this is faster: A=PERMUTE(X,[1,3,2]); M=A(:,size(X,3),:);
Further acceleration: Use same array name for input and output (see: Loren's blog "In-place Operations on Data").

26 Oct 2009 Jan Simon

Sorry - I forgot some indices:
Y = ROT90_3D(X,1,1) equals:
  M = PERMUTE(X, [1,3,2]); Y = M(:, size(X,3):-1:1, :);
Other equivalents:
ROT90_3D(X, 1, 2):
  Y = X(:, size(X, 2):-1:1, size(X, 3):-1:1);
ROT90_3D(X, 1, 3):
  Y = PERMUTE(X(:, size(X,2):-1:1, :), [1,3,2]);

For the other dimensions, this formulas are cyclical shifted. For e.g. [100 x 100 x 100] arrays this takes about 2% of the time of ROT90_3D, so I'd suggest to update the submission.

27 Oct 2009 Matt Fetterman

Hi Jan, Thanks for comments. I did update it. It is hard to write it using the permute command but hopefully got it right !

04 Nov 2009 Jan Simon

Some indices are confused: Dim=2 and 3, NumRot=1 and 3. I've used your correct working first submission for checking the results. I'll try to contact you by email.

Please login to add a comment or rating.
Updates
12 Oct 2009

In the comments, the test matrix smoki was not as I had intended.

14 Oct 2009

I corrected the description to clarify that it rotates about x, y, or z-axis.

27 Oct 2009

updated as suggested by Jan Simon. Makes it faster by removing loops !

04 Nov 2009

Thanks to Jan for sending me this corrected version !

Tag Activity for this File
Tag Applied By Date/Time
rotate Matt Fetterman 12 Oct 2009 12:36:50
3d Matt Fetterman 12 Oct 2009 12:36:50
rot90 Matt Fetterman 12 Oct 2009 12:36:50

Contact us at files@mathworks.com