3
votes

I'm working in PHP with some filled arcs and I'm having trouble finding a way of calculating the coordinates for the end point of an arc. I know the centre point coordinates, the radius (the width and height are the same), the start angle, and the end angle (as is required by the php imagefileldarc() function). From this, how can I calculate the end point coordinates for the arc?

I've tried the following formula to no avail:

$end['x'] = cos($Angle) * $Radius + $CenterX; 
$end['y'] = sin($Angle) * $Radius + $CenterY;

Many thanks

1
You are using radians for $Angle, aren't you?Mark Baker
I'm using degrees for the angle.Dan Murfitt
I've just converted the degrees to radians using PHP's deg2rad() and it seems to be working now. Many thanks.Dan Murfitt

1 Answers

3
votes

The fact that you are drawing an arc does not really matter. Your calculation will always be:

x=cos(angle)*ratio+centerx
y=sin(angle)*ratio+centery