Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 20:41   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 旋转矩阵按列而不是按行计算

我有一个名为forest的类和一个名为fixedPositions的属性,该属性存储100点(x,y),它们在MatLab中存储为250x2(行x列)。当我选择“ fixedPositions”时,我可以单击散点图,它将绘制点。

现在,我想旋转绘制的点,并且有一个旋转矩阵,可以使我这样做。

下面的代码应该工作:

theta = obj.heading * pi / 180;表观= [cos(theta)-sin(theta); sin(theta cos(theta)] * obj.fixedPositions;

但这不会。我得到这个错误。

???使用==> mtimes时出错。内部矩阵尺寸必须一致。

错误==>地标> 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 PS:如果您将其中一行更改为:obj.fixedPositions = 100 * rand([2,numberOfTrees])。* sign(rand([2,numberOfTrees])-0.5);

一切都会正常工作...它不会情节。

ans = obj.fixedPositions; ans';将其翻转到我需要绘制的位置,但是必须有一种避免这种情况的方法?



回答:

我想您想在乘以旋转前后对矩阵进行转置。如果矩阵是实数,则可以执行以下操作:

apparent = ([cos(theta) -sin(theta) ; sin(theta) cos(theta)] * (obj.fixedPositions)')';

更多&回答...
poster 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 01:20


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.