Site Tools


Adding Curvature Circles

Developer: RhinoScript
Summary: Demonstrates how to add curvature circles using RhinoScript.

Question

I find Rhino's Curvature command very useful for analyzing the curvature at a point on a curve. Is there anyway for Rhino to add the circle to the document when I pick on the curve (instead of just drawing it dynamically)?

Answer

There is no option on the Curvature command for leaving the circle that it draw dynamically. But, with the help of a script, you can write a subroutine that will. The following example demonstrates how to do just this.

Note, if you want to run the following script, just download it. Then, extract the .rvb file from the zip file onto your desktop, and then drag it on top of Rhino and drop it. Finally, run the CurvatureCircle command.

RhinoScript

Option Explicit 
 
Sub CurvatureCircle
  Dim crv, crv_pt, crv_t
  Dim arr, crv_pl, pl
 
  crv = Rhino.GetObject("Select curve for curvature measurement", 4, True)
  If IsNull(crv) Then Exit Sub
 
  Do    
    crv_pt = Rhino.GetPointOnCurve(crv, "Select point on curve for curvature measurement")
    If IsNull(crv_pt) Then Exit Do
 
    crv_t = Rhino.CurveClosestPoint(crv, crv_pt)
    If IsNull(crv_t) Then Exit Do
 
    arr = Rhino.CurveCurvature(crv, crv_t)
    If IsNull(arr) Then 
      Rhino.Print("Unable to compute curve curvature.")
      Exit Do
    End If
 
    crv_pl = Rhino.PlaneFromFrame(arr(0), arr(1), arr(4))
    pl = Rhino.MovePlane(crv_pl, arr(2))
 
    Rhino.AddCircle pl, arr(3)
    Rhino.AddPoint arr(0)
  Loop While Not IsNull(crv_pt)
End Sub

Python

import rhinoscriptsyntax as rs
 
def curvaturecircle():
    curve = rs.GetObject("Select curve for curvature measurement", rs.filter.curve, True)
    if not curve: return
 
    while True:
        crv_pt = rs.GetPointOnCurve(curve, "Select point on curve for curvature measurement")
        if not crv_pt: break
 
        crv_t = rs.CurveClosestPoint(curve, crv_pt)
        arr = rs.CurveCurvature(curve, crv_t)
        if not arr:
            print "Unable to compute curve curvature."
            break
 
        crv_pl = rs.PlaneFromFrame(arr[0], arr[1], arr[4])
        pl = rs.MovePlane(crv_pl, arr[2])
 
        rs.AddCircle(pl, arr[3])
        rs.AddPoint(arr[0])
 
curvaturecircle()



developer/scriptsamples/curvaturecircle.txt ยท Last modified: 2011/11/11 by dale