Tangential Circle through Point

Circle passing through a point and tangential to two curves

//Increase num for higher precision
//Will fail if too low and take too long if too high
num = 15;

//Centers of circles that are tangential and equidistant to the input Curves
pt1 = c1.PointAtParameter(0..1..#num);
pt2 = c2.PointAtParameter(0..1..#num);
pl1 = Plane.ByThreePoints(c1.CenterPoint,c1.CenterPoint.Translate(0,0,1),pt1);
vc1 = Vector.ByTwoPoints(c2.CenterPoint,pt2);
pt3 = Point.PruneDuplicates(List.Flatten(pt2.Project(pl1<1>,vc1<2>),-1),0.01);
ds1 = Math.Round(pt3<1>.DistanceTo(pt1<2>),1);
ds2 = Math.Round(pt3<1>.DistanceTo(pt2<2>),1);
pt4 = List.FilterByBoolMask(pt3,List.AllFalse((ds1==ds2)<1>))["out"];

//Centers that are equidistant to the input Curves and Point
ds3 = Math.Round(pt4<1>.DistanceTo(c1<2>),1);
ds4 = Math.Round(pt4<1>.DistanceTo(c2<2>),1);
ds5 = Math.Round(pt4<1>.DistanceTo(p1<2>),1);
pt5 = List.FilterByBoolMask(pt4,ds3==ds5 && ds4==ds5)["in"];
ds6 = pt5.DistanceTo(p1);
cr1 = Circle.ByCenterPointRadius(pt5,ds6);

//Geometry Color
[GeometryColor.ByGeometryColor(p1,Color.ByARGB(255,255,0,0)),
GeometryColor.ByGeometryColor(c1,Color.ByARGB(255,0,255,0)),
GeometryColor.ByGeometryColor(c2,Color.ByARGB(255,0,0,255)),
GeometryColor.ByGeometryColor(cr1[0],Color.ByARGB(255,255,0,255))];
//Curve 1
c1 = Arc.ByThreePoints(Point.ByCoordinates(-3,2),
Point.ByCoordinates(2,1),Point.ByCoordinates(5,3));

// Curve 2
c2 = Arc.ByThreePoints(Point.ByCoordinates(-6,2),
Point.ByCoordinates(-4,1),Point.ByCoordinates(0,3));

//Point
p1 = Point.ByCoordinates(-2,1);

//Limit length of arcs as much as possible
//Will fail if no circle passes through the point
//Multiple circles that satisfy the condition possible

Last updated