Mardi - 1 year ago 126

Java Question

I have one coordinate and want to get a new coordinate after rotation like image below. Can anyone give me a simple formula ?

EDIT : after using eol formula...

there's a very small miss "6.1232338E-15".

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

Answer Source

Just use a rotation matrix (taken from https://en.wikipedia.org/wiki/Rotation_matrix):

```
float newX = x*Math.cos(angleRad) - y*Math.sin(angleRad);
float newY = x*Math.sin(angleRad) - y*Math.cos(angleRad);
```

One thing to mention is that you need to make sure that the angle is in radians, so you may need to perform this conversion:

```
float angleRad = angle*Math.PI/180;
```

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