090923_Bending Simulation

Degree_5

Bending angle = 5 degreeDegree_15

Bending angle = 15 degree

Degree_30

Bending angle = 30 degree

 

 

 

 

Call main
Sub main
 Dim ptStart, vecDir, Props(6), Generation
 
 ‘ ptStart = Rhino.GetPoints(True)
 ptStart = Rhino.PointCloudPoints(rhino.GetObject(“select pointCloud”,2))
 vecDir = array (0,0,1)
 ‘Props = array(1,2,10,2,0.9,30,0.9)
 props(0)=1
 Props(1)=1
 Props(2)= 10
 Props(3)= 2
 Props(4)= 0.9
 props(5)= 5
 Props(6)= 0.9
 
 For i =0 To ubound(ptStart)
  recursiveGrowth ptStart(i), vecDir, Props, generation
 Next 

 
End Sub

Function RecursiveGrowth(ByVal ptStart, ByVal vecDir, ByVal Props(), ByVal Generation)
 If Generation > Props(2) Then Exit Function
 Dim ptGrow, vecGrow, newTwig
 Dim newProps : newProps = Props
 newProps(3) = Props(3) * Props(4)
 newProps(5) = Props(5) * Props(6)
 If newProps(5) > 90 Then newProps(5) = 90
 Dim N, maxN
 maxN = CInt(Props(0) + Rnd() * (Props(1) – Props(0)))
 For N = 1 To maxN
  ptGrow = RandomPointInCone(ptStart, vecDir, 0.25*Props(3), Props(3), Props(5))
  newTwig = AddArcDir(ptStart, ptGrow, vecDir)
  If Not IsNull(newTwig) Then
   vecGrow = Rhino.CurveTangent(newTwig, Rhino.CurveDomain(newTwig)(1))
   Call RecursiveGrowth(ptGrow, vecGrow, newProps, Generation+1)
  End If
 Next
End Function

 

Function RandomPointInCone(ByVal Origin, ByVal Direction, ByVal MinDistance, ByVal MaxDistance, ByVal MaxAngle)
 Dim vecTwig
 vecTwig = Rhino.VectorUnitize(Direction)
 vecTwig = Rhino.VectorScale(vecTwig, MinDistance + Rnd() * (MaxDistance-MinDistance)) ‘ assign values
 
 Dim MutationPlane
 MutationPlane = Rhino.PlaneFromNormal(Array(0,0,0), vecTwig)
 vecTwig = Rhino.VectorRotate(vecTwig, Rnd() * maxAngle, MutationPlane(1))
 vecTwig = Rhino.VectorRotate(vecTwig, Rnd() * 360, Direction)
 RandomPointInCone = Rhino.PointAdd(Origin, vecTwig)
End Function
Function AddArcDir(ByVal ptStart, ByVal ptEnd, ByVal vecDir)
 AddArcDir = Null
 Dim vecBase : vecBase = Rhino.PointSubtract(ptEnd, ptStart)
 If Rhino.VectorLength(vecBase) = 0.0 Then Exit Function
 If Rhino.IsVectorParallelTo(vecBase, vecDir) Then Exit Function
 vecBase = Rhino.VectorUnitize(vecBase)
 vecDir = Rhino.VectorUnitize(vecDir)
 Dim vecBisector : vecBisector = Rhino.VectorAdd(vecDir, vecBase)
 vecBisector = Rhino.VectorUnitize(vecBisector)
 Dim dotProd : dotProd = Rhino.VectorDotProduct(vecBisector, vecDir)
 Dim midLength : midLength = (0.5 * Rhino.Distance(ptStart, ptEnd)) / dotProd
 vecBisector = Rhino.VectorScale(vecBisector, midLength)
 AddArcDir = Rhino.AddArc3Pt(ptStart, ptEnd, Rhino.PointAdd(ptStart, vecBisector))
End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s