Search code examples
android-cameraquaternionsarcoreplane

How to get the screen as a mathematical plane from camera position and pose in AndroidStudio with Google ARCore?


For my project it would be very useful to have the current screen position and rotation as a mathematical plane or some sort of plane because my models need to be oriented perpendicular towards this plane and not the camera itsef.

I have the current CameraWorldPosition as Vector3 and CameraWorldRotation as a quaternion. Since I do not have much expierience with quaternios I have following questions:

  1. Do the x,y and z of the quaternion define a vector? Does w define the rotation of the 3d-model around this vector?
  2. Is the vector mentioned in 1. perpendicular to my phones screen? That would make finding a mathematical plane very easy.
  3. If 2 is not correct what is the best way to calculate my screens-plane with given things? I thought about using my CameraWorldPosition as the support vector. Then I would need to calculate the span-vectors still.

If you have any ideas or something that could help me please tell me.

Thanks in advance.


Solution

    1. The x, y and z components of a quaternion do define a vector. That vector is the axis of rotation. However it is not a unit vector in general. Its lenght is equal to sin(theta/2) where theta is the angle of rotation. So w is not the angle of rotation, it is cos(theta/2).

    2. It is not, since the camera can rotate around any axis.

    3. For defining the plane it is enough to have two things: the normal vector and a point in the plane. The point in plane is the easiest one, you already have it. It is CameraWorldPosition. For the normal vector of the plane you need to know the normal vector of the camera in the absense of rotation i.e. when the rotation is the identity quaternion. Lets say for example that the camera always has initially a normal vector coincident with the Z vector. Then the normal of the plane is just the Z vector rotated by the quaternion CameraWorldRotation. So if you can know the initial conditions of the camera (i.e., the initial normal vector), then you can define the plane at any moment having the camera position and camera rotation.