matlab中的三維坐標系與旋轉


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.

此旋轉函數可選擇三維空間中的圖像,遵循右手坐標系,順着軸的正方向來看,且逆時針方向為正,順時針方向為負。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM