简体   繁体   English

在Matlab中绕y轴旋转3D点

[英]rotating a 3D point around the y axis in matlab

I have been provided with a rotation matrix to use: 我已获得要使用的旋转矩阵:

矩阵

and have entered the matrix into my function as 并将矩阵输入到我的函数中

theta = radians(theta);
Ry(theta) = [cos(theta) 0 sin(theta); 0 1 0; -sin(theta) 0 cos(theta)];
newpose = pos*Ry(theta);

yet whenever the function reaches this stage it returns the error 但是无论何时函数到达此阶段,它都会返回错误

??? ??? Subscript indices must either be real positive integers or logicals. 下标索引必须是实数正整数或逻辑值。

any help much appreciated 任何帮助非常感谢

The problem is the Ry(theta) . 问题是Ry(theta) Call it something like Ry_theta if you want it to be a variable, or put it in an actual function. 如果希望它成为变量,则将其Ry_theta ,或将其放入实际函数中。 This should work: 这应该工作:

theta = radians(theta);
Ry_theta = [cos(theta) 0 sin(theta); 0 1 0; -sin(theta) 0 cos(theta)];
newpose = pos*Ry_theta;

Or - if you want a more reusable solution: 或者-如果您想要更可重用的解决方案:

% in your existing file:
theta = radians(theta);
newpose = pos*rotationAboutYAxis(theta);;

% in a file called rotationAboutYAxis.m:
function Ry = rotationAboutYAxis(theta)
Ry = [cos(theta) 0 sin(theta); 0 1 0; -sin(theta) 0 cos(theta)];
Ry(theta) 

theta最有可能不是实数或逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM