How convert to camera FOV from diagonal FOV?

Hey all. I need to set the camera’s FOV to a certain value, but that value is given to me as the ‘diagonal FOV’. And Unity’s cameras FOV is ‘vertical FOV’. So I need to do this conversion. I realize it means using the aspect ratio, right? or somehow getting the view frustum?
Does anyone know the formula for this?

Yes, why is there something else I should be using? Camera.fieldOfView is vertical FOV. I need to convert a diagonal FOV (like, say 73 degrees) into what ever number that is in the vertical so I can set it, thus producing a 73 degree diagonal FOV on that camera.

1 Answer

1

I believe this should work, its just some trigonometry:

var diagonalFOV : float = 100;
private var camAspect : float;
private var diagonalRatio : float;
private var verticalFOV : float;

function Start () {
	camAspect = camera.aspect;
	diagonalRatio = Mathf.Sqrt(1 + Mathf.Pow(camAspect, 2));
	verticalFOV = (Mathf.Atan(Mathf.Tan(diagonalFOV*(Mathf.Deg2Rad/2.0))/diagonalRatio))*Mathf.Rad2Deg*2;
	
	camera.fieldOfView = verticalFOV;
}

I have tested this so it doesn’t give errors though I’m unable to test if it is the correct output angle, so hopefully my maths is correct!

Scribe

Thanks! I'll check it against this thing I found: http://vrguy.blogspot.com/2013/04/converting-diagonal-field-of-view-and.html

Hmm. The numbers are sorta close but not matching for my 73 degree example and 4:3 ratio it should be closer to 43 degrees I think but this code gives me 47 degrees.

I worked it out and also came up with similar results. I believe the linked site is actually incorrect - he's taking the Pythagorean theorem and arbitrarily applying it to angles, which is a very naughty thing for him to do. It'll give approximations at certain ranges, but will start to differ significantly with higher values. Doing some quick debugs in Unity I see that with a V FOV of 42 and an aspect ratio of 4:3 the diagonal FOV should be 65.22, not 70 like the site claims. For a diagonal at 73 degrees and aspect ratio of 4:3, the V FOV should be 47.88021.