This site uses strictly necessary cookies. More Information

X# 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

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

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

How to make pie menu options interact to OnMouseDown? 0 Answers

Mathf.NegativeInfinity unexpectly converts to PositiveInfinity 2 Answers

Mathf.Min, get which object is the minimum? 1 Answer

how to restart mecanim state animation or play it from random position [SOLVED] 0 Answers