Quaternion Rotation

asked 2014-05-03 03:10:26 -0500

Juni gravatar image

updated 2014-05-03 03:13:19 -0500

I want to rotate point by quaternion. It it is to use library for rotation Quaternion or Matrix. But now I want to do it by myself. I wrote some code. but I'm not sure it is right. Before that code, I used Quaternion multiplication that has been implemented in tf::Quaternion(or Bullet).

now here is question.

I want to rotate [orientation quaternion] by multiplying [rotation quaternion]. Rotating Order is [ZYX].

//tf::Quaternion(x, y, z, w);
tf::Quaternion Qorien = tf::Quaternion(0.0, 0.0, 0.0, 1.0);
double angleX, angleY, angleZ;
angleX = 1.0;
angleY = 4.0;
angleZ = 2.0;

double cosX,sinX,cosY,sinY,cosZ,sinZ;
cosX = cos(angleX/2); sinX = sin(angleX/2);
cosY = cos(angleY/2); sinY = sin(angleY/2);
cosZ = cos(angleZ/2); sinZ = sin(angleZ/2);
tf::Quaternion QrotX,QrotY,QrotZ;

QrotX = tf::Quaternion( 1.0*sinX,
                        0.0*sinX,
                        0.0*sinX,
                        cosX);
QrotY = tf::Quaternion( 0.0*sinY,
                        1.0*sinY,
                        0.0*sinY,
                        cosY);
QrotZ = tf::Quaternion( 0.0*sinZ,
                        0.0*sinZ,
                        1.0*sinZ,
                        cosZ);
tf::Quaternion Qtotal = QrotX*QrotY*QrotZ;
Qorien = Qtotal * Qorien;

/*
now [Qorien] is the Orientation Quaternion that represents new orientation
after rotating by an order Z->Y->X.
/*
edit retag flag offensive close merge delete

Comments

So... the question is... ?

AbuIbra gravatar image AbuIbra  ( 2014-05-03 19:23:40 -0500 )edit

Sorry, I forgot to write question... I wonder if my solution was right.

Juni gravatar image Juni  ( 2014-05-03 19:40:20 -0500 )edit