Lucy Loo - 1 year ago 121

C++ Question

I'm building a small Physics engine and I'm having trouble converting my Radian value to Degrees using

`atan`

Firstly, I have an

`x`

`y`

`atan`

`angleDivide = yN / xN;`

Then, before putting this value into

`tan`

`angleToDegrees = angleDivide * (3.14 / 180);`

Then I place angleToDegrees into

`atan`

`angle = atan(angleToDegrees);`

But when I'm displaying

`angle`

Please could you tell me what is wrong with my code and how to fix this?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You want to calculate `radians=tan(y/x)`

first.

Then you can convert it to degrees:

```
radians = atan(y/x)
degrees = radians * (180.0/3.14)
```

See the reference here for atan:

On a side note, you also have to take into account what quadrant you are in to get the correct answer (since `-y/x`

is the same number as `y/-x`

)

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**