# Lattice Pipe

This Rhino Script allows the user to create an oscillating lattice of curves.  The user is asked to select a curve to act as a rail.  The user can then select the number of strands that will oscillate around the rail, the number of points of contact, and an overall torsion if desired.  In addition, the user can select a minimum and maximum radius of oscillation as well as the number of times it will move between these two radii.

## Rhino Script

```Option Explicit
'Script written by <David Mans>
'Script version Sunday, August 30, 2009 1:22:47 AM

Call Main()
Sub Main()
Dim strCurve
strCurve = Rhino.GetObject("Select Curve", 4, True)
If isNull(strCurve) Then Exit Sub
Call reparameterize(strCurve)

Dim i, j, temp, strLayer
Call Rhino.EnableRedraw(False)
For i = 2 To 10 Step 1
temp = curveLattice(strCurve, 8, 6, 1 / i, array(1, 2), 4, 18)
strLayer = CStr("test_05_" &amp; i)
For j = 0 To uBound(temp) - 1 Step 1
Call Rhino.ObjectLayer(temp(j), strLayer)
Next
Next
Call Rhino.EnableRedraw(True)

End Sub
curveLattice = Null
intOscillations = intOscillations * 2

Dim i,j, count, tDom, tStep, rStep, dblSc
Dim tFrame, rFrame
Dim arrOutput(),arrPt()

count = intSamples * intOscillations
ReDim arrPt(count), arrOutput(intStrands)

tDom = Rhino.CurveDomain(strCurve)
tStep = (tDom(1) - tDom(0)) / count
rStep = 360 / intStrands

For i = 0 To intStrands - 1 Step 1
For j = 0 To count Step 1
tFrame = Rhino.CurvePerpFrame(strCurve, tDom(0) + tStep * j)
If i Mod (2) Then
rFrame = Rhino.RotatePlane(tFrame, rStep * i + (rStep * 0.5) * sin(intOscillations * PI * (j / count)) + (360 * dblRotation) * j / count, tFrame(3))
Else
rFrame = Rhino.RotatePlane(tFrame, rStep * i + (rStep * 0.5) * sin(PI + intOscillations * PI * (j / count)) + (360 * dblRotation) * j / count, tFrame(3))
End If
arrPt(j) = Rhino.PointAdd(tFrame(0), Rhino.VectorScale(Rhino.VectorUnitize(rFrame(1)), arrRadius(0) + dblSc + dblSc * cos(intRadius * PI * (j / count))))
Next

Next

curveLattice = arrOutput
End Function
Function reparameterize(strObjectID)
If Rhino.IsCurve(strObjectID) = True Then
Call rhino.SelectObject(strObjectID)
Call rhino.Command("reparameterize 0 1")
Call rhino.UnselectAllObjects()
End If
If Rhino.IsSurface(strObjectID) = True Then
Call rhino.SelectObject(strObjectID)
Call rhino.Command("reparameterize 0 1 0 1")
Call rhino.UnselectAllObjects()
End If
End Function```