Thanks for the code. The chord length and radius are calculated in a similar way. But I'm unable to figure out how to calculate the start and end angles... at least, I did some calculations that turned out to be working. But in this specific drawing it doesn't. That sounds to me like there is a certain condition at which the code goes wrong.
Here is my code:
Code:
function LWBulgeCalc($xs, $xe, $ys, $ye, $bulge)
{
$result = array();
$dx = $xe - $xs;
$dy = $ye - $ys;
$xmid = $dx/2 + $xs;
$ymid = $dy/2 + $ys;
$l = sqrt(pow($dx,2) + pow($dy,2)); //linelength from point 1 to point 2
$r = abs($l*(($bulge*$bulge)+1)/$bulge/4); //Radius circle
// $r = abs($l/(2* sin((4*atan($bulge))/2))); //another way of calculating the radius.
$a = abs($bulge*$l/2);
$sb = $bulge/abs($bulge);
$theta_p = 4*atan($bulge);
if($dx != 0) $theta_c = atan($dy/$dx);
else $theta_c = pi()/2;
if ($dx > 0) $sb *= -1;
$cx = $xmid + $sb*($r-$a)*sin($theta_c); //centerpoint X
$cy = $ymid - $sb*($r-$a)*cos($theta_c); //centerpoint Y
$angle1 = asin(($ye-$cy)/$r); //angle 1
$angle2 = asin(($cy-$ys)/$r); //angle 2
if($cx > $xe) $angle1 = pi() - $angle1;
else $angle1 = 2*pi() + $angle1;
if($bulge < 0) //CW
{
$arcst = $angle1;
$arcend = pi() + $angle2;
}
else //CCW
{
$arcend = $angle1;
$arcst = pi() + $angle2;
}
$arcst = rad2deg($arcst);
$arcend = rad2deg($arcend);
$result[0] = $cx;
$result[1] = $cy;
$result[2] = $r;
$result[3] = $arcst;
$result[4] = $arcend;
return $result;
}