"kees de Kapper" <kees_de_kapper@hotmail.com> wrote in message <goqmqi$7m5$1@fred.mathworks.com>...
> 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(((x256)/20).^2)'*(exp(((y256)/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)*(xx0)sin(Theta)*(yy0)+x0;
> y2 = sin(Theta)*(xx0)+cos(Theta)*(xx0)+y0;
>
> Then apply to the function:
> z2 = (exp(((x2256)/20).^2)'*(exp(((y2256)/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
Hi Kees,
you make the 2D gaussian by multiplying the profile in y by the profile in x, this works only if the axes are parallel to your coordinate axes.
When you rotate your gaussian you have to calculate all positions as no decomposition is possible.
try
Theta = pi/4
x0 = 256; y0 = 256;
[x,y] = meshgrid(1:512,1:512);
x2 = cos(Theta)*(xx0)sin(Theta)*(yy0)+x0;
y2 = sin(Theta)*(xx0)+cos(Theta)*(xx0)+y0;
z2 = (exp(((x2256)/20).^2).*(exp(((y2256)/40).^2)));
imagesc(z2); colormap(gray);
hth
kinor
