Advertisement

Quaternion questions

Started by November 17, 2002 10:59 AM
0 comments, last by Zorodius 22 years, 3 months ago
I''ve created a Quaternion class. It seems to work just fine, but I''m wondering: 1) How exactly am I supposed to transform a point by a quaternion? I''ve tried, where Q is a quaternion and P is a point of the form <0, v>, P = Q times P times Q''s conjugate, and this seems to work, but I was sort of hoping there wouldn''t be more than one quaternion multiplication per point I want to transform. It still seems to work even if I take off the multiplication by Q''s conjugate, but it''s rotating about half as quickly as before. This makes it seem awfully temping to just double the rotation speed but I think I''d regret a lame hack like that in the long run. What''s the right way to transform a point by a quaternion? 2) If I have a unit quaternion, should I re-normalize it after every time I multiply it by another quaternion? 3) My quaternion multiplication takes 16 multiplications, 12 additions/subtractions, and 4 assignments. Is this pretty much normal, or am I missing out on a faster way of doing it?
You don't need to vote for the "lesser of two evils"! Learn about Instant Runoff Voting, the simple cure for a broken democracy!
> What''s the right way to transform a point by a quaternion?

P = Q times P times Q''s conjugate. There''s no other way: doing Q times P rotating twice as fast gives incorrect results.

> If I have a unit quaternion, should I re-normalize it after
> every time I multiply it by another quaternion?

You don''t need to, but it''s not a bad idea. Multiplying two unit quaternions should give you another unit quaternion. Roundng errors mean that in general the result will not be exactly a unit vector and doing a series of multiplications will produce a series of quaternions getting more and more un-unit like.

Eventually you end up with quaternions so wrong that they will cause problems, but it''s difficult to say when this will happen. You can test them but to do this you have to take their length, and if you do this you may as well use it to renormalise them.

> My quaternion multiplication takes 16 multiplications, 12
> additions/subtractions, and 4 assignments. Is this pretty much
> normal, or am I missing out on a faster way of doing it?

Sounds about right. Many modern processors will combine the multiply-add into a single instruction, so it needs only 16 arithmetic operations. You can accelerate it further on a SIMD (e.g. MMX, SSE) processor but whether this is worth doing will depend on how much quaternion maths you are doing.
John BlackburneProgrammer, The Pitbull Syndicate

This topic is closed to new replies.

Advertisement