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.
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 ) )
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.
Agreed - I didn't attempt to interpret the meaning of the code - I merely translated the syntax!
Your answer
Follow this Question
Related Questions
How To Move My Player With Sin And Cos Functions 1 Answer
mathf.round problem 2 Answers
Smooth speed increase while sprinting 0 Answers
Issues w/ 2D shmup ship "lean" animations on diagonals 1 Answer