McNeel Wiki
Distance on a Curve from a Point
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

日本語

한국어

中文(繁體)

中文(简体)

 
.
DeveloperRhinoScript
VersionRhino 4.0
SummaryDemonstrates how to determine a point on a curve that is a specifed distance from another point.

Question

How would you create a point that is a given distance from another point, where the distance is to be measured along the curve.

For example:

Answer

The problem can be easily solved by using RhinoScript's CurveArcLengthPoint function. The CurveArcLengthPoint function returns the point on the curve that is a specified arc length from the start of the curve. By first determining the distance of the known point from the start of the curve, you can then determine how far to offset another point.

For example:

  Option Explicit


  Sub OffsetPointOnCurve


    ' Select the curve
    Dim crv : crv = Rhino.GetObject("Select curve", 4)
    If IsNull(crv) Then Exit Sub


    ' Select a point on the curve to offset from      
    Dim pt : pt = Rhino.GetPointOnCurve(crv, "Select point on curve")
    If IsNull( pt) Then Exit Sub


    ' Specify the offset distance    
    Dim dist : dist = Rhino.GetReal("Distance to offset point")
    If IsNull(dist) Then Exit Sub


    ' Get the closest point on the curve from the test point      
    Dim t : t = Rhino.CurveClosestPoint(crv, pt)


    ' Get the curve's domain
    Dim d : dom = Rhino.CurveDomain(crv)


    ' Get the total length of the curve
    Dim l : l = Rhino.CurveLength(crv)


    ' Determine the length from the start of the curve to the test point
    Dim ls : ls = Rhino.CurveLength(crv,,Array(Dom(0),t))


    ' Offset a point in each direction    
    Rhino.AddPoint Rhino.CurveArcLengthPoint(crv, ls + dist, True)
    Rhino.AddPoint Rhino.CurveArcLengthPoint(crv, l - ls + dist, False)


    ' Add the test point for reference
    Rhino.AddPoint pt


  End Sub
rename · changes · history · subscriptions · lost and found · references · file upload