image thumbnail
from Rotate a plot by Jon André Adsersen
Simple function that rotates a plot in 2D about a given rotationpoint.

rotation_paelevaerk.m
%
clc
clear all 
close all

%%%----- Input ---------------------------------------------------------%%%
% The two following vectors contain the x- and y-coordinates of the members
% and is typed in the form: x=[m1x1 m1x2 m2x1 m2x5 ... mnx1 mnx2], 
% y=[m1y1 m1y2 m2y1 m2y2 ... mny1 mny2], where:
% m1x1 is the first x-coordinate of member nr. 1
% m1x2 is the second x-coordinate of member nr. 1
% m1y1 is the first y-coordinate of member nr. 1
% m1y2 is the second y-coordinate of member nr. 1
% and so on..
x=[0 0 1 1 4-tand(18.4)*3 4 4.5+tand(18.4)*3 4.5 0 4.5]; % X-coordinates of members.

y=[-3 0 -3 0 -3 0 -3 0 0 0]; % Y-coordinates of members.

vr=-10; % Rotationangle [degrees]. Pos. counter clockwise.

xo=0; % X-coordinate of rotationspoint.

yo=0; % Y-coordinate of rotationspoint.
%%%---------------------------------------------------------------------%%%

% Definition of colors used in following plot.
lightgrey = [0.7,0.7,0.7];
grey = [0.5,0.5,0.5];

% Plot
hold all

scatter(xo,yo,'Linewidth',2); % Plot of rotationpoint.

% Rotation of points
[x2 y2]=rotate2d(xo,yo,x,y,vr); % The function rotate2d is used to rotate
% all points.

for i=1:2:length(x) % Plot of points after rotation.
    plot(x2(i:i+1),y2(i:i+1),'Linewidth',2,'Color',lightgrey)
end
for i=1:2:length(x) % Plot of points before the rotation.
    plot(x(i:i+1),y(i:i+1),'Linewidth',2,'Color',grey)
end
for i=1:length(x) % Plot of dashed lines.
    plot([x(i) x2(i)],[y(i) y2(i)],'--','Linewidth',1,'Color','Blue')
end
% Plot of dashed lines between the points before and after rotation.

axis equal

% Definition of the axes
axis([floor(min(min([x,x2,xo]))-0.5) ceil(max(max([x,x2,xo]))+0.5) floor(min(min([y,y2,yo]))-0.5) ceil(max(max([y,y2,yo]))+0.5)])

Contact us