Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:insertknot [2015/09/14] (current)
Line 1: Line 1:
 +====== Add a Knot to a NURBS Curve ======
 +> **Developer:​** //​[[developer:​dotnetplugins|.NET]]//​
 +> **Summary:​** //​Demonstrates how to add a knot to a NURBS curve.//
 +> **NOTICE:** //The Rhino.NET SDK is deprecated in Rhino 5.  This example adapted for the new RhinoCommon SDK is [[developer:​rhinocommonsamples:​intertknot|here]]//​
 +==== C# ====
 +<code c#>
 +public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
 +{
 +  MRhinoGetObject go = new MRhinoGetObject();​
 +  go.SetCommandPrompt("​Select curve for knot insertion"​);​
 +  go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);​
 +  go.EnableSubObjectSelect(false);​
 +  go.GetObjects(1,​ 1);
 +  if (go.CommandResult() != IRhinoCommand.result.success)
 +    return go.CommandResult();​
 +
 +  IOnCurve curve = go.Object(0).Curve();​
 +  if (null == curve)
 +    return IRhinoCommand.result.failure;​
 +
 +  OnNurbsCurve nurb = new OnNurbsCurve();​
 +  if (0 == curve.GetNurbForm(ref nurb))
 +    return IRhinoCommand.result.failure;​
 +
 +  MRhinoGetPoint gp = new MRhinoGetPoint();​
 +  gp.SetCommandPrompt("​Point on curve to add knot"​);​
 +  gp.Constrain(nurb);​
 +  gp.GetPoint();​
 +  if (gp.CommandResult() == IRhinoCommand.result.success)
 +  {
 +    double t = 0.0;
 +    IOnCurve crv = gp.PointOnCurve(ref t);
 +    if (null != crv && nurb.InsertKnot(t,​ 1))
 +    {
 +      context.m_doc.ReplaceObject(go.Object(0),​ nurb);
 +      context.m_doc.Redraw();​
 +    }
 +  }
 +
 +  return IRhinoCommand.result.success;​
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer dotnet}}
  
developer/insertknot.txt ยท Last modified: 2015/09/14 (external edit)