Path: news.mathworks.com!not-for-mail
From: "kees de Kapper" <kees_de_kapper@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: How to rotate a 2D function
Date: Fri, 6 Mar 2009 08:28:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 31
Message-ID: <goqmqi$7m5$1@fred.mathworks.com>
Reply-To: "kees de Kapper" <kees_de_kapper@hotmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1236328082 7877 172.30.248.35 (6 Mar 2009 08:28:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 6 Mar 2009 08:28:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 345740
Xref: news.mathworks.com comp.soft-sys.matlab:522949


Dear all,

I have, probably, a stupid question with hopefully an easy answer.

I have got a 2D function, say a simple Gaussian: 

x = 1:1:512;
y = 1:1:512;
z = (exp(-((x-256)/20).^2)'*(exp(-((y-256)/40).^2);
%imagesc(z); colormap(gray); 

This gives a Gaussian with different length at the axes.

Now I want to rotate this function around its center. So, I thought to transform the coordinates, thus:

x0 = 256; y0 = 256;
x2 = cos(Theta)*(x-x0)-sin(Theta)*(y-y0)+x0;
y2 = sin(Theta)*(x-x0)+cos(Theta)*(x-x0)+y0;

Then apply to the function:
z2 = (exp(-((x2-256)/20).^2)'*(exp(-((y2-256)/40).^2);
%imagesc(z); colormap(gray); 

However, this will not do the job. For example, if Theta = pi/2 then x2 = y and y2 = x, which represents the same values. Therefore no rotation is visible.

What goes wrong?
For computational speed and discretization errors I want to avoid "imrotate".

Thanks for your help.

Kees