Site Tools


Intersecting a Line with a Circle

Developer: .NET
Summary: Demonstrates how to intersect a line with a circle.
Notice: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here.

Question

How can I intersect a line with a circle?

Answer

See the following example.

C#

OnCircle circle = new OnCircle(OnPlane.World_xy, 5.0);
OnLine line = new OnLine(new On3dPoint(0, 0, 0), new On3dPoint(10, 0, 0));
 
double line_t0 = 0;
double line_t1 = 0;
On3dPoint circle_point0 = new On3dPoint();
On3dPoint circle_point1 = new On3dPoint();
 
// Intersects an infinite line and a circle
int rc = OnUtil.ON_Intersect(line, circle, ref line_t0, ref circle_point0, ref line_t1, ref circle_point1);
if( rc > 0)
{
  context.m_doc.AddPointObject(circle_point0);
  if (rc == 2)
    context.m_doc.AddPointObject(circle_point1);
  context.m_doc.Redraw();
}


developer/sdksamples/intersectlinecircle.txt ยท Last modified: 2016/03/16 by sandy