Jump to content
  • Advertisement
Sign in to follow this  
thallish

perspective math, calculating horisontal FoV from vertical

This topic is 4579 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After some searches I think I get the calculations from vertical to horizontal field of view, i just have one question here goes:
width = 2 * tan(hFoV/2)
height = 2 * tan(vFoV/2)
and from what I can guess:
2 * tan(hFoV/2)/width = 2 * tan(vFoV/2)/height
Now is this jump possible because of the fact that both the width and the height have the same size in the view window? I can not see any other reason due to the fact that with and height could have different sizes, but maybe I am just misunderstanding it. The rest of the calculations is easy and understandable. Regards [Edited by - thallish on January 4, 2007 5:51:47 PM]

Share this post


Link to post
Share on other sites
Advertisement
You've just rewritten the eqns:

width = 2 * tan(hFoV/2)

->

2 * tan(hFoV/2) / width = 1



I don't really understand your question, what are you confused by/trying to do?

Share this post


Link to post
Share on other sites
ahh yeah.. ok I see how it is possible now, as the both equals 1 after rewriting them. doh!! Guess I was tired at that point[smile]

I was trying to understand why I got from the two equations to the one, and I was right, but for the wrong reasons. Thanks for letting me see the light.

Regards

Share this post


Link to post
Share on other sites
I'm glad :) Fov V/H & w/h also relate to the aspect ratio of the viewport, it's actually fairly tricky to get the math exactly right (Jim Blinns 'A Trip Down The Graphics Pipeline' has a very good explanation of the differences and mappings between clip, viewport and screen spaces - I'm sure there are others out there). For widescreen support it is important to get these things right so you don't wind up with warped images.

Share this post


Link to post
Share on other sites
i'm also interested in the answer.
So what's the formula for the horizontal fov with given vertical fov and aspect ratio?

regards,
m4gnus

Share this post


Link to post
Share on other sites
Quote:
Original post by m4gnus
So what's the formula for the horizontal fov with given vertical fov and aspect ratio?
This pair of functions converts back and forth between horizontal and vertical fields of view (it'll be easier to just paste the functions than to write out the formulas :):
/** Convert horizontal field of view to vertical field of view. */
template < typename T >
T xfov_to_yfov(T xfov, T aspect) {
return T(2.0 * std::atan(std::tan(xfov * T(.5)) / double(aspect)));
}

/** Convert vertical field of view to horizontal field of view. */
template < typename T >
T yfov_to_xfov(T yfov, T aspect) {
return T(2.0 * std::atan(std::tan(yfov * T(.5)) * double(aspect)));
}

Share this post


Link to post
Share on other sites
Considering that the distance to the near plane (the adjacent side to the FOV angle) stays the same, but the other side (the opposite side from the FOV angle) changes by a ratio of width/height, the tangents must also vary by that same ratio (since tan = opposite/adjacent, and opposite changes)

Therefore, you end up with:
horizontalFov = atan( tan(verticalFov) * width/height )
verticalFov = atan( tan(horizontalFov) * height/width )
Though, for most screen aspect ratios, simply using
horizontalFov = verticalFov * width/height
verticalFov = horizontalFov * height/width
is a really close approximation.

Share this post


Link to post
Share on other sites
ok so the formulas are:
horizontalFov = atan( tan(verticalFov) * aspectratio )
verticalFov = atan( tan(horizontalFov) / aspectratio )
thanks that was what i needed.

regards,
m4gnus


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!