(n)certainties – Columbia – Fall 2007

071114_Agritect_v4.5

‘########################################################################################################
‘###     AGRITECT version 4.5 : November 14, 2007                                                    
‘###     Copyrighted Matthew R. Pauly, 2007, All rights reserved
‘###     Script developed for (n)certainties studio                                                  
‘########################################################################################################
  Option Explicit
  Call Rhino.Print( ” __________________________ START OF SCRIPT ___________________________ ” )
  Dim gYEAR, gRINGS, gPLOT_low, gPLOT_high, gPath_height, gPath_divisions, gDirection, gPath_r1, gPath_r2
  Dim gCheck
‘######################################## GLOBAL PARAMETERS #############################################
 gYEAR = 600            ’<— Global YEARS the system runs
 gPLOT_high = 200      ’<— Yield, High (in bushels per acre)
 gPLOT_low = 165      ’<— Yield, Low  (in bushels per acre)
 gPath_height = 8         ’<— Start floor to floor height (in meters)
 gPath_r1 = 80      ’<— TEMPORARY seed inner radius(start)
 gPath_r2 = 24     ’<— TEMPORARY seed thickness
 gDirection = 1     ’<— TEMPROARY might change direction depending on seed, Not used
 gPath_divisions = 20  ’<— Number of “chutes” and seeds
 gCheck = gPath_r2 * 3  ’<— Distance to Leech
 ’——FIXED VARIABLES——
 gRINGS = 7       ’<— Number of rings  (3 PLOT, 4 INTERSTICE)
‘########################################################################################################
Call Rhino.EnableRedraw(false)
Call Growth(gYEAR, gRINGS, gPLOT_high, gPLOT_low, gPath_r1, gPath_r2)
Call Rhino.EnableRedraw(true)
‘________________________________________________________________________________________________________
Sub Growth(gYEAR, gRINGS, gPLOT_high, gPLOT_low, gPath_r1, gPath_r2)
 Dim i, temp, lYEAR, gSEED, lSEED, lTheta, lPi, tTheta
 Dim tArr_1(), tArr_2(), tArr_3(2), tYield_1(), tYield_2(), gSEED_start(1), tArr_4(1)
 Dim gPLOT(), gPLOT_lYield(), gPLOT_gYield(), gSEED_chute, gSEED_check(), gSEED_surplus()
 Dim gROBOT_max1, gROBOT_max2, gROBOT_min1, gROBOT_min2
 lTheta = 0
 lPi = Rhino.Pi()
‘———————————————- LOCAL VARIABLES —————————————–
 gSEED = 0′gPath_divisions     ‘<— TEMPORARY Number of seeds, should be lost offspring limit
 gROBOT_max1 = gPath_r1 * 1.1 ’<— Maximum Radius from inner factory
 gROBOT_max2 = gPath_r2 * 2.5 ’<— Maximum width the Robot can expand to
 gROBOT_min1 = gPath_r1 *.95     ‘<— Minimum Radius from inner factory
 gROBOT_min2 = gPath_r2 ‘* .5 ’<— Minimum Width of Robot
‘——————————————————————————————————–
 For lYEAR = 0 to gYEAR
  Redim Preserve gPLOT(lYEAR)
  Redim Preserve gPLOT_lYield(lYEAR)
  Redim Preserve gPLOT_gYield(lYEAR)
  Call func_gYIELD(gPLOT_gYield, gPLOT_low, gPLOT_high, lYEAR)
  If lYEAR < (gPATH_divisions + 1) Then
  lTheta = ((2*lPi)/gPath_divisions ) + lTheta  
  End If
  tTheta = lTheta
  ’———————————————————————————————— 
  For lSEED = 0 to gSEED
   Redim Preserve tArr_1(lSEED)
   Redim Preserve tYield_1(lSEED)
   If lYEAR = 0 Then
    gSEED_chute = 0
    Redim Preserve gSEED_check(lSEED)
    Redim Preserve gSEED_surplus(lSEED)
    gSEED_check(lSEED) = 0
    gSEED_surplus(lSEED) = 0
   End If
   gSEED_check(0) = gPath_divisions + 1
   ’—— Establish each seed’s starting point —–
   If lYEAR < gPath_divisions Then
    If lSEED = 0 Then
     gSEED_start(0) = 0
     gSEED_start(1) = 0
    Else
     gSEED_start(0) = Cos( ((2*lPi)/gPath_divisions)*lSEED )*(  (gPath_r1 + gPath_r2)*2.3 )
     gSEED_start(1) = Sin( ((2*lPi)/gPath_divisions)*lSEED )*(  (gPath_r1 + gPath_r2)*2.3 )
    End If
   Else
    tArr_4(0)=0 
    tArr_4(1)=0 
    For i = 1  to gPath_divisions
     tARR_4(0) = tARR_4(0) + gPLOT(lYEAR-i)(lSEED)(0)(0)
     tARR_4(1) = tARR_4(1) + gPLOT(lYEAR-i)(lSEED)(0)(1)
    Next
    gSEED_start(0) = tARR_4(0)/gPath_divisions
    gSEED_start(1) = tARR_4(1)/gPath_divisions

   End If
   ’————————————————–
   If gSEED_check(lSEED) = 0 And gSEED_chute = lSEED And gPLOT_gYield(lYEAR) > ((gPLOT_high+gPLOT_low)/2) Then
    gSEED_surplus(lSEED) = gSEED_surplus(lSEED) + gPLOT_gYield(lYEAR) – ((gPLOT_high+gPLOT_low)/2)
    If gSEED_surplus(lSEED) > 120 Then ‘<— Critical Mass!!!!
     gSEED_check(lSEED) = 1
    End If
   End If  
   ’__________________________________________________________________________________________  
   Dim temp_Distance3, tHeight
   temp_Distance3 = 0
   
   For i = 0 to gRINGS
    Redim Preserve tArr_2(i)
    Redim Preserve tYield_2(i)
    tArr_2(i) = tArr_3   
    Call func_YIELD(tYield_2, gPLOT_gYield, lYEAR, i)  ’<— Assign local Yield 
   ’—— POSITION ASSIGNMENT ——
   If gSEED_check(lSEED) = 0 Then
    tArr_2(i) = array(gSEED_start(0), gSEED_start(1), 0)  ‘<—- Point assignment for non-triggered seeds
      Else
   ’———————————
    Dim temp_Distance1, temp_Distance2, lPath_r1, lPath_r2
     If lYEAR > gPath_divisions And gSEED_check(lSEED) > gPath_divisions Then ‘ALL LEVELS ABOVE FIRST

     temp_Distance1 = Rhino.Distance(gPLOT(lYEAR – gPATH_divisions)(lSEED)(gRings), gPLOT(lYEAR – gPATH_divisions)(lSEED)(0))
     temp_Distance2 = Rhino.Distance(array( gSEED_start(0), gSEED_start(1), gPLOT(lYEAR – gPATH_divisions)(lSEED)(gRINGS)(2) ), gPLOT(lYEAR – gPATH_divisions)(lSEED)(gRINGS))
     lPath_r2 =  temp_Distance1  * ( (gPLOT_gYield(lYEAR)-gPLOT_low/1.15)/((gPLOT_high + gPLOT_low)/2-gPLOT_low/1.15) )
     lPath_r1 =  temp_Distance2  * ( (gPLOT_gYield(lYEAR))/((gPLOT_high + gPLOT_low)/2) )

     ’—- LIMIT: Robot Radii —
     If lPath_r2 > gROBOT_max2 Then lPath_r2 = gROBOT_max2 End If
     If lPath_r1 > gROBOT_max1 Then lPath_r1 = gROBOT_max1 End If
     If lPath_r2 < gROBOT_min2 Then lPath_r2 = gROBOT_min2 End If
     If lPath_r1 < gROBOT_min1 Then lPath_r1 = gROBOT_min1 End If     
     ’—- Z Location —-

     tArr_2(i)(2) = gPath_height * ((gPLOT_gYield(lYEAR)-gPLOT_low/1.15)/(((gPLOT_high+gPLOT_low)/2)-gPLOT_low/1.15))  + gPLOT(lYEAR-gPath_divisions)(lSEED)(i)(2)
     If i = gRINGS Then
      Dim k
      tArr_2(i)(2) = gPath_height * ((gPLOT_gYield(lYEAR-1)-gPLOT_low/1.15)/(((gPLOT_high+gPLOT_low)/2)-gPLOT_low/1.15))  + gPLOT(lYEAR-gPath_divisions)(lSEED)(i)(2)      
      tHeight = tArr_2(i)(2)-tArr_2(0)(2)
      For k = 2 to gRings – 1 Step 2
       tArr_2(k)(2) =  tArr_2(0)(2) – tHeight*k/gRings 
       tArr_2(k-1)(2) = tArr_2(k)(2)    
      Next
     End If           
     ’—- XY Location —-
    If i = 0 Then ‘ Outer Point
     lTheta = (  ((2*lPi)/gPath_divisions )  ) + tTheta 
     ’lTheta = (  ((2*lPi)/gPath_divisions )*(tYield_2(i)/((gPLOT_high+gPLOT_low)/2))  ) + tTheta 
     tArr_2(i)(0) = (Cos(lTheta) *  lPath_r2)+ (Cos(lTheta) * lPath_r1) + gSEED_start(0)
     tArr_2(i)(1) = (Sin(lTheta) *  lPath_r2)+ (Sin(lTheta) * lPath_r1)+ gSEED_start(1)
     Call func_NEAR(gPLOT, tArr_2, lSEED, lYEAR, gCHECK, gPath_height) ‘<——-
    Else
     lTheta = (  ((2*lPi)/gPath_divisions )  ) + tTheta 
     ’lTheta = (  ((2*lPi)/gPath_divisions )*(tYield_2(i)/((gPLOT_high+gPLOT_low)/2))  ) + tTheta 
     If i = 1 Or i = 3 Or i = 5 Or i = 7 Then
      temp_Distance3 = temp_Distance3 + ((lPath_r2 – gPath_r2)/4)
      tArr_2(i)(0) = (Cos(lTheta) *  (lPath_r2- temp_Distance3))+ (Cos(lTheta) * lPath_r1) + gSEED_start(0)
      tArr_2(i)(1) = (Sin(lTheta) *  (lPath_r2- temp_Distance3))+ (Sin(lTheta) * lPath_r1) + gSEED_start(1)
     Else
      temp_Distance3 = temp_Distance3 + (gPath_r2/3)
      tArr_2(i)(0) = (Cos(lTheta) * (lPath_r2- temp_Distance3))+ (Cos(lTheta) * lPath_r1) + gSEED_start(0)
      tArr_2(i)(1) = (Sin(lTheta) *  (lPath_r2- temp_Distance3))+ (Sin(lTheta) * lPath_r1) + gSEED_start(1)    
     End If
    End If
     ‘——————————-   
     Else ‘ FIRST LEVEL
       ’—- Z Location —-
       If lYEAR = 0  Or gSEED_check(lSEED) = 1 Then ‘FIRST YEAR
      tArr_2(i)(2)=0
         Else
      tArr_2(i)(2)=(gPath_height/gPath_divisions) + gPLOT(lYEAR-1)(lSEED)(i)(2)
     End If
     ’—- XY Location —-
     If i = 1 Or i = 3 Or i = 5 Or i = 7 Then
      tArr_2(i)(0) = tArr_2(i-1)(0)
      tArr_2(i)(1) = tArr_2(i-1)(1)
     Else
      tArr_2(i)(0) = ((Cos(lTheta) * ((gRings -i) /gRings) * gPath_r2)) + (Cos(lTheta) * gPath_r1) + gSEED_start(0)
      tArr_2(i)(1) = ((Sin(lTheta) * ((gRings -i) /gRings) * gPath_r2)) + (Sin(lTheta) * gPath_r1) + gSEED_start(1)
     End If
     End If
   End If
    tArr_1(lSEED) = tArr_2     ’<— Assign “Ring Array” to Seed
    tYield_1(lSEED) = tYield_2
   Next
   ’____________________________________________________________________________________________
    If  gSEED_check(lSEED) > 0 Then
     gSEED_check(lSEED) = gSEED_check(lSEED) + 1
    End If
   gPLOT_lYield(lYEAR) = tYield_1   
   gPLOT(lYEAR) = tArr_1      ’<— Assign “Seed Array” to Year 
  Next
  ’————————————————————————————————
    ’—- Adjust to next Chute —-
    If gSEED_chute < gPath_divisions Then
     gSEED_chute = gSEED_chute + 1
    Else
     gSEED_chute = 0
    End If
 Next
