# Intersection.LineCircle examples

Examples for [LineCircle](https://developer.rhino3d.com/api/rhinocommon/type/rhino.geometry.intersect.intersection/linecircle.md) in Rhino.Geometry.Intersect.Intersection.

## C#

```cs
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;
    }
  }
}
```

## Python

```py
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()
```

## VB.NET

```vbnet
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
```
