matlab中的三维坐标系与旋转
2019-03-27 09:55阅读:
1. matlab中的三维坐标系
matlab中的三维坐标系是使用的右手坐标系;
输入以下代码:
>> plot3(0,0,0)
>> xlabel('axis X')
>> ylabel('axis Y')
>> zlabel('axis Z')

可以看出是个很明显的右手坐标系。
2. matlab中的欧拉角和四元数旋转
euler angles ----> quaternion ----> dcm
---->rotation
MATLAB中欧拉角旋转基本遵循以上步骤,欧拉角、四元数、旋转矩阵之间是可以相互转换的,具体可以参见help文档中的Aerospace
Toolbox ----> Functions ----> Axes ----> Axes
Transformations中查看。
假设我在三维坐标系中有一向量r,绕Z轴旋转90度,结果为:
close all; clear; clc; r = [
0
1
1
]; % 默认的旋转顺序是ZYX,所以[
90 0
0]表示绕Z轴旋转90度 angle = [
90
0 0] * pi /
180;
quaternion =
angle2quat(angle(
1),angle(
2),angle(
3));
n = quatrotate(quaternion,r)
结果:
n =
1.0000
0.0000
1.0000
原始向量在YZ平面上[0 1 1],旋转后的平面在XZ的平面上[1 0 1],可以看出从Z轴的正方向来看,顺时针旋转;
再次验证:
close all; clear; clc; r = [
0
1 1]; %
默认的旋转顺序是ZYX,所以[
0 0
-
90]表示绕X轴旋转90度 angle = [
0
0 -
90] * pi /
180;
quaternion =
angle2quat(angle(
1),angle(
2),angle(
3));
n =
quatrotate(quaternion,r) 结果: n =
0 -
1.0000 1.0000
结论:MATLAB中的默认坐标系是右手坐标系,且进行欧拉角旋转时,顺着轴的正方向来看,顺时针方向为正,逆时针方向为负。
另外,MATLAB自带rotate函数,解释如下:
rotate Rotate object in
specified direction Syntax rotate(h,direction,alpha)
rotate(...,origin) Description The rotate function rotates a
graphics object in
three-dimensional space, according to the right-
hand rule.
rotate(h,direction,alpha) rotates the graphics
object h by alpha degrees. direction
is a
two- or three-element vector that describes the axis of rotation
in conjunction with the origin.
rotate(...,origin) specifies the origin of the axis of
rotation as a three-element vector. The
default origin
is the center of the plot
box.

此旋转函数可选择三维空间中的图像,遵循右手坐标系,顺着轴的正方向来看,且逆时针方向为正,顺时针方向为负。