Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by artie · Dec 02, 2013 at 10:32 PM · camerafovdiagonal

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image artie · Dec 02, 2013 at 11:56 PM 0
Share

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 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Scribe · Dec 03, 2013 at 12:30 AM

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image artie · Dec 03, 2013 at 04:17 AM 0
Share

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

avatar image artie · Dec 03, 2013 at 05:32 AM 0
Share

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.

avatar image Scribe · Dec 03, 2013 at 02:40 PM 0
Share

I'm not sure where the differences in values is co$$anonymous$$g from, I've made a picture to try to demonstrate my thought process and so others might be able to point out any errors, personally I can't see anything wrong with my calculations on a second look!

http://i1.$$anonymous$$us.com/igbWuV$$anonymous$$vDqEXb.png

from this I deduced that my code could be rewritten as

 var diagonalFOV : float = 73;
 private var camAspect : float;
 
 function Start () {
     camAspect = camera.aspect;
     
     camera.fieldOfView = 2.0*$$anonymous$$athf.Atan($$anonymous$$athf.Tan(diagonalFOV*$$anonymous$$athf.Deg2Rad/2.0)/$$anonymous$$athf.Sqrt(1 + $$anonymous$$athf.Pow(camAspect, 2)))*$$anonymous$$athf.Rad2Deg;
 }

though this gives the same answer my old code did

$$anonymous$$aybe you can find where I've gone wrong, or possibly the site you linked to is incorrect though thats probably less likely

Scribe

avatar image Roland1234 · Dec 03, 2013 at 05:15 PM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

crop or offset the camera display? 0 Answers

Camera movement in a 2D? (like angry birds) 1 Answer

Minimap camera display size. 1 Answer

How to accurately zoom (not dolly) and pan Camera to mouse click position 1 Answer

Is it possible to show only a part of what camera sees 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges