Jump to content
• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# Sorry, but basic quaternion question

This topic is 5244 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

In my 3D Math Primer book, it says that to rotate a 3D point p by a quaternion q, the formula is p''=(q^-1)pq, assuming that quaternion multiplication is [w1w2 - v1 * v2, w1v2+w2v1+v1 x v2]. Now, that''s all fine and good, but how the heck do I multiply a 3d vector by a quaternion? How would I evaluate the product above into code that takes a Vector3 and returns a Vector3? Thanks so much!

#### Share this post

##### Share on other sites
Advertisement
IIRC, you turn the vector into a quaternion by assigning the vector to the vector portion of the quat, and setting the scalar portion to 0. It says this somewhere in the book, but it''s probably easy to overlook...

#### Share this post

##### Share on other sites
Actually, you would set the W component to 1.

#### Share this post

##### Share on other sites
No, you set the w component to 0 for a vector quaternion. You set the w component to 1 for a homogeneous point. Not the same thing.

Jim Van Verth
Essential Math for Games

#### Share this post

##### Share on other sites
According to the book, you set w to 0. Since you''re only rotating and not translating (at least as I understand it) there is no difference here between a vector and a point.

I''ve never actually rotated a point this way, though, so I can''t swear by it...

#### Share this post

##### Share on other sites
Ok, now I''m confused. You''re saying that I turn a point p into [0, px, py, pz] and then take the cross product with the conjugate of my orientation quaternion, and then take the cross product of that with the orientation quaternion itself?

#### Share this post

##### Share on other sites
"Ok, now I''m confused. You''re saying that I turn a point p into [0, px, py, pz] and then take the cross product with the conjugate of my orientation quaternion, and then take the cross product of that with the orientation quaternion itself? "

Yes, that''s right. Although I think whether you go qpq-1 or q-1pq depends on how you have your quat mult function set up.

#### Share this post

##### Share on other sites
Ok, sorry now, but how do I then convert back to a quaternion? Here''s the code I''ve written, but it''s based on the assumption that I toss out the w component for the result, and again, I have no idea if I should do that.

Vector3 transformPoint(const Vector3 &p) const{	Quaternion result;	// with the multiplication I''m using, transformation is	// p''=(q^-1)pq	// first, multiply the conjugate by the point (whose w=0 )	result.w= x*p.x + y*p.y + z*p.z;	result.x= w*p.x - z*p.y + y*p.z; 	result.y= w*p.y - x*p.z + z*p.x;	result.z= w*p.z - y*p.x + x*p.y;	// now multiply that by the original quaternion	result=result.cross(*this);	return Vector3(result.x, result.y, result.z);	}

#### Share this post

##### Share on other sites
id recommend first creating a rotationmatrix from your quaternion, and then do simple transformation with it. probably much faster and less floating point inaccuracies when working with more than one point.

the routine for this can be found somewhere in the articles section.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 9
• 13
• 82
• 11
• 10
• ### Forum Statistics

• Total Topics
632969
• Total Posts
3009595
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!