Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Reconnoiter · Nov 11, 2016 at 01:41 PM · animatormathfdegreessinradial

degrees to radians formula question

Howdy,

I want to convert this asinv( sinv( 23.45 ) ) (in degrees, CW I think) to Unity c# code, but the Math/Mathf functions seem to use radians so I need to convert them. But I can't seem to get it right.

I thought it would be something like this (for a float): Mathf.Asin ( Mathf.Sin( Mathf.Deg2Rad * 23.45f ) )

Maybe I am missing some conversion?

Tnx for taking the time.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by tanoshimi · Nov 11, 2016 at 01:51 PM

You don't say what your source language is, but on the assumption that asinv expects an input between -1 and 1, and returns an angle between 0-360, whereas sin expects an input between 0-360 and returns a value between -1 and 1, then you need to convert the result of Unity's methods back to degrees:

 Mathf.Rad2Deg * Mathf.Asin ( Mathf.Sin( Mathf.Deg2Rad * 23.45f ) ) 
Comment
Add comment · Show 3 · 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 Bunny83 · Nov 11, 2016 at 02:05 PM 0
Share

Right, but there's no real point in doing that ^^ this line of code would simply evaluate to about 23.45f.

Also note that Sin actually expects values in the range of -PI/2 to +PI/2 or -90 to 90 and returns a value between -1 and 1. Greater or smaller numbers just wraparound. So $$anonymous$$athf.Sin(180f * $$anonymous$$athf.Deg2Rad) returns "0" just like an angle of "0f".

Of course Asin does the reverse. So it expects a value in the range of -1 to 1 and returns an angle in the range of -PI/2 to PI/2 (or -90 to 90)

Also note that all trigonometry methods are mathematically defined as counter clockwise, not clockwise. Also in the 2d context 0 degree is "right" since the x value is the cosine and the y value the sine. Given that 0/0 is at the bottom left corner.

avatar image tanoshimi Bunny83 · Nov 11, 2016 at 02:07 PM 0
Share

Agreed - I didn't attempt to interpret the meaning of the code - I merely translated the syntax!

avatar image Reconnoiter · Nov 11, 2016 at 02:05 PM 0
Share

Tnx, the $$anonymous$$athf.Rad2Deg * did the trick.

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

61 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

How To Move My Player With Sin And Cos Functions 1 Answer

mathf.round problem 2 Answers

Can anyone help me smooth the lean of my character using mathf.smoothdamp or vector3.smoothdamp or any other method? 0 Answers

Smooth speed increase while sprinting 0 Answers

Issues w/ 2D shmup ship "lean" animations on diagonals 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