/// <summary> /// Returns circles that are tangent to another circle and line. /// </summary> /// <param name="circle">Circle that returned circles should be tangent to.</param> /// <param name="line">Line that returned circles should be tangent to.</param> /// <param name="radius">Radius of new circles.</param> /// <returns>External tangent circles are listed first.</returns> public static Circle2D[] FromTangentTangentRadius(Circle2D circle, LineSeg2D line, decimal radius) { List <Circle2D> orbits = new List <Circle2D>(); LineSeg2D[] parallels = new LineSeg2D[2]; List <Point2D> centerPoints = new List <Point2D>(); List <Circle2D> tangentCircles = new List <Circle2D>(); orbits.Add(new Circle2D(circle.X, circle.Y, circle.Radius + radius)); if (radius < circle.Radius) { orbits.Add(new Circle2D(circle.X, circle.Y, circle.Radius - radius)); } parallels = line.GetParallels(radius); foreach (Circle2D orbit in orbits) { for (int i = 0; i <= 1; i++) { centerPoints.AddRange(orbit.GetIntersect(parallels[i])); } } for (int i = 0; i <= centerPoints.Count - 1; i++) { tangentCircles.Add(new Circle2D(centerPoints[i].X, centerPoints[i].Y, radius)); } return(tangentCircles.ToArray()); }
/// <summary> /// Returns circles that are tangent to two lines. /// </summary> /// <param name="lineA">First line.</param> /// <param name="lineB">Second line.</param> /// <param name="radius">Radius of the tangent circles.</param> /// <returns>Will return no circles if the two lines are parallel or the same line.</returns> public static Circle2D[] FromTangentTangentRadius(LineSeg2D lineA, LineSeg2D lineB, decimal radius) { List <LineSeg2D> parallels = new List <LineSeg2D>(); Nullable <Point2D> centerPoint = default(Nullable <Point2D>); List <Point2D> centerPoints = new List <Point2D>(); List <Circle2D> tangentCircles = new List <Circle2D>(); parallels.AddRange(lineA.GetParallels(radius)); parallels.AddRange(lineB.GetParallels(radius)); for (int i = 0; i <= parallels.Count - 2; i++) { for (int j = i + 1; j <= parallels.Count - 1; j++) { centerPoint = parallels[i].GetIntersect(parallels[j], true); if (centerPoint.HasValue) { centerPoints.Add(centerPoint.Value); } } } for (int i = 0; i <= centerPoints.Count - 1; i++) { tangentCircles.Add(new Circle2D(centerPoints[i].X, centerPoints[i].Y, radius)); } return(tangentCircles.ToArray()); }