使用矩阵向量乘法的多边形旋转

问题描述 投票:0回答:1

考虑具有顶点(0, 0), (1, 0), (7/10, 1), (1/2, 1/2), and (3/10, 1)的多边形。使用填充函数在Matlab中绘制此多边形的图。使用Matlab中的矩阵向​​量乘法,使用适当选择的旋转矩阵R,将此多边形旋转角度为100度。使用fill创建旋转多边形的另一个绘图。

% Makes original polygon 
X = [0 1 7/10 1/2 3/10];
Y = [0 0 1 1/2 1];
norm_poly = fill(X,Y,'k');

thetad  = 100;
R = [cosd(thetad) -sind(thetad); sind(thetad) cosd(thetad)];
C = repmat([0 0], 5, 1)';
axis([-10 10 -10 10])
V = get(norm_poly,'Vertices')';  % get the current set of vertices
V = R*(V - C) + C;             % do the rotation relative to the centre of the 
square
set(norm_poly,'Vertices',V');    % update the vertices

我将如何制作不同的图表来展示它们?旋转代码是否有意义并满足所有要求?

matlab
1个回答
0
投票

旋转本身是有道理的。要在制作第一个图表后使用hold on将多个事物绘制到同一图表中。或者你可以制作一个新的figure并在那里绘制一个新的fill

P = [0, 1, 7/10, 1/2, 3/10;
     0, 0, 1,    1/2, 1];
fill(P(1,:), P(2,:), 'k');

theta = 100;
R = @(t) [cosd(t) -sind(t); sind(t) cosd(t)];

axis([-3 3 -3 3])
grid on
V = R(theta)*P;

hold on;
fill(V(1,:), V(2,:), 'k');
© www.soinside.com 2019 - 2024. All rights reserved.