MATLAB - 如何使用旋转矩阵旋转轨道/球体?

时间:2015-04-17 20:15:52

标签: matlab matrix rotation orbit

我正在尝试使用下面给出的旋转矩阵旋转“轨道”:

[cos(angle) -sin(angle) 0; 

 sin(angle) cos (angle) 0;

 0           0          1 ]

我认为应该做的第一件事是使用sphere():

[x y z] = sphere;

然后在向量中将x,y和z连接在一起:

xyz = [x; y; z];

rotatMat = [cos(angle) -sin(angle) 0; sin(angle) cos (angle) 0; 0  0  1 ];

乘以旋转矩阵和xyz以旋转轨道:

rotated = rotatMat .* xyz;

但是,xyz62x22尺寸而我的rotatMat仅为3x3,因此我无法将它们相乘。

我该如何解决这个问题?

提前谢谢。

2 个答案:

答案 0 :(得分:1)

你必须使用*运算符进行矩阵乘法运算,而不是.*进行逐元素乘法运算。

此外,您的xyz矩阵的大小应为n-by-3(而不是62-by-22),您必须使用xyz*rotatMat'才能正确匹配尺寸。或者,您可以xyz大小为3-by-n,并使用语法rotatMat*xyz

最佳,

答案 1 :(得分:0)

xyz = [x(:) y(:) z(:)].'; %'// put x, y, z as rows of a matrix
xyz_rotated = rotatMat*xyz %// use matrix multiplication
x_rotated = reshape(xyz_rotated(1,:), size(x)); %// reshape transformed rows
y_rotated = reshape(xyz_rotated(2,:), size(x));
z_rotated = reshape(xyz_rotated(3,:), size(x));