Site Tools

Curve-Surface Intersection


Summary: Demonstrates how to get the intersection between a surface and a curve
NOTICE: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here


Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext)_
       As IRhinoCommand.result
  'get a surface
  Dim getsurface As New MRhinoGetObject()
  getsurface.SetCommandPrompt("Select Surface")
                            Or IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object)
  getsurface.GetObjects(1, 1)
  If (getsurface.CommandResult() <> IRhinoCommand.result.success) Then
    Return getsurface.CommandResult()
  End If
  'get a curve
  Dim getcurve As New MRhinoGetObject()
  getcurve.SetCommandPrompt("Select Curve")
  getcurve.GetObjects(1, 1)
  If (getcurve.CommandResult() <> IRhinoCommand.result.success) Then
    Return getcurve.CommandResult()
  End If
  Dim brep As IOnBrep = getsurface.Object(0).Brep()
  Dim curve As IOnCurve = getcurve.Object(0).Curve()
  If (brep Is Nothing Or curve Is Nothing) Then
    Return IRhinoCommand.result.failure
  End If
  Dim tol As Double = context.m_doc.AbsoluteTolerance()
  Dim curves(0) As OnCurve
  Dim points As New On3dPointArray
  Dim rc As Boolean = RhUtil.RhinoCurveBrepIntersect(curve, brep, tol, curves, points)
  If (rc = True) Then
    For i As Integer = 0 To points.Count() - 1
  End If
  Return IRhinoCommand.result.success
End Function


public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  // get a surface
  MRhinoGetObject getsurface = new MRhinoGetObject();
  getsurface.SetCommandPrompt("Select Surface");
  getsurface.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object |
  getsurface.GetObjects(1, 1);
  if(getsurface.CommandResult() != IRhinoCommand.result.success)
    return getsurface.CommandResult();
  // get a curve
  MRhinoGetObject getcurve = new MRhinoGetObject();
  getcurve.SetCommandPrompt("Select Curve");
  getcurve.GetObjects(1, 1);
  if(getcurve.CommandResult() != IRhinoCommand.result.success)
    return getcurve.CommandResult();
  IOnBrep brep = getsurface.Object(0).Brep();
  IOnCurve curve = getcurve.Object(0).Curve();
  if(brep == null | curve == null)
    return IRhinoCommand.result.failure;
  double tol = context.m_doc.AbsoluteTolerance();
  OnCurve[] curves = null;
  On3dPointArray points = null;
  bool rc = RhUtil.RhinoCurveBrepIntersect(curve, brep, tol,out curves,out points);
  if( rc && points != null )
    for( int i=0; i<points.Count(); i++ )
  return IRhinoCommand.result.success;
developer/sdksamples/curvesurfaceintersect.txt ยท Last modified: 2015/09/14 (external edit)