Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

rotatepoint

四元数の点の回転

R2020a 以降

説明

rotationResult = rotatepoint(quat,cartesianPoints) は、四元数 quat を使用して直交座標点を回転します。四元数の要素は回転に使用する前に正規化されます。

Rotation

すべて折りたたむ

3 次元で点を定義します。点の座標は、常に "x""y""z" の順で指定します。可視化しやすくするために、"x"-"y" 平面上の点を定義します。

x = 0.5;
y = 0.5;
z = 0;

plot(x,y,"ko")
hold on
axis([-1 1 -1 1])

Figure contains an axes object. The axes contains a line object which displays its values using only markers.

"z" 軸を中心とする 2 つの異なる回転を指定する quaternion ベクトルを作成します。1 つは点を 45 度回転し、もう 1 つは点を -90 度回転します。rotatepoint を使用して回転を実行します。

quat = quaternion([0,0,pi/4; ...
                   0,0,-pi/2],"euler","XYZ","point");
               
rotatedPoint = rotatepoint(quat,[x,y,z])
rotatedPoint = 2×3

   -0.0000    0.7071         0
    0.5000   -0.5000         0

回転した点をプロットします。

plot(rotatedPoint(1,1),rotatedPoint(1,2),"bo")
plot(rotatedPoint(2,1),rotatedPoint(2,2),"go")

Figure contains an axes object. The axes object contains 3 objects of type line. One or more of the lines displays its values using only markers

3 次元空間で 2 つの点を定義します。これらの点を回転する四元数を定義します。最初に "z" 軸を中心に 30 度回転してから、新しい "y" 軸を中心に 45 度回転します。

a = [1,0,0];
b = [0,1,0];
quat = quaternion([30,45,0],"eulerd","ZYX","point");

rotatepoint で四元数の回転演算子を使用して両方の点を回転します。結果を表示します。

rP = rotatepoint(quat,[a;b])
rP = 2×3

    0.6124    0.5000   -0.6124
   -0.3536    0.8660    0.3536

点の元の向きと回転後の向きを可視化します。原点から各点までの線を可視化のために描画します。

plot3(a(1),a(2),a(3),"bo");

hold on
grid on
axis([-1 1 -1 1 -1 1])
xlabel("x")
ylabel("y")
zlabel("z")

plot3(b(1),b(2),b(3),"ro")
plot3(rP(1,1),rP(1,2),rP(1,3),"bd")
plot3(rP(2,1),rP(2,2),rP(2,3),"rd")

plot3([0;rP(1,1)],[0;rP(1,2)],[0;rP(1,3)],"k")
plot3([0;rP(2,1)],[0;rP(2,2)],[0;rP(2,3)],"k")
plot3([0;a(1)],[0;a(2)],[0;a(3)],"k")
plot3([0;b(1)],[0;b(2)],[0;b(3)],"k")

Figure contains an axes object. The axes object with xlabel x, ylabel y contains 8 objects of type line. One or more of the lines displays its values using only markers

入力引数

すべて折りたたむ

回転を定義する四元数。quaternion オブジェクトまたは quaternion オブジェクトのベクトルとして指定します。quatcartesianPoints のサイズは次のように互換性がなければなりません。

  • length(quat) == size(cartesianPoints,1) または

  • length(quat) == 1 または

  • size(cartesianPoints,1) == 1

3 次元直交座標点。単一の点を表す 1 行 3 列の数値ベクトルまたは N 点を表す N 行 3 列の数値行列として指定します。quatcartesianPoints のサイズは次のように互換性がなければなりません。

  • length(quat) == size(cartesianPoints,1) または

  • length(quat) == 1 または

  • size(cartesianPoints,1) == 1

データ型: single | double

出力引数

すべて折りたたむ

四元数の回転を使用して定義される回転後の直交座標点。1 行 3 列の数値ベクトルまたは数値行列として返されます。

quat がスカラー quaternion オブジェクトであり、cartesianPoints が単一の点を表す 1 行 3 列のベクトルである場合、rotationResult は 1 行 3 列のベクトルです。それ以外の場合、rotationResult は M 行 3 列の行列です。ここで、M は length(quat)size(cartesianPoints,1) の最大値です。

データ型: single | double

アルゴリズム

四元数の点の回転では、指定された四元数に従って R3 で指定された点を回転します。

Lq(u)=quq*

ここで、q は四元数であり、* は共役を表します。u は回転する点であり、四元数として指定します。

便宜上、関数 rotatepointR3 の点を受け取り、R3 の点を返します。任意の四元数 q = a + bi + cj + dk と任意の座標 [x,y,z] が指定された次のような関数呼び出しを考えます。

rereferencedPoint = rotatepoint(q,[x,y,z])
関数 rotatepoint は次の操作を実行します。

  1. [x,y,z] を四元数に変換します。

    uq=0+xi+yj+zk

  2. 四元数 q を正規化します。

    qn=qa2+b2+c2+d2

  3. 回転を適用します。

    vq=quqq*

  4. 四元数の出力 vq を変換して R3 に戻します。

拡張機能

C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。

バージョン履歴

R2020a で導入