Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:arclengthpoint [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Find point on curve at distance =====
 +
 +===== C# =====
 +<code c#>
 +public static Rhino.Commands.Result ArcLengthPoint(Rhino.RhinoDoc doc)
 +{
 +  Rhino.DocObjects.ObjRef objref;
 +  Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("​Select curve",​
 +    true, Rhino.DocObjects.ObjectType.Curve,​out objref);
 +  if(rc!= Rhino.Commands.Result.Success)
 +    return rc;
 +  Rhino.Geometry.Curve crv = objref.Curve();​
 +  if( crv==null )
 +    return Rhino.Commands.Result.Failure;​
 + 
 +  double crv_length = crv.GetLength();​
 +  double length = 0;
 +  rc = Rhino.Input.RhinoGet.GetNumber("​Length from start",​ true, ref length, 0, crv_length);​
 +  if(rc!= Rhino.Commands.Result.Success)
 +    return rc;
 + 
 +  Rhino.Geometry.Point3d pt = crv.PointAtLength(length);​
 +  if (pt.IsValid)
 +  {
 +    doc.Objects.AddPoint(pt);​
 +    doc.Views.Redraw();​
 +  }
 +  return Rhino.Commands.Result.Success;​
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Shared Function ArcLengthPoint(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result
 +  Dim objref As Rhino.DocObjects.ObjRef = Nothing
 +  Dim rc As Rhino.Commands.Result = Rhino.Input.RhinoGet.GetOneObject("​Select curve",​ True, Rhino.DocObjects.ObjectType.Curve,​ objref)
 +  If rc <> Rhino.Commands.Result.Success Then
 +    Return rc
 +  End If
 +  Dim crv As Rhino.Geometry.Curve = objref.Curve()
 +  If crv Is Nothing Then
 +    Return Rhino.Commands.Result.Failure
 +  End If
 +
 +  Dim crv_length As Double = crv.GetLength()
 +  Dim length As Double = 0
 +  rc = Rhino.Input.RhinoGet.GetNumber("​Length from start",​ True, length, 0, crv_length)
 +  If rc <> Rhino.Commands.Result.Success Then
 +    Return rc
 +  End If
 +
 +  Dim pt As Rhino.Geometry.Point3d = crv.PointAtLength(length)
 +  If pt.IsValid Then
 +    doc.Objects.AddPoint(pt)
 +    doc.Views.Redraw()
 +  End If
 +  Return Rhino.Commands.Result.Success
 +End Function
 +</​code>​
 +===== Python =====
 +<code python>
 +import Rhino
 +import scriptcontext
 +
 +def ArcLengthPoint():​
 +    rc, objref = Rhino.Input.RhinoGet.GetOneObject("​Select curve",​ True, Rhino.DocObjects.ObjectType.Curve)
 +    if rc!=Rhino.Commands.Result.Success:​ return rc
 +    crv = objref.Curve()
 +    if not crv: return Rhino.Commands.Result.Failure
 +    crv_length = crv.GetLength()
 +    length = 0
 +    rc, length = Rhino.Input.RhinoGet.GetNumber("​Length from start",​ True, length, 0, crv_length)
 +    if rc!=Rhino.Commands.Result.Success:​ return rc
 +    pt = crv.PointAtLength(length)
 +    if pt.IsValid:
 +        scriptcontext.doc.Objects.AddPoint(pt)
 +        scriptcontext.doc.Views.Redraw()
 +    return Rhino.Commands.Result.Success
 +
 +if __name__=="​__main__":​
 +    ArcLengthPoint()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/arclengthpoint.txt ยท Last modified: 2015/09/14 (external edit)