【发布时间】:2010-05-03 22:54:49
【问题描述】:
我有一个名为 forest 的类和一个名为 fixedPositions 的属性,它存储 100 个点 (x,y),它们在 MatLab 中存储为 250x2(行 x 列)。当我选择“fixedPositions”时,我可以单击散点图,它会绘制点。
现在,我想旋转绘制的点,我有一个旋转矩阵可以让我这样做。
下面的代码应该可以工作:
theta = obj.heading * pi/180; 明显 = [cos(theta) -sin(theta) ; sin(theta) cos(theta)] * obj.fixedPositions;
但它不会。我收到此错误。
???使用 ==> 时出错 内部矩阵尺寸必须一致。
==> 地标>landmarks.get.apparentPositions 在 22 处出错 明显 = [cos(theta) -sin(theta) ; sin(theta) cos(theta)] * obj.fixedPositions;
当我更改 forest.fixedPositions 以存储变量 2x250 而不是 250x2 时,上面的代码将起作用,但它不会绘图。我将在模拟中不断地绘制 fixedPositions,所以我宁愿保留它,而是让旋转工作。
有什么想法吗?
此外,固定位置是 xy 点的位置,就好像您直视前方一样。即标题 = 0。标题设置为 45,这意味着我想将点顺时针旋转 45 度。
这是我的代码:
classdef landmarks
properties
fixedPositions %# positions in a fixed coordinate system. [x, y]
heading = 45; %# direction in which the robot is facing
end
properties (Dependent)
apparentPositions
end
methods
function obj = landmarks(numberOfTrees)
%# randomly generates numberOfTrees amount of x,y coordinates and set
%the array or matrix (not sure which) to fixedPositions
obj.fixedPositions = 100 * rand([numberOfTrees,2]) .* sign(rand([numberOfTrees,2]) - 0.5);
end
function apparent = get.apparentPositions(obj)
%# rotate obj.positions using obj.facing to generate the output
theta = obj.heading * pi/180;
apparent = [cos(theta) -sin(theta) ; sin(theta) cos(theta)] * obj.fixedPositions;
end
end
end
附:如果将一行更改为: obj.fixedPositions = 100 * rand([2,numberOfTrees]) .* sign(rand([2,numberOfTrees]) - 0.5);
一切都会好起来的......它只是不会情节。
ans = obj.fixedPositions;回答';会将其翻转为我需要绘制的内容,但必须有办法避免这种情况?
【问题讨论】:
标签: matlab matrix rotation linear-algebra robotics