‘——————————————————————————————————–
Call func_BUILD2(gPLOT, gRINGS, gPath_divisions, gYEAR)
End Sub
‘________________________________________ FUNCTION : BUILD 2  ____________________________________________
Function func_BUILD2(gPLOT, gRINGS, gPath_divisions, gYEAR)
Dim lYEAR, lSEED, i, n, tARRAY(), tCIRCLES, tPline, j, k, m, p, tStep
Dim arrPlane, sLofter()
arrPlane = Rhino.WorldXYPlane
lSEED = 0
p=0
‘———————– Rings ————————
For m = 1 to 3
p = 0
For n = 0 to gPATH_divisions
 j = 0
 If p = 0 Then
  tStep = gPath_divisions
  Else
  tStep = 0
 End If

 For i = 0 to (gYEAR-tStep) Step gPATH_divisions
  If i+n <= gYEAR Then
   Redim Preserve tARRAY(j)
   tARRAY(j) = gPLOT(i+n)(lSEED)(m*2-1)
   j = j + 1
  End If
  k = i
 Next
 For i = k to 0 Step -gPATH_divisions
  If i+n <= gYEAR Then
   Redim Preserve tARRAY(j)
   tARRAY(j) = gPLOT(i+n)(lSEED)(m*2)
   j = j + 1
  End If
 Next
 Redim Preserve tARRAY(j)
 tARRAY(j) = tARRAY(0)
 
 Redim Preserve sLofter(p)
 sLofter(p) = Rhino.AddPolyline (tARRAY)
 p = p+1
