Using quaternion to get polar rotational components

59 Views Asked by At

I have tried multiple times to understand quaternions and have failed miserably. I know how to use it to extract unit vectors for cartesian operations, but not how to use it directly for these types of things or even if it can be used directly for what I need.

I have a quaternion representing a cameras orientation. I have a ray originating from the position of the camera that exists anywhere in the viewing frustrum along it's forward vector. I want the $\theta$ and the $\rho$ angles where $\theta$ is the rotation about the up vector and the $\rho$ is the rotation about the right vector using the space described by the quaternion that would move the forward vector to be equal to the direction of the ray.

Can someone show me how I should have derived this? I know based on the wiki page for spherical coordinate systems how to get polar coordinates from cartesian coordinates, but not how I would do this from the space described by the camera quaternion.

1

There are 1 best solutions below

0
On

If you know how to get the angles you want when the camera is not rotated, then use the orientation quaternion to find the rotation matrix R and transform all vectors into the camerate coordinate system.

Given quaternion q, do the following

  1. R = rot(q)
  2. local_raydir = transpose(R) * raydir
  3. cameradir = (0,0,1)

the local camera forward direction might be different, according to the convention you are using.

To find the 3×3 rotation matrix R from the quaternion q use the formula from this post:

fig1