Rotation and direction problem

I think this line is the root of the confusion:

self.rad = 2 * math.acos(self.rot.z)

A quaternion is represented by a vector part (x,y,z) and an angle part (w). The vector part may be zero (the unit quaternion is (0,0,0,1)). And the sum of all elements squared is 1.

Simply taking the vector part’s z component and using it as an angle doesn’t work. Using the “w” part should give better results, since in this example we’re rotating around Z, but I would go with @sven’s suggestion since it is easier to read and understand.

Here’s an excellent introductory presentation about quaternions.

8 Likes