RhinoScript – Parametric Curves ( Sine, Cosine & Tan )

Option Explicit 'Script written by www.supermanoeuvre.com Call math_circleMaker() Sub math_circleMaker() '----------------------------------------------------------------------------------------------------------- ' USER INPUTS Dim strPt : strPt = rhino.GetObject("gimme POINT object", 1) If isNull(strPt) Then Exit Sub Dim arrCmds(1) arrCmds(0) = "clockwise" arrCmds(1) = "anticlockwise" Dim strCmd : strCmd = rhino.getString("which Direction do you want to draw the circle???", , arrCmds ) Dim numPts : numPts = 12 Dim dblRad : dblRad = 10 '----------------------------------------------------------------------------------------------------------- ' SCRIPT BODY Dim i, counter, arrPtCrv, dblCoordXX, dblCoordYY, dblCoordZZ, arrPtCoord, uSteps arrPtCoord = rhino.pointCoordinates(strPt) uSteps = (2*PI) / numPts ReDim arrPtSet(numPts-1) counter = 0 Select Case strCmd Case "clockwise" For i = numPts - 1 To 0 Step -1 dblCoordXX = arrPtCoord(0) + (dblRad*cos(i*uSteps)) dblCoordYY = arrPtCoord(1) + (dblRad*sin(i*uSteps)) dblCoordZZ = arrPtCoord(2) arrPtSet(counter) = Array(dblCoordXX, dblCoordYY, dblCoordZZ) counter = counter + 1 Call rhino.addTextDot("pt" & counter, arrPtSet(counter-1)) If counter = numPts Then ReDim Preserve arrPtSet(counter) arrPtSet(counter) = arrPtSet(0) End If Next Case "anticlockwise" For i = 0 To numPts - 1 dblCoordXX = arrPtCoord(0) + (dblRad*cos(i*uSteps)) dblCoordYY = arrPtCoord(1) + (dblRad*sin(i*uSteps)) dblCoordZZ = arrPtCoord(2) arrPtSet(counter) = Array(dblCoordXX, dblCoordYY, dblCoordZZ) counter = counter + 1 Call rhino.addTextDot("pt" & counter, arrPtSet(counter-1)) If counter = numPts Then ReDim Preserve arrPtSet(counter) arrPtSet(counter) = arrPtSet(0) End If Next End Select ' Call Rhino.addInterpCurve(arrPtSet) Call Rhino.addPolyLine(arrPtSet) 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

SINE CURVES
Example 01: Simple Sin Curve
Following example generates two simple parametric curves using the sine mathematic function. We can control the direction of the curve through the manner in which we describe the sine pattern as is clearly seen in the code.
Option Explicit 'Script written by www.supermanoeuvre.com Call math_SinWave() Sub math_SinWave() Dim dblWavelength : dblWavelength = 100 Dim intPts2Plot : intPts2Plot = 50 Dim dblMagnitude : dblMagnitude = 2 Dim dblFrequency : dblFrequency = 1 Dim i Dim uStep, tParam ReDim arrPtSet1(intPts2Plot), arrPtSet2(intPts2Plot) uStep = dblWavelength / intPts2Plot ''' EXAMPLE: Classic sine()wave formula tParam = ((2 * PI)*dblFrequency) / intPts2Plot ''' EXAMPLE: Shortened wave period ' tParam = ((2 *(PI/3))*dblFrequency) / intPts2Plot For i = 0 To intPts2Plot ' Traditional Direction arrPtSet1(i) = Array( i*uStep, sin(i*tParam)*dblMagnitude, 0 ) ' Opposite direction - note difference of Y component arrPtSet2(i) = Array( i*uStep, sin( (intPts2Plot-i) *tParam)*dblMagnitude, 0 ) Next ' draw the resultant curves Call Rhino.AddInterpCurve(arrPtSet1) Call Rhino.AddInterpCurve(arrPtSet2) End Sub
About this entry
You’re currently reading “RhinoScript – Parametric Curves ( Sine, Cosine & Tan )”, an entry on supermanoeuvre
- Published:
- 28.04.09 / 10am
- Category:
- RhinoScript, Tutorials
- Tags:
- Post Navigation:
- « RhinoScript – Surfaces: Part 01
RhinoScript – Attractors »
Comments are closed
Comments are currently closed on this entry.