RhinoScript – Curves

All curves are defined by their DOMAIN. The domain of a curve is a value between 0 & 1, where 0 is the start of the curve, and 1 the end. The domain does not refer to the length of a curve, but it is influenced by the curvature of the curve.
Example 01: Get a point along a curve
To execute this script, you will first need to draw a curve. To understand CURVE DOMAINS better, try drawing a curves of different degrees of curvature, namely; 1,2 & 3 degree curves.
Option Explicit 'Script written by www.supermanoeuvre.com Call addPoints2Curve() Sub addPoints2Curve() '------------------------------------------------------------------------------------------------------ ' USER INPUT Dim strCrv : strCrv = rhino.getObject("Gimme CURVE object!", 4) If isNull(strCrv) Then Exit Sub Dim numPtsOnCrv : numPtsOnCrv = rhino.getInteger("Gimme number of POINTS t make on curve!", 50, 2, 100) If isNull(numPtsOnCrv) Then Exit Sub '------------------------------------------------------------------------------------------------------ ' SCRIPT BODY rhino.print "SCRIPT STARTED" ' Get the curve domain using the rhino script method Dim arrCrvDom : arrCrvDom = rhino.CurveDomain(strCrv) '----------------------------------------------------- ' Now define the minimum and maximum curve values Dim i, uMin, uMax, uStep, dblParam , arrPtOnCrv uMin = arrCrvDom(0) uMax = arrCrvDom(1) uStep = (uMax - uMin) / numPtsOnCrv '----------------------------------------------------- ' Loop to create points For i = 0 To numPtsOnCrv ' Define a paraemter point along the curve dblParam = i * uStep arrPtOnCrv = rhino.evaluateCurve(strCrv, dblParam) ' make a point object at this position rhino.addPoint arrPtOnCrv Next rhino.print "SCRIPT COMPLETED" End Sub

Example 02: Connect 2 Random Points on a Closed Curve
Option Explicit Call curveRandomEval() Sub curveRandomEval() '--------------------------------------------------------------- ' USER INUTS Dim strCrv : strCrv = rhino.getObject("Gimme closed CURVE", 4) If isnull(strCrv) Then rhino.Print "dude! where's my CURVE!" If isnull(strCrv) Then Exit Sub Dim numCrvs : numCrvs = rhino.getInteger("How many new curve to create", 75, 20, 150) If isnull(numCrvs) Then Exit Sub '--------------------------------------------------------------- ' SCRIPT BODY rhino.print "!!! SCRIPT STARTED !!!" ' Curve domain vals Dim arrCrvDom : arrCrvDom = rhino.CurveDomain(strCrv) Dim uMin : uMin = arrCrvDom(0) Dim uMax : uMax = arrCrvDom(1) Dim i, dblParam, arrPt01, arrPt02 ' Nested loop to get two random points on the curve For i = 0 To numCrvs-1 dblParam = rnd*(uMax-uMin) arrPt01 = rhino.evaluateCurve(strCrv, dblParam) dblParam = rnd*(uMax-uMin) arrPt02 = rhino.evaluateCurve(strCrv, dblParam) rhino.addLine arrPt01, arrPt02 ' tell the user how the script is going! rhino.print CInt((i/numCrvs)*100) & " % curves completed !!!" Next rhino.print "!!! SCRIPT COMPLETED !!!" rhino.print numCrvs & " curves drawn" End Sub

Option Explicit 'Script written by www.supermanoeuvre.com Call catenoid_ArrayShifting() Sub catenoid_ArrayShifting() '-------------------------------------------------------------------------------------------- ' SCRIPT BODY Dim dblRadTop : dblRadTop = 10 Dim dblRadBot : dblRadBot = 15 Dim dblHeight : dblHeight = 50 Dim intDivs : intDivs = 20 Dim intShift : intShift = 9 '-------------------------------------------------------------------------------------------- ' SCRIPT BODY ' TOP CURVE Dim StrCrvTop : strCrvTop = rhino.addCircle( Rhino.WorldXYPlane, dblRadTop ) Call rhino.moveObject(strCrvTop, Array(0,0,0), Array(0,0,dblHeight)) Dim arrPtsTop : arrPtsTop = rhino.DivideCurve(StrCrvTop, intDivs) ' BOTTOM CURVE Dim StrCrvBot : StrCrvBot = rhino.addCircle( Rhino.WorldXYPlane, dblRadBot ) Dim arrPtsBot : arrPtsBot = rhino.DivideCurve(StrCrvBot, intDivs) ' LOOP TO CREAT LINES Dim i, arrPtShift, indexCounter indexCounter = intShift For i = 0 To ubound(arrPtsBot) arrPtShift = arrPtsTop( indexCounter ) Call rhino.addLine(arrPtsBot(i), arrPtShift) ' keep the top point in range If indexCounter < (ubound(arrPtsBot)) Then indexCounter = indexCounter + 1 Else indexCounter = 0 End If Next End Sub
About this entry
You’re currently reading “RhinoScript – Curves”, an entry on supermanoeuvre
- Published:
- 28.04.09 / 9am
- Category:
- RhinoScript, Tutorials
- Tags:
- Post Navigation:
- « RhinoScript – Fractals
RhinoScript – Surfaces: Part 01 »
Comments are closed
Comments are currently closed on this entry.