CNC-Cog
view release on metacpan or search on metacpan
my $k = abs($r) * sqrt( (($x2-$x1)**2+($y2-$y1)**2)/($x2-$x1)**2);
my $j=$c+$k*$ks; # ks is the sign of k from above.
# we need to solve this with the circle x^2+y^2=(b+r)^2
# substituting for y in here gives
#
# x^2+y^2=(b+r)^2
# y=mx+j
# x^2+m^2x^2+2mxj+j^2=(b+r)^2
# (1+m^2) x^2 + 2mj x +j^2-(b+r)^2=0
# use quadratic equation formula to find x:
# x=(-b+- sqrt(b^2-4ac)/2a
#
# x=(-2mj +- sqrt(4m^2j^2-4(1+m^2)(j^2-(b+r)^2)))/2(1+m^2)
# This is the center point of the arc.
# s is the distance between c and l2, we now have x and y coords for both c and l2.
# u^2=s^2-r^2 and is distance from l2 in direction of l1 for the new l2 point at start of smoothing arc.
# The end of the arc is oc scaled such that distance is b, the radius of the circle.
$r=-$r if (dist(0,0,$x1,$y1)<$b);
( run in 0.288 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )