RhinoCommon API
IntersectionLineCircle Method |
Intersects a line with a circle using exact calculations.
Namespace: Rhino.Geometry.Intersect
Assembly: RhinoCommon (in RhinoCommon.dll)

public static LineCircleIntersection LineCircle( Line line, Circle circle, out double t1, out Point3d point1, out double t2, out Point3d point2 )
Public Shared Function LineCircle ( line As Line, circle As Circle, <OutAttribute> ByRef t1 As Double, <OutAttribute> ByRef point1 As Point3d, <OutAttribute> ByRef t2 As Double, <OutAttribute> ByRef point2 As Point3d ) As LineCircleIntersection
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: LineCircleIntersectionIf Single is returned, only t1 and point1 will have valid values. If Multiple is returned, t2 and point2 will also be filled out.

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; } } }
Imports Rhino Imports Rhino.Commands Imports Rhino.Geometry Imports Rhino.Geometry.Intersect Namespace examples_vb Public Class IntersectLineCircleCommand Inherits Command Public Overrides ReadOnly Property EnglishName() As String Get Return "vbIntersectLineCircle" End Get End Property Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result Dim circle As Circle Dim rc = Rhino.Input.RhinoGet.GetCircle(circle) If rc <> Result.Success Then Return rc End If doc.Objects.AddCircle(circle) doc.Views.Redraw() Dim line As Line rc = Rhino.Input.RhinoGet.GetLine(line) If rc <> Result.Success Then Return rc End If doc.Objects.AddLine(line) doc.Views.Redraw() Dim t1 As Double, t2 As Double Dim point1 As Point3d, point2 As Point3d Dim lineCircleIntersect = Intersection.LineCircle(line, circle, t1, point1, t2, point2) Dim msg As String = "" Select Case lineCircleIntersect Case LineCircleIntersection.None msg = "line does not intersect circle" Exit Select Case LineCircleIntersection.[Single] msg = [String].Format("line intersects circle at point ({0},{1},{2})", point1.X, point1.Y, point1.Z) doc.Objects.AddPoint(point1) Exit Select Case LineCircleIntersection.Multiple msg = [String].Format("line intersects circle at points ({0},{1},{2}) and ({3},{4},{5})", point1.X, point1.Y, point1.Z, point2.X, point2.Y, _ point2.Z) doc.Objects.AddPoint(point1) doc.Objects.AddPoint(point2) Exit Select End Select RhinoApp.WriteLine(msg) doc.Views.Redraw() Return Result.Success End Function End Class End Namespace
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()

Rhino for Mac
Supported in: 5.4Rhino for Windows
Supported in: 6.8