When working with openGL perspectives I am not quite sure how to compute the fovx from the fovy. I read different things in different places and in I don't get the right behavior by using either method that I found. So can someone please tell me, given the fovy of the camera and the aspect ratio, how to I calculate the fovx of the camera? If any other data is needed that is fine just let me know what I need. Thank you so much in advance!
Asked
Active
Viewed 8,294 times
4 Answers
12
Correct:
fieldOfViewX = 2 * atan(tan(fieldOfViewY * 0.5) * aspect)
Wrong, especially for large aspects, see @gman's comments below:
Aspect ratio === width/height
fovy ~= "height"
==> fovx = fovy * aspect
Test:
Fovy = 60 degs
Aspect = 4:3 ~= 1.33
Fovx = 60*1.33 = 80
80/60 = 4:3 (fovs match, yay)
For "reasonable" fovs/aspects, simple method is "reasonably" near the truth, but if you have extreme aspects you will get fovx > 180 degrees, which you don't want.

Macke
- 24,812
- 7
- 82
- 118
-
1This answer is completely wrong. Simple example. Make the width 10 and the height 1. The aspect will be 10. Now make the fovy = 60, the fovx will now be 600, an impossible field of view. – gman Apr 06 '15 at 16:48
-
@gman: Please, don't use bad numbers and blame the math on the result. A very wide aspect (10:1 !!!) and some reasonable fovy (60 degree fovy) WILL result in 600 fovx (repeat view almost twice), if you want square pixels. Then, you need to split your rendering to avoid perspective distorsion for wide aspects. For 10:1, you pobably want to define fovx first, to say 120 and derive FovY from it instead. (12 degrees). – Macke Apr 09 '15 at 06:30
-
1You can never have a field of view larger than 360 degrees as that's all possible degrees there are. You're using the **wrong** math. Fix your answer. The correct answer is `fieldOfViewX = 2 * atan(tan(fieldOfViewY * 0.5) * aspect)`. I was hoping not to have to write a demo to prove because it's obvious you'll get nonsense answers from your math. By your logic if I have window in the real world that's 10 feet by 1 foot I'll suddenly be able to see behind me. Think about it. – gman Apr 09 '15 at 08:26
-
3[Here's a sample to show the issue](http://twgljs.org/examples/fov-checker.html). `fovx` is computed by `fieldOfViewX = 2 * atan(tan(fieldOfViewY * 0.5) * aspect)` where `aspect = width/ height`. Notice how it match the display. `bad fovx` is computed using your method. Make the window short and wide and notice how your answer is wrong. – gman Apr 09 '15 at 10:02
-
@gman: Ah. I see the your point. Great demo btw, Could you write a new anser explaining your math (i.e. atan/atan) and I'll happily upvote it. I guess I'm used to fov/aspects around 60-90 and 2:1-1:2, where the difference is < 10%-ish and not noticable. – Macke Apr 09 '15 at 12:47
-
@gman: I failed to see the case where you were standing with your nose at the 1:10 window, thus getting a fovy of 60 deg but still fovx < 180. I assumed you'd be a bit further away from it, fovy will be much smaller and thus my formula would give something "close enough", hence my mistake. Thanks for pointing it out. – Macke Apr 09 '15 at 12:52
-
Heh. I've used that calculation for 20 years and nobody noticed. :) – Macke Apr 09 '15 at 12:55
-
No problem. I found some code recently I'd been using for 8 years that seemed to work but was actually just *close enough* ... until it wasn't :P – gman Apr 09 '15 at 17:08
4
Here is a good link:
http://wiki.panotools.org/Field_of_View
Note that the aspect ratio is not the same thing as the field of view ratio, and the proper relationship given on this page should be used for relating field of view angles.

EdgarSandyShoes
- 41
- 1
1
Java:
double d = (viewportHeight * 0.5) / Math.tan(Math.toRadians(fovY * 0.5));
fovX = (float) (2 * Math.toDegrees(Math.atan((viewportWidth * 0.5) / d)));

Peter O.
- 32,158
- 14
- 82
- 96

user718478
- 11
- 1
-
2It would be great if you add some commentary as well along with your answer. – Amar Nov 07 '12 at 19:11
-1
Have you looked at the formulas here?:

Justin Pearce
- 4,994
- 2
- 24
- 37
-
(-1) The link posted relates stuff that relate to photography cameras. Not open GL stuff. – Vaillancourt Jul 25 '14 at 03:02