Click or drag to resize
IntersectionLineCircle Method
Intersects a line with a circle using exact calculations.

Namespace: Rhino.Geometry.Intersect
Assembly: RhinoCommon (in RhinoCommon.dll) Version: 5.1.50000.0 (5.0.20693.0)
Syntax
public static LineCircleIntersection LineCircle(
	Line line,
	Circle circle,
	out double t1,
	out Point3d point1,
	out double t2,
	out Point3d point2
)

Parameters

line
Type: Rhino.GeometryLine
Line for intersection.
circle
Type: Rhino.GeometryCircle
Circle for intersection.
t1
Type: SystemDouble
Parameter on line for first intersection.
point1
Type: Rhino.GeometryPoint3d
Point on circle closest to first intersection.
t2
Type: SystemDouble
Parameter on line for second intersection.
point2
Type: Rhino.GeometryPoint3d
Point on circle closest to second intersection.

Return Value

Type: LineCircleIntersection
If Single is returned, only t1 and point1 will have valid values. If Multiple is returned, t2 and point2 will also be filled out.
Examples
using Rhino;
using Rhino.Commands;
using Rhino.Input;
using Rhino.Geometry;
using Rhino.Geometry.Intersect;

namespace examples_cs
{
  public class IntersectLineCircleCommand : Command
  {
    public override string EnglishName { get { return "csIntersectLineCircle"; } }

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      Circle circle;
      var rc = RhinoGet.GetCircle(out circle);
      if (rc != Result.Success)
        return rc;
      doc.Objects.AddCircle(circle);
      doc.Views.Redraw();

      Line line;
      rc = RhinoGet.GetLine(out line);
      if (rc != Result.Success)
        return rc;
      doc.Objects.AddLine(line);
      doc.Views.Redraw();

      double t1, t2;
      Point3d point1, point2;
      var line_circle_intersect = Intersection.LineCircle(line, circle, out t1, out point1, out t2, out point2);
      string msg = "";
      switch (line_circle_intersect) {
        case LineCircleIntersection.None:
          msg = "line does not intersect circle";
          break;
        case LineCircleIntersection.Single:
          msg = string.Format("line intersects circle at point ({0})", point1);
          doc.Objects.AddPoint(point1);
          break;
        case LineCircleIntersection.Multiple:
          msg = string.Format("line intersects circle at points ({0}) and ({1})",
            point1, point2);
          doc.Objects.AddPoint(point1);
          doc.Objects.AddPoint(point2);
          break;
      }
      RhinoApp.WriteLine(msg);
      doc.Views.Redraw();
      return Result.Success;
    }
  }
}
import rhinoscriptsyntax as rs
from scriptcontext import doc
import Rhino
from Rhino.Geometry.Intersect import Intersection, LineCircleIntersection

def RunCommand():
  rc, circle = Rhino.Input.RhinoGet.GetCircle()
  if rc != Rhino.Commands.Result.Success:
    return rc
  doc.Objects.AddCircle(circle)
  doc.Views.Redraw()

  rc, line = Rhino.Input.RhinoGet.GetLine()
  if rc != Rhino.Commands.Result.Success:
    return rc
  doc.Objects.AddLine(line)
  doc.Views.Redraw()

  lineCircleIntersect, t1, point1, t2, point2 = Intersection.LineCircle(line, circle)
  message = ""
  if lineCircleIntersect == LineCircleIntersection.None:
    message = "line does not intersect circle"
  elif lineCircleIntersect == LineCircleIntersection.Single:
    message = "line intersects circle at point ({0},{1},{2})".format(point1.X, point1.Y, point1.Z)
    doc.Objects.AddPoint(point1)
  elif lineCircleIntersect == LineCircleIntersection.Multiple:
    message = "line intersects circle at points ({0},{1},{2}) and ({3},{4},{5})".format(
      point1.X, point1.Y, point1.Z, point2.X, point2.Y, point2.Z)
    doc.Objects.AddPoint(point1)
    doc.Objects.AddPoint(point2)

  print message
  doc.Views.Redraw()

if __name__ == "__main__":
    RunCommand()
See Also