in a current assignment we need to create a method, to rotate a given point, around a center point given, in the angle given, in CLOCK WISED offset. after searching through posts here, i thought i figured it out, but according to my teacher, something is wrong with this and i can't figure it out.
i was hoping maybe someone could help out pointing what the problem is.
this is my method
/**
* rotate this Point around a given enter point, with the given angle, in clock wised offset.
* @param center - the center Point for rotation
* @param angle - the size angle in degrees - to be rotate clock wised
*/
public void rotate(Point center, double angle){
// convert the angle to radiant (to use with Math class methods). The negative sign is because, in trigonometry, default rotation is COUNTER-clock wised.
double rad_angle = -Math.toRadians(angle);
// in order to rotate properly, we need to know the difference between the coordinates, to get a base for the rotation.
double diff_x = this.x - center.X();
double diff_y = this.y - center.Y();
// calculate the rotation difference
this.x = diff_x * Math.cos(rad_angle) - diff_y* Math.sin(rad_angle);
this.y = diff_x * Math.sin(rad_angle) + diff_y * Math.cos(rad_angle);
// translate the differences back to this point
this.x = this.x + center.X();
this.y = this.y + center.Y();
return;
}//rotate
thanks in advance.