【问题标题】:Polygon Rotation using matrix-vector multiplication使用矩阵向量乘法的多边形旋转
【发布时间】:2018-03-02 06:38:21
【问题描述】:

考虑具有顶点(0, 0), (1, 0), (7/10, 1), (1/2, 1/2), and (3/10, 1) 的多边形。使用填充函数在 Matlab 中绘制此多边形的图。 Rotate this polygon by an angle of 100 degrees using matrix-vector multiplication in Matlab with an appropriately chosen rotation matrix R. Make another plot of the rotated polygon using 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

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

【问题讨论】:

  • 您是否只是在寻找一种显示两个不同图的方法?或者关于轮换的建议?在前一种情况下,标题具有误导性。
  • 两者,很抱歉造成混淆。我想确保我的代码有意义。我还需要弄清楚如何显示两个不同的图
  • C = repmat([0 0], 5, 1)'; 不是多边形的中心。

标签: matlab


【解决方案1】:

旋转本身是有意义的。要将多个事物绘制到同一个图表上,请在制作第一个绘图后使用 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');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 2020-10-29
    • 1970-01-01
    相关资源
    最近更新 更多