0

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

enter image description here

EDIT : after using eol formula...

Debug

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

Mardi
  • 13
  • 2

1 Answers1

-1

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;
eol
  • 23,236
  • 5
  • 46
  • 64
  • I use your formula but there very small miss in calculation. i know it will ignore in render but you know why? – Mardi Jul 03 '16 at 09:45
  • @Mardi This might be due to rounding errors. See http://stackoverflow.com/questions/1661273/floating-point-arithmetic-not-producing-exact-results – eol Jul 03 '16 at 10:31