rotating a 3D point around the y axis in matlab
I have been provided with a rotation matrix to use:
and have entere开发者_Go百科d 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 is most likely not a real positive integer or a logical.
精彩评论