Rs Torsion
Last changed: dale@mcneel.com-204.177.179.107

.
DeveloperRhinoScript
Version4.0
SummaryDemonstrates how to evaluate the torsion of a curve using RhinoScript.

Question

How determine the torsion of a curve at a parameter using RhinoScript?

Answer

The torsion of a curve measures how sharply it is twisting. It is analogous to curvature in two dimensions. The following example function calculates the torsion of a curve at a parameters:

  '''
  ''' Description
  '''   Evaluate the torsion of a curve.
  ''' Parameters
  '''   crv - a string that identifies the curve to evaluate
  '''   t   - a parameter of the curve within its domain
  ''' Returns
  '''   The torsion if successful.
  '''   Null if the torsion is undefined at the parameter.
  '''
  Function EvaluateTorsion(crv, t)


    ' Local variables
    Dim data, d1xd2, numer, denom


    ' Default return value
    EvaluateTorsion = Null


    ' Calculate the torsion
    data = Rhino.CurveEvaluate(crv, t, 3)
    If IsArray(data) And UBound(data) = 3 Then
      d1xd2 = Rhino.VectorCrossProduct(data(1), data(2))
      numer = Rhino.VectorDotProduct(d1xd2, data(3))
      denom = Rhino.VectorDotProduct(d1xd2, d1xd2)
      If denom > 0 Then
        EvaluateTorsion = numer / denom
      End If
    End If


  End Function

The following example script demonstates how you might use the above function:

  Sub TestTorsionOnCurve()


    ' Local variables        
    Dim crv, pt, t, tor


    ' Select curve to evaluate
    crv = Rhino.GetObject("Select curve to evaluate", 4, True)
    If IsNull(crv) Then Exit Sub


    ' Get point on curve to evalaute  
    pt = Rhino.GetPointOnCurve(crv, "Point to evaluate")
    If Not IsArray(pt) Then Exit Sub


    ' Get parameter of the point on a curve that is closest to pt          
    t = Rhino.CurveClosestPoint(crv, pt)
    If IsNull(t) Then Exit Sub


    ' Evaluate the torsion of the curve at t.          
    tor = EvaluateTorsion(crv, t)
    If IsNull(tor) Then
      Rhino.Print "Torsion at curve parameter " & CStr(t) & " is undefined"
    Else
      Rhino.Print "Torsion at curve parameter " & CStr(t) & " is " & CStr(tor)
    End If


  End Sub