So, i have an array of data thats in [X,Y] and i need to be able to rotate all of the points around another [x,y] point.

So, if i had a square: [0,0] , [0,10] , [10,10] , [10,0] and wanted to rotate it 45deg around [5,5] , whats the best approach for doing so?

Only thing i can think of is to enumerate trough each node, calculate the distance between them, then sin() or cos() or whichever one it is to get the angle, then add 0,90,180,270 deg based upon the quadrant it is around the central point with a condition to check [+/-x , =/-y]. With that, i can then add 45deg to that angle with the given distance it needs to be, and once again with the simple sin\cos\tan get the new X,Y coordinates.

I'm doing this in javascript and I have some code I wrote from before to give me the new location once i figure out the angle and distance to that point.

Does anyone have some code or logic that's better?

So, if i had a square: [0,0] , [0,10] , [10,10] , [10,0] and wanted to rotate it 45deg around [5,5] , whats the best approach for doing so?

Only thing i can think of is to enumerate trough each node, calculate the distance between them, then sin() or cos() or whichever one it is to get the angle, then add 0,90,180,270 deg based upon the quadrant it is around the central point with a condition to check [+/-x , =/-y]. With that, i can then add 45deg to that angle with the given distance it needs to be, and once again with the simple sin\cos\tan get the new X,Y coordinates.

I'm doing this in javascript and I have some code I wrote from before to give me the new location once i figure out the angle and distance to that point.

Code:

```
function calcXY(xIn, yIn, angle, distance)
{
var b = angle / RADIAN;
var xOut= (Math.sin(b) * distance) + xIn;
var yOut = (Math.cos(b) * distance) + yIn;
var out = [];
out[0] = xOut;
out[1] = yOut;
return out;
}
```

Does anyone have some code or logic that's better?