Next
 Call Rhino.AddLoftSrf(sLofter) 
Next
End Function
‘________________________________________ FUNCTION : lYIELD ____________________________________________
Function func_YIELD(Yield, gPLOT_avg, lYEAR,  i)
 Yield(i) = ( gPLOT_avg(lYEAR) + Random( -0, 0) ) ‘ <— Local Yield
End Function
‘________________________________________ FUNCTION : gYIELD ____________________________________________
Function func_gYIELD(gPLOT_avg, gPLOT_low, gPLOT_high, lYEAR)
 gPLOT_avg(lYEAR) =  Random(gPLOT_low, gPLOT_high)
End Function
‘________________________________________ FUNCTION : RANDOM ____________________________________________
Function Random(low, up) 
 Randomize
 random = ((up – low)* Rnd()) + low ‘ *** take the difference of range
End Function
‘________________________________________ FUNCTION : NEAREST____________________________________________
Function func_NEAR(lPLOT, tPlot, lSEED, lYEAR, gCHECK, gPath_height)
 Dim tYEAR, tSEED, dHOLD, dCHECK_z, dCHECK_xy, holdSEED, holdYEAR, tPoint
 dHOLD = 10000000
 
 For tYEAR = 0 to (uBound(lPLOT)-1)
  For tSEED = 0 to uBound( lPLOT(tYEAR) )
   If tSEED <> lSEED  And lPLOT(tYEAR)(tSEED)(0)(2) > tPLOT(0)(2)Then
    dCHECK_xy = Rhino.Distance( array(lPLOT(tYEAR)(tSEED)(0)(0), lPLOT(tYEAR)(tSEED)(0)(1), 0), array(tPLOT(0)(0), tPLOT(0)(1), 0) )
    dCHECK_z = abs( lPLOT(tYEAR)(tSEED)(0)(2) – tPLOT(0)(2) )
    
    If dCHECK_xy > 0 And dCHECK_xy < gCHECK And dCHECK_xy < dHOLD And dCHECK_z < (gPath_height * .5) Then
     dHOLD = dCHECK_xy
     tPoint = lPLOT(tYEAR)(tSEED)(0)
     holdSEED = tSEED
     holdYEAR = tYEAR   
    End If
   End If
  Next
 Next
 ’—–
 If dHOLD < 10000000 Then
  If dHOLD < (gCHECK * .33) Then
  ’ tPLOT(0) = tPoint
  Else
  ’ Call Rhino.AddCylinder(tPoint, tPLOT(0), 1 )
  End If

 End If
End Function

1 Comment

1 response so far ↓

Leave a Comment