Search code examples
pythonnumpyquaternions

quaternion creation by spherical coords in numpy


While trying to understand the usage the quaternion extension of numpy, I saw that

import numpy as np
import quaternion as q

theta = np.pi * 1.0 / 3.0
phi = 0.0

print(q.from_spherical_coords(theta,phi))

prints out

(quaternion(0.866025403784439, -0, 0.5, 0))

This quaternion is a 60 degrees rotation around Y axis, but I expected a 60 degrees rotation around Z axis only, since phi is 0.0. Have theta and phi changed with respect to source files or am I missing something?

Thanks for any help.


Solution

  • Your understanding to quaternion is totally correct. But I think maybe you are confused by how theta and phi are used in spherical coordinate system.

    See the picture here, this convention is well-known. For theta = 60, phi = 0, the point is located in zx-plane with a 60 degree angle to z-axis. Thus you do need a rotation around y-axis by 60 degree to transport the north-pole to this point.