rotmat
四元数の回転行列への変換
説明
は、四元数 rotationMatrix
= rotmat(quat
,rotationType
)quat
を等価の回転行列表現に変換します。
例
点の回転に使用する四元数を定義します。
theta = 45; gamma = 30; quat = quaternion([0,theta,gamma],"eulerd","ZYX","point")
quat = quaternion
0.8924 + 0.23912i + 0.36964j + 0.099046k
四元数を回転行列に変換します。
rotationMatrix = rotmat(quat,"point")
rotationMatrix = 3×3
0.7071 -0.0000 0.7071
0.3536 0.8660 -0.3536
-0.6124 0.5000 0.6124
回転行列を検証するには、y 軸および x 軸を中心とした回転に対応する 2 つの回転行列を直接作成します。回転行列を乗算して、rotmat
の出力と比較します。
theta = 45; gamma = 30; ry = [cosd(theta) 0 sind(theta) ; ... 0 1 0 ; ... -sind(theta) 0 cosd(theta)]; rx = [1 0 0 ; ... 0 cosd(gamma) -sind(gamma) ; ... 0 sind(gamma) cosd(gamma)]; rotationMatrixVerification = rx*ry
rotationMatrixVerification = 3×3
0.7071 0 0.7071
0.3536 0.8660 -0.3536
-0.6124 0.5000 0.6124
座標系の回転に使用する四元数を定義します。
theta = 45; gamma = 30; quat = quaternion([0,theta,gamma],"eulerd","ZYX","frame")
quat = quaternion
0.8924 + 0.23912i + 0.36964j - 0.099046k
四元数を回転行列に変換します。
rotationMatrix = rotmat(quat,"frame")
rotationMatrix = 3×3
0.7071 -0.0000 -0.7071
0.3536 0.8660 0.3536
0.6124 -0.5000 0.6124
回転行列を検証するには、y 軸および x 軸を中心とした回転に対応する 2 つの回転行列を直接作成します。回転行列を乗算して、rotmat
の出力と比較します。
theta = 45; gamma = 30; ry = [cosd(theta) 0 -sind(theta) ; ... 0 1 0 ; ... sind(theta) 0 cosd(theta)]; rx = [1 0 0 ; ... 0 cosd(gamma) sind(gamma) ; ... 0 -sind(gamma) cosd(gamma)]; rotationMatrixVerification = rx*ry
rotationMatrixVerification = 3×3
0.7071 0 -0.7071
0.3536 0.8660 0.3536
0.6124 -0.5000 0.6124
3 行 1 列の正規化された quaternion ベクトルを作成します。
qVec = normalize(quaternion(randn(3,4)));
quaternion 配列を回転行列に変換します。rotmatArray
のページは、qVec
の線形インデックスに対応します。
rotmatArray = rotmat(qVec,"frame");
qVec
と rotmatArray
が回転のシーケンスに対応すると仮定します。複数の四元数回転を単一の表現に統合してから、任意に初期化した直交座標点に四元数回転を適用します。
loc = normalize(randn(1,3)); quat = prod(qVec); rotateframe(quat,loc)
ans = 1×3
0.9524 0.5297 0.9013
複数の回転行列を単一の表現に統合してから、同じ初期直交座標点に回転行列を適用します。四元数回転と回転行列の結果を同じ方向で検証します。
totalRotMat = eye(3); for i = 1:size(rotmatArray,3) totalRotMat = rotmatArray(:,:,i)*totalRotMat; end totalRotMat*loc'
ans = 3×1
0.9524
0.5297
0.9013
入力引数
変換する四元数。quaternion
オブジェクト、または任意の次元の quaternion
オブジェクトの配列として指定します。
rotationMatrix
出力によって表現される回転のタイプ。"frame"
または "point"
として指定します。
データ型: char
| string
出力引数
アルゴリズム
次の形式の四元数を考えます。
座標系の回転に対応する等価の回転行列は次のように定義されます。
点の回転に対応する等価の回転行列は、座標系の回転行列の転置です。
参照
[1] Kuipers, Jack B. Quaternions and Rotation Sequences: A Primer with Applications to Orbits, Aerospace, and Virtual Reality. Princeton, NJ: Princeton University Press, 2007.
拡張機能
C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)