我有一个名为forest的类,一个名为fixedPositions的属性存储100个点(x,y),它们在MatLab中存储为250x2(行x列)。当我选择'fixedPositions'时,我可以点击散点图并绘制点。旋转矩阵按列计算而不是按行计算
现在,我想旋转绘制点,我有一个旋转矩阵,这将允许我这样做。
在下面的代码应工作:
THETA = obj.heading * PI/180; apparent = [cosθ-sinθ; sin(theta)cos(theta)] * obj.fixedPositions;
但它不会。我得到这个错误。
???错误使用==> mtimes 内部矩阵维度必须一致。
错误在==>地标> landmarks.get.apparentPositions at 22 apparent = [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;答;将它转换为我需要绘制的内容,但是必须有一种方法来避免这种情况?
钱!谢谢。对于像这样的动画来说,最好的方法就是消除散点图并重绘它? – 2010-05-03 23:43:33