Rotation of a function around the origin by any angle

4 views (last 30 days)
theoasla on 21 Nov 2021
Commented: theoasla on 22 Nov 2021
Hello,
Hope you're all doing well. I've come back to Matlab for a project and have been stuck on a problem since a few hours.
I have a 2D function and want to rotate it around the origin. I used a rotation matrix and everything works fine for angle of 45°;90;180... But if I want to rotate it by let's say 10° then the graph look nothin like the original and looks just like a straight line.
Here is the code :
clear all clc
d=0:1:7500; %distance behind wind turbine
angle=45; %angle of the incoming electromagnetic wave
frequency = 8000*10^(6); %Mhz
lambda = 3e8/(frequency); %wavelength
x=radius/lambda; %rapport rayon sur longueur d'onde
for i = 1:length(d)
if d(i)>d0
y(i)=yb_d;
end
end
A(1,:)=d;
A(2,:)=y;
Rotx=[cosd(angle) -sind(angle); sind(angle) cosd(angle)]
Rotx = 2×2
0.7071 -0.7071 0.7071 0.7071
rotXY =Rotx*A
rotXY = 2×7501
-2.1213 -1.4159 -0.7104 -0.0049 0.7005 1.4060 2.1115 2.8169 3.5224 4.2278 4.9333 5.6388 6.3442 7.0497 7.7552 8.4606 9.1661 9.8716 10.5770 11.2825 11.9879 12.6934 13.3989 14.1043 14.8098 15.5153 16.2207 16.9262 17.6317 18.3371 2.1213 2.8301 3.5388 4.2476 4.9563 5.6651 6.3738 7.0826 7.7913 8.5001 9.2088 9.9176 10.6263 11.3351 12.0438 12.7526 13.4613 14.1701 14.8788 15.5876 16.2963 17.0051 17.7138 18.4226 19.1313 19.8401 20.5488 21.2576 21.9663 22.6751
u=rotXY(1,:)
u = 1×7501
-2.1213 -1.4159 -0.7104 -0.0049 0.7005 1.4060 2.1115 2.8169 3.5224 4.2278 4.9333 5.6388 6.3442 7.0497 7.7552 8.4606 9.1661 9.8716 10.5770 11.2825 11.9879 12.6934 13.3989 14.1043 14.8098 15.5153 16.2207 16.9262 17.6317 18.3371
v=rotXY(2,:)
v = 1×7501
2.1213 2.8301 3.5388 4.2476 4.9563 5.6651 6.3738 7.0826 7.7913 8.5001 9.2088 9.9176 10.6263 11.3351 12.0438 12.7526 13.4613 14.1701 14.8788 15.5876 16.2963 17.0051 17.7138 18.4226 19.1313 19.8401 20.5488 21.2576 21.9663 22.6751
plot(u,v,'b-')
xlabel('distance behind wind turbine')
hold on As you see I made sure to work in degrees and not radians... and again, if I'm using angle that are multiples of 45° it works fine, but for random angles it doesn't...
Anyone knows why or can help?
Thanks
theoasla on 22 Nov 2021
It actually does as @Image Analyst pointed out... thanks for the heads up tho! :)

Image Analyst on 21 Nov 2021
This seems to work for me. I think you just didn't have your axes set up with equal scaling so it didn't look right.
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
d=0:1:7500; %distance behind wind turbine
angle = 30; %angle of the incoming electromagnetic wave
% Ask user for one integer number.
defaultValue = angle;
titleBar = 'Enter angle';
userPrompt = 'Enter the angle';
dialogBoxWidth = 40;
caUserInput = inputdlg(userPrompt, titleBar, [1, dialogBoxWidth], {num2str(defaultValue)});
if isempty(caUserInput),return,end % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
angle = -round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(angle)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
angle = defaultValue;
message = sprintf('I said it had to be an integer.\nTry replacing the user.\nI will use %d and continue.', angle);
uiwait(warndlg(message));
end
frequency = 8000*10^(6); %Mhz
lambda = 3e8/(frequency); %wavelength
x=radius/lambda; %rapport rayon sur longueur d'onde
for i = 1:length(d)
if d(i)>d0
y(i)=yb_d;
else
end
end
A(:, 1) = d(:);
A(:, 2) = y(:);
% Compute the rotation matrix.
rotationMatrix = [cosd(angle) -sind(angle); sind(angle) cosd(angle)]
% Rotate the coordinates.
rotXY = A *rotationMatrix;
plot(d, y,'r-', 'LineWidth', 2)
axis equal
u=rotXY(:, 1);
v=rotXY(:, 2);
hold on
plot(u,v,'b-', 'LineWidth', 2)
xlabel('distance behind wind turbine')
grid on;
legend('Original', 'Rotated')
Here it is for an angle of 30 degrees: Matt J on 21 Nov 2021
@theoasla Since your problem seens to have been resolved, you should Accept-click @Image Analyst's answer.