Azzera filtri
Azzera filtri

problem with rotation matrix

2 visualizzazioni (ultimi 30 giorni)
Villanova
Villanova il 15 Mag 2012
Hi, I have this U shape which is in this code. I was wondering how I could rotate it using 2-D rotation matrix.
theta = pi/2;
rotation_matrix = [cos(theta), -sin(theta); sin(theta), cos(theta)];
obstacle_matrix = [z1, z2];
obstacle_shape = obstacle_matrix * rotation_matrix;
plot(obstacle_shape)
here is my other file.
% obstacle definition
function [z1 z2] = toric_obstacle(enl_fac)
x0 = -1.2*enl_fac;
y0 = -1*enl_fac;
x1 = -0.6/enl_fac;
y1 = -0.5/enl_fac;
x2 = 0.6/enl_fac;
x3 = 1.2*enl_fac;
y3 = 0.8*enl_fac;
delta = 0.01;
z1 = zeros(1000,1);
z2 = zeros(1000,1);
%line 1
i = 0;
for x = x0:delta:x3
i = i + 1;
z1(i) = x;
z2(i) = y0;
end
%line 2
i = i - 1;
for y = y0:delta:y3
i = i + 1;
z1(i) = x3;
z2(i) = y;
end
%line 3
i = i - 1;
for x = x3:-delta:x2
i = i + 1;
z1(i) = x;
z2(i) = y3;
end
%line 4
i = i - 1;
for y = y3:-delta:y1
i = i + 1;
z1(i) = x2;
z2(i) = y;
end
%line 5
i = i - 1;
for x = x2:-delta:x1
i = i + 1;
z1(i) = x;
z2(i) = y1;
end
%line 6
i = i - 1;
for y = y1:delta:y3
i = i + 1;
z1(i) = x1;
z2(i) = y;
end
%line 7
i = i - 1;
for x = x1:-delta:x0
i = i + 1;
z1(i) = x;
z2(i) = y3;
end
%line 8
i = i - 1;
for y = y3:-delta:y0
i = i + 1;
z1(i) = x0;
z2(i) = y;
end
i = i - 1;
z1 = z1(1:i);
z2 = z2(1:i);

Risposta accettata

Geoff
Geoff il 15 Mag 2012
Your code works fine, but you're just not plotting it correctly.
plot(obstacle_shape(:,1), obstacle_shape(:,2));
You might also want to correct the aspect ratio:
pos = get(gcf, 'Position');
aspect = pos(3) / pos(4);
set(gca, 'XLim', [-2,2]);
set(gca, 'YLim', [-2,2] / aspect);
By the way, your rotation is backwards. It is rotating clockwise, which is unconventional. You should negate both the sin terms in your rotation matrix.

Più risposte (0)

Categorie

Scopri di più su 3-D Scene Control in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by