I want to rotate by quaternion as left hand coordinate

Home / Uncategorized / I want to rotate by quaternion as left hand coordinate

Question:
Vector v = (x, y, z),

Quaternion q = (u, w), u is unreal vector.

Cunjugate Quaternion q* = (-u, w)

Quaternion multiply

pg =
( p4,-p3, p2, p1)(q1)

( p3, p4,-p1, p2)(q2)

(-p2, p1, p4, p3)(q3)

(-p1,-p2,-p3, p4)(q4)

and this is real code
public Quaternion Multiply(Quaternion quaternion)
{
Quaternion tmpQuaternion = new Quaternion();

tmpQuaternion.x = quaternion.x * w – quaternion.y * z + quaternion.z * y + quaternion.w * x;
tmpQuaternion.y = quaternion.x * z + quaternion.y * w – quaternion.z * x + quaternion.w * y;
tmpQuaternion.z = – quaternion.x * y + quaternion.y * x + quaternion.z * w + quaternion.w * z;
tmpQuaternion.w = – quaternion.x * x – quaternion.y * y – quaternion.z * z + quaternion.w * w;

return tmpQuaternion;
}

q = (sin(θ/2)n, cos(θ/2)) (n is rotation axis),

rotation operator Rq(v) = qvq*(q is unit quaternion),
public void Rotate(Common_Math.Matrix1X4 axis, int degree)
{
double radian = Math.toRadians(degree);
Common_Math.Quaternion rotateQuaternion = new Common_Math.Quaternion(axis.getX() * Math.sin(radian * 0.5), axis.getY() * Math.sin(radian * 0.5), axis.getZ() * Math.sin(radian * 0.5), Math.cos(radian * 0.5));
rotateQuaternion.Normalize();

objectMatrix.setxVector(rotateQuaternion.Multiply(objectMatrix.xVector().Multiply(rotateQuaternion.Reverse())));
objectMatrix.setyVector(rotateQuaternion.Multiply(objectMatrix.yVector().Multiply(rotateQuaternion.Reverse())));
objectMatrix.setzVector(rotateQuaternion.Multiply(objectMatrix.zVector().Multiply(rotateQuaternion.Reverse())));

objectMatrix.xVector().Normalize();
objectMatrix.yVector().Normalize();
objectMatrix.zVector().Normalize();
}

when I try this code I got a result and I think this result is right hand coordinate, but I want to get left hand coordinate.

Is there any problem in my code or should I do some change there?


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *