简体   繁体   中英

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) . Call it something like Ry_theta if you want it to be a variable, or put it in an actual function. 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最有可能不是实数或逻辑。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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