I have a simple quaternion implementation for object rotation. If I create two quaternions representing rotations about the same axis-aligned vector (i.e. along the X, Y, or Z axis) the result is the same as a single rotation by the sum of their magnitudes (i.e. rotating by PI/2 then PI/2 again is the same as rotating by PI). That's good.
As soon as the axis of rotation is not axis-aligned, then the concatenations diverge from the expected (rotating by PI/2 then PI/2 again is not the same as rotating by PI). That's not good.
After poring over my code for a couple days, I'm not seeing anything wrong, so let me ask now: Am I in some way fundamentally misunderstanding how quaternions work? I'm reasoning about the quaternions in terms of the axis-angle rotations they represent, because frankly I don't completely understand quaternions.
If not, can you look at my code? :-) I just pushed the whole thing (written in Java--I'm targeting Android) to GitHub: https://github.com/wtracy/quaternions Under the Quaternions directory is an Eclipse project. (You shouldn't need Eclipse to read anything, but it's convenient.) The quaternion class is under the src/ folder. In the test/ folder are JUnit tests and stubs of the classes needed to run my Quaternion class.
I've done my best to make my code and tests easy to follow. I feel dumb asking the internet to find a bug in my code, but I am clean out of ideas. :-P