McNeel Wiki
Curve-Surface Intersection
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
SummaryDemonstrates how to get the intersection between a surface and a curve

VB.NET (Rhino 4)

  Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext)_
         As IRhinoCommand.result
    'get a surface
    Dim getsurface As New MRhinoGetObject()
    getsurface.SetCommandPrompt("Select Surface")
    getsurface.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object_
                              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.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object)
    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
        context.m_doc.AddPointObject(points(i))
      Next
      context.m_doc.Redraw()
    End If
    Return IRhinoCommand.result.success
  End Function

C# (Rhino 4)

  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 |
                                 IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_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.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
    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++ )
        context.m_doc.AddPointObject(points[i]);
      context.m_doc.Redraw();
    }
    return IRhinoCommand.result.success;
  }
rename · changes · history · subscriptions · lost and found · references · file upload