# Get the up vector of the camera in ARKit

I'm trying to get the four vectors that make up the boundaries of the frustum in ARKit, and the solution I came up with is as follows:

• Find the field of view angles of the camera
• Then find the direction and up vectors of the camera
• Using these information, find the four vectors using cross products and rotations

This may be a sloppy way of doing it, however it is the best one I got so far.

I am able to get the FOV angles and the direction vector from the ARCamera.intrinsics and ARCamera.transform properties. However, I don't know how to get the up vector of the camera at this point.

Below is the piece of code I use to find the FOV angles and the direction vector:

func session(_ session: ARSession, didUpdate frame: ARFrame) {
if xFovDegrees == nil || yFovDegrees == nil {
let imageResolution = frame.camera.imageResolution
let intrinsics = frame.camera.intrinsics
xFovDegrees = 2 * atan(Float(imageResolution.width) / (2 * intrinsics[0,0])) * 180 / Float.pi
yFovDegrees = 2 * atan(Float(imageResolution.height) / (2 * intrinsics[1,1])) * 180 / Float.pi
}

let cameraTransform = SCNMatrix4(frame.camera.transform)
let cameraDirection = SCNVector3(-1 * cameraTransform.m31,
-1 * cameraTransform.m32,
-1 * cameraTransform.m33)
}


I am also open to suggestions for ways to find the the four vectors I'm trying to get.

In a 4x4 transformation matrix, all directions are contained:

• First row of matrix contains the x-axis.

• Second row of the matrix contains the y-axis.

• Third row of the matrix contains the z-axis.

• Fourth row of the matrix contains the position/translation.

Looking at your code, -z is the direction the camera looks at. Most likely, the y-axis in that transformation is the vector that you are looking for.

SCNVector3( cameraTransform.m21, cameraTransform.m22, cameraTransform.m23 );