Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Quicker way to rotate a 3 dimensional array?
Date: Mon, 28 Jan 2013 07:31:08 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 18
Message-ID: <ke59fr$8uo$1@newscl01ah.mathworks.com>
References: <ke4thb$s7j$1@newscl01ah.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1359358268 9176 172.30.248.45 (28 Jan 2013 07:31:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 28 Jan 2013 07:31:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:787528

"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