Rotation iteration through 3d space using quaternions

1.1k views Asked by At

I have a set of 3 dimensional coordinates. I have written functions which can rotate 3d vectors using quaternion multiplciation. To do this, I need an axis to rotate points around. The axes need to be unit vectors, I have a function written which will normalize a given vector. I have tried it with some simple quaternions (rotations around x,y and z axis) and it works.

I am representing a 3d object as a list of coordinates. I want to rotate the object in each way possible. For example if I was going in increments of 1 degrees, I would want to rotate the object through each 1 degree increment, it would involve (360)(360)(360) different orientations (at least I think so). Or if I was doing the same in 10 degree increments, (36)(36)(36). This is all fine, but how do I come up with an axis to rotate around?

E.g. if I write

     for x in range (0, 360, 10):
         for y in range (0, 360, 10):
             for z in range (0, 360, 10):

I'm not sure what to write next to create the axis vector. I think it would be computationally easier to calculate the axis vector directly and then apply it to the list of coordinates, than it would be to do 3 separate rotations for each point

1

There are 1 answers

0
Nikola Dimitroff On

By multiplying quaternions you can combine the rotations of several quaternions. Assuming you've overriden the * operator to allow for quaternion multiplication and that your quaternions can be constructed from an angle and axis, here's the how to implement the nested loops:

 for x in range (0, 360, 10):
     rotation_x = Quaternion(Vector3(1, 0, 0), x)
     for y in range (0, 360, 10):
         rotation_y = Quaternion(Vector3(0, 1, 0), y)
         for z in range (0, 360, 10):
             rotation_z = Quaternion(Vector3(0, 0, 1), z)
             combined_rotation = rotation_x * rotation_y * rotation_z
             # do whatever you need with the rotation