我正在尝试使用下面给出的旋转矩阵旋转“轨道”:
[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;
但是,xyz
为62x22
尺寸而我的rotatMat
仅为3x3
,因此我无法将它们相乘。
我该如何解决这个问题?
提前谢谢。
答案 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));