Floating point calculations, especially those with trigonometric functions, are always error prone due to the limited resolution of floating point variables. You could increase the accuracy of the calculations when you multiply the difference of coordinates by a trigonometric function instead of multiplying the coordinates and subtracting the results. You can try this code (assuming the angle is in radians and math.pas is used):
var dx,dy,ca,sa:Extended; rotp:Tpoint; begin SinCos(angle, sa, ca); dx := point.x - CenterPoint.X; dy := point.y - CenterPoint.Y; result.X := CenterPoint.X + round(dx*ca - dy*sa); result.Y := CenterPoint.Y + round(dx*sa + dy*ca); end;
Update: And, according to the edited David, you should not use incremental rotations, as this will increase the rounding error.
Uwe raabe
source share