McNeel Wiki
Find Closest Curve to Test Point
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

中文(简体)

 
.
DeveloperRhinoScript
SummaryDemonstrates how to find the closest curve to test point using RhinoScript.

The following RhinoScript sample demonstrates how to find the closest curve to test point using RhinoScript.

  Sub FindClosestCurve


    Const rhPoint = 1
    Const rhCurve = 4


    'Dim arrCurves : arrCurves = Rhino.ObjectsByType(rhCurve)
    Dim arrCurves: arrCurves = Rhino.GetObjects("Select curves to test", rhCurve)
    If Not IsArray(arrCurves) Then Exit Sub


    Dim strPoint : strPoint = Rhino.GetObject("Select test point", rhPoint)
    If IsNull(strPoint) Then Exit Sub


    Dim arrPoint : arrPoint = Rhino.PointCoordinates(strPoint)


    Dim dblDistance : dblDistance = Null
    Dim strCurve : strCurve = Null
    Dim dblParameter : dblParameter = Null
    Dim arrPt : arrPt = Null


    Dim i, b, t, pt, d
    For i = 0 To UBound(arrCurves)
      b = vbFalse
      t = Rhino.CurveClosestPoint( arrCurves(i), arrPoint )
      If Not IsNull(t) Then
        pt = Rhino.EvaluateCurve( arrCurves(i), t )
        If IsArray(pt) Then
          d = Rhino.Distance(pt, arrPoint)
          If IsNull(dblDistance) Then
            b = vbTrue
          ElseIf (d < dblDistance) Then
            b = vbTrue
          End If


          If (b = vbTrue) Then
            dblDistance = d
            strCurve = arrCurves(i)
            dblParameter = t
            arrPt = pt
          End If
        End If
      End If
    Next


    If Not IsNull(dblDistance) Then
      Rhino.Print "Closest curve = " & CStr(strCurve)
      Rhino.Print "Curve parameter = " & CStr(dblParameter)
      Rhino.Print "Point = " & Rhino.Pt2Str(arrPt)
      Rhino.Print "Distance = " & CStr(dblDistance)


      Rhino.SelectObject strCurve
      Rhino.SelectObject Rhino.AddPoint(arrPt)
    End If


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