I am trying to make a function to rotate a point around another point. My maths are very rusty but i did some research and i just dont understand why my function is not working.
public void rotatePoint(int pX,int pY,int angle) {
int newX = 0, newY = 0;
int centerX = 400, centerY = 300;
angle *= Math.PI / 180; // convert angle from deg to rad
double rotatedX = Math.cos(angle)*(pX-centerX)-Math.sin(angle)*(pY-centerY) + centerX;
double rotatedY = Math.sin(angle) * (pX-centerX) + Math.cos(angle) * (pY-centerY) + centerY;
newX = (int)Math.round(rotatedX);
newY = (int)Math.round(rotatedY);
}
On the image i just provide my original point is in grey. After a rotation of 90 or 180deg i would expect the point to arrive where the green ones are. They arrive where the red points are.