MS_Draw_On_Surface

porosiy2Option Explicit
‘Script written by <Adolfo Nadal, Gwen MacFarland, Koko Takahashi and Jay Shah>
‘Script version Sunday, July 20, 2008 10:40:30 AM

Call Main()
 
Sub Main()
 
 Dim i,j,k,w,q,g,t,s,p,pt,x,div, a,b,c,e, o, curve,f
 Dim u,v,n
 Dim arrPoint
 Dim start, bFlip
 
 Dim arrstrSrf : arrstrSrf = Rhino.GetObjects (“Select a host surfs”,8)
 Dim StreamCrvs : StreamCrvs = Rhino.GetObjects (“Select Robot Paths”,4)
 Dim intU : intU = Rhino.GetReal(“U divisions”,64,1,120)
 Dim intV : intV = Rhino.GetReal(“V divisions”,48,1,240)
 Dim strSrf
 Dim strDelete : strDelete = “No”
 Dim oops,d2,closestpt
 Dim UDomain
 Dim VDomain
 Dim UStep
 Dim VStep
 Dim pts(), pts2()
 
 ReDim arrFrame(intU,intV)
 ReDim arrPts(intU,intV)
 Dim arrPt, Strokes()
 
 Dim pta,ptb,ptc,ptd,pte,ptf,ptg,pth,cnt,abc,d,NormalVect,line,line2, vect
 Dim MovinABC1(),MovinABC2(),curves()
 Dim WorldPlane, NorthVect, Angle, ZenithVect, AxisVect
 Dim Spandrel1, Spandrel2, IsoParms, MasterUDomain,fnA,stp, stp2, stp3
 Dim div2,div3,line3,r
 Dim PapaTrack(), TrackAss(),Trackcnt, BackTrack(),vectcnt, movpt, Scootvect, Trackparm, SideTrack()
 Dim pt0,pt1
 Dim newpts(),amypt, FlatMIdpt
 
 
 For p =0 To ubound (arrstrSrf) 
  Rhino.AddLayer “lines”&p
  Rhino.CurrentLayer “lines”&p
  Rhino.EnableRedraw (False)
  strSrf = arrstrSrf(p)
  IsoParms = Find_isocurves(StreamCrvs,strSrf)
  MasterUDomain = Rhino.SurfaceDomain(strSrf, 0)
  UDomain = Rhino.SurfaceDomain(strSrf, 0)
  VDomain = Rhino.SurfaceDomain(strSrf, 1)
  
  MasterUDomain(0)= MasterUDomain(0)+0.0001
  MasterUDomain(1)= MasterUDomain(1)-0.0001
  
  
  
  ‘MAke Track
   
   
   
  For a=0 To 2
   ReDim Preserve PapaTrack (a)
   ReDim Preserve TrackAss (a)
   PapaTrack(a)= Rhino.ExtractIsoCurve (strSrf,IsoParms(a),1)
   TrackAss(a) = Rhino.CurveStartPoint (PapaTrack(a)(0))
   Rhino.AddPoint TrackAss(a)
  Next
   
   
  Trackcnt = FindCenter(TrackAss)

  For a=0 To 2
   ReDim Preserve BackTrack(a)
   vectcnt = Rhino.VectorCreate (Trackcnt,TrackAss(a))
   vectcnt = Rhino.VectorUnitize (vectcnt)
   vectcnt = Rhino.VectorScale (vectcnt, 1.3)
   movpt = Rhino.PointAdd (TrackAss(a), vectcnt)
   BackTrack(a) = movpt
   ‘Rhino.ObjectColor BackTrack(a),10
   ‘BackTrack(a) = Rhino.MoveObject (BackTrack(a),TrackAss(a),movpt)
   e=0
   For b=0 To 2
    If a<>b Then
     For c=0 To 2
      If c<>a And c<>b Then
       ReDim Preserve SideTrack(e)
    
       Scootvect = Rhino.VectorCreate (TrackAss(b),TrackAss(c))
       Scootvect = Rhino.VectorUnitize (Scootvect)
       Scootvect = Rhino.VectorScale (Scootvect,1)
       
       movpt= Rhino.PointAdd (TrackAss(a),Scootvect)
      
       SideTrack(e) = movpt
       e=e+1
      End If
     Next
    End If
   Next
   Rhino.AddPoint SideTrack(0)
   ‘Rhino.AddPoint SideTrack(1)
   ‘Rhino.AddPoint BackTrack(a)
   
   vect= Rhino.VectorCreate (BackTrack(a),SideTrack(0))
   vect= Rhino.VectorScale (vect,0.5)
   
   pt0= Rhino.PointAdd (SideTrack(0),vect)
   
   vect= Rhino.VectorCreate (BackTrack(a),SideTrack(1))
   vect= Rhino.VectorScale (vect,0.5)
   pt1 = Rhino.PointAdd (SideTrack(1),vect)
   Rhino.AddPoint pt0
   
   vect= Rhino.VectorCreate (pt1,SideTrack(0))
   vect= Rhino.VectorScale (vect,0.7)
   pt1=Rhino.PointAdd (pt1,vect)
   vect= Rhino.VectorCreate (pt0,SideTrack(1))
   vect= Rhino.VectorScale (vect,0.7)
   pt0=Rhino.PointAdd (pt0,vect)
   Rhino.AddPoint pt0
   curve = Rhino.AddInterpCurve (array(SideTrack(0),pt0,BackTrack(a),pt1,SideTrack(1)))
   div = Rhino.DivideCurve(curve, 9)
   For o=0 To Ubound (div)
    Rhino.CopyObject PapaTrack(a)(0),TrackAss(a),div(o)
   Next
   
  Next
  
  Rhino.DeleteObjects array(PapaTrack(0)(0),PapaTrack(1)(0), PapaTrack(2)(0))
  
  
  
  
  
  
  
  
  
  
  For fnA=0 To 2
   If IsoParms(0)(0) >1 Then
    IsoParms(2)(0) = IsoParms(2)(0) -0.00001
    If fna=0 Then
     UDomain(0) = MasterUDomain(0)
     UDomain(1) = IsoParms(0)(0)
    End If
    If fna=1 Then
     UDomain(0) = IsoParms(0)(0)
     UDomain(1) = IsoParms(1)(0)
    End If
    If fna=2 Then
     UDomain(0) = IsoParms(1)(0)
     UDomain(1) = IsoParms(2)(0)
    End If
   Else
    If fna=0 Then
     UDomain(0) = MasterUDomain(0)
     UDomain(1) = IsoParms(1)(0)
    End If
    If fna=1 Then
     UDomain(0) = IsoParms(1)(0)
     UDomain(1) = IsoParms(2)(0)
    End If
    If fna=2 Then
     UDomain(0) = IsoParms(2)(0)
     UDomain(1) = MasterUDomain(1)
    End If
   End If
  
  
   UStep = (UDomain(1) – UDomain(0)) / intU
   VStep = (VDomain(1) – VDomain(0)) / intV
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

   For i = 0 To intU
    For j = 0 To intV
     u = UDomain(0) + UStep * i 
     v = VDomain(0) + VStep * j
     arrFrame(i,j) = Rhino.SurfaceFrame (strSrf, Array(U,V))
     ‘arrPt= Rhino.AddPoints (array(arrFrame(i,j)(0)))
    Next
   Next
  
   
   stp = 2’avinstep
   stp2 = 7’side
   stp3 = 2’vert
   start = 17
   ReDim pts (0)
   ReDim pts2 (0)
   For j=0 To intU    
    If j>1 And j Mod 32 = 0 Then
     For k = 0 To intV
      If k>1 And k Mod 16 = 0 Then
       If Ubound (pts)= 0 Then
        ReDim Preserve pts(2)
        pts(0) = arrFrame (j-16+stp,k-16)(0)
        pts(1) = arrFrame(j-stp,k-8)(0)
        pts(2) = arrFrame(j-16+stp,k)(0)
        ReDim Preserve pts2(2)
        pts2(0) = arrFrame (j-16-stp,k-16)(0)
        pts2(1) = arrFrame(j-32+stp,k-8)(0)
        pts2(2) = arrFrame(j-16-stp,k)(0)
        ‘Rhino.AddPoint arrFrame(j-4,k-2)(0)
        ‘Rhino.AddPoint arrFrame(j-8,k)(0)
        Spandrel1 = arrFrame(j-16,k-8)
       
        
        If j=32 Then
        
         line = Rhino.AddInterpCrvOnSrf (strSrf, array(arrFrame(j-16-stp2,k-16)(0), arrFrame(j-32+stp,k-8-stp3)(0)))
         
        End If 
       Else
        ReDim Preserve pts(Ubound (pts)+2)
        ReDim Preserve pts2(Ubound (pts2)+2)
        pts(Ubound (pts)-1) = arrFrame(j-stp,k-8)(0)
        pts(Ubound (pts)) = arrFrame(j-16+stp,k)(0)
        pts2(Ubound (pts2)-1) = arrFrame(j-32+stp,k-8)(0)
        pts2(Ubound (pts2)) = arrFrame(j-16-stp,k)(0)
        ‘Rhino.AddPoint arrFrame(j-4,k-2)(0)
        ‘Rhino.AddPoint arrFrame(j-8,k)(0)
        Spandrel1 = arrFrame(j-16,k-8)
        Spandrel2 = arrFrame(j-32,k-16)
        Rhino.AddPoint arrFrame(j-32,k-16)(0)
        
        
        
        If j=32 Then
        
         line = Rhino.AddInterpCrvOnSrf (strSrf, array(arrFrame(j-32+stp2,k-20)(0),arrFrame(j-16-stp2,k-16)(0), arrFrame(j-32+stp,k-8-stp3)(0)))
         line2 = Rhino.AddInterpCrvOnSrf (strSrf, array(arrFrame(j-32+stp2,k-18)(0), arrFrame(j-32+stp+1,k-8-stp3-1)(0)))
         div=Rhino.DivideCurve (line,10)
         div2 = Rhino.DivideCurve (line2,10)
         For o=0 To Ubound (div)
          Rhino.AddLine div(o),div2(o)
         Next
         Rhino.DeleteObjects array(line,line2)
        End If 
        
        If j= 64 Then
         line = Rhino.AddInterpCrvOnSrf (strSrf, array(arrFrame(j-stp2,k-12)(0),arrFrame(j-16+stp2,k-16)(0), arrFrame(j-stp2,k-24+stp3)(0)))
         line2 = Rhino.AddInterpCrvOnSrf (strSrf, array(arrFrame(j-stp2,k-14)(0), arrFrame(j-stp2-2,k-24+stp3+1)(0)))
         div=Rhino.DivideCurve (line,10)
         div2 = Rhino.DivideCurve (line2,10)
         For o=0 To Ubound (div)
          Rhino.AddLine div(o),div2(o)
         Next
         Rhino.DeleteObjects array(line,line2)
        End If
        ‘If k=16 Then
         
        ‘line = Rhino.AddInterpCrvOnSrf (strSrf, array(arrFrame(j-16+stp,k)(0), arrFrame(j-32,k-6)(0), arrFrame(j-stp,k)(0)))
        ‘ End If
        ‘If j=intU Then
        ‘ For s=0 To 2
        ‘  line = Rhino.AddInterpCrvOnSrf (strSrf, array(arrFrame(j,k-2)(0), arrFrame(j-s,k-4)(0)))
        ‘  line2 = Rhino.AddInterpCrvOnSrf (strSrf, array(arrFrame(j,k-6)(0), arrFrame(j-s,k-4)(0)))
        ‘ Next
        ‘ End If
        
        
        
       End If
       WorldPlane = Rhino.WorldXYPlane ()
       NorthVect = WorldPlane(2)
       NorthVect = Rhino.VectorUnitize (NorthVect)
      
      
      
       ‘—TEST SPANDREL 1—–
       NormalVect = Spandrel1(3)
       NormalVect = Rhino.VectorUnitize (NormalVect)
       Angle = VectorAngle(NormalVect,NorthVect)
       oops=0
       If Angle > 90 Then
        oops=random (-2,1)
       End If
       If k<start Then
        oops=oops+2
       End If
       If oops <= 0 Then
       
        cnt= Spandrel1(0)
        pta= arrFrame(j-16,k-stp3)(0)
        ptb= arrFrame(j-32+stp2,k-8)(0)
        ptc= arrFrame(j-16,k-16+stp3)(0)
        ptd = arrFrame(j-stp2,k-8)(0)
        d= Rhino.Distance (cnt, ptb)
      
        For q=0 To Ubound (arrstrSrf)
         If q<>p Then
          closestpt = Rhino.SurfaceClosestPoint (arrstrSrf(q), cnt)
          closestpt = Rhino.EvaluateSurface (arrstrSrf(q), closestpt)
          d2 = Rhino.Distance (cnt,closestpt)
          If d2<d*1.25 Then
           oops=oops+2
          End If
         End If
        Next
        If oops <= 0 Then
         For g=0 To Ubound (StreamCrvs)
          closestpt = rhino.CurveClosestPoint (StreamCrvs(g),cnt)
          closestpt = Rhino.EvaluateCurve (StreamCrvs(g), closestpt)
          d2= Rhino.Distance (cnt,closestpt)
          If d2<d/4 Then
           oops=oops+1
          End If
         Next
         If oops <= 0 Then
          Call MakeWindow (Spandrel1, array(pta,ptb,ptc,ptd,pta), strSrf)
         End If
        End If
       End If
      
       If oops > 0 Then
        pta= arrFrame(j-16-1,k-stp3)(0)
        ptb= arrFrame(j-32+stp2,k-8)(0)
        ptc= arrFrame(j-16-stp,k-16+stp3)(0)
        
        ptd = arrFrame(j-16+1,k-stp3)(0)
        pte = arrFrame(j-stp2,k-8)(0)
        ptf = arrFrame(j-16+stp,k-16+stp3)(0)
        
        ptg = arrFrame(j-16,k-16+stp3+1)(0)
        
        d= Rhino.Distance (pta,ptc)
        
        line = Rhino.AddInterpCrvOnSrf (strSrf, array(pta,ptb,ptc))
        line2 = Rhino.AddInterpCrvOnSrf (strSrf,array(pta,ptg))
        line3 = Rhino.AddInterpCrvOnSrf (strSrf, array(ptd,pte,ptf))
        
        
        div= Rhino.DivideCurve (line, 25)
        div2= Rhino.DivideCurve (line2, 25)
        div3 = Rhino.DivideCurve (line3,25)
        For r=0 To Ubound (div)
         Rhino.AddInterpCurve array(div(r),div2(r),div3(r))
        Next
        Rhino.DeleteObjects array(line,line2,line3)
       End If
     
       
       
       
       If j>32 And k>16 Then
        ‘—TEST SPANDREL 2—–
        NormalVect =  Spandrel2(3)
        NormalVect = Rhino.VectorUnitize (NormalVect)
        Angle = VectorAngle(NormalVect,NorthVect)
        oops= 0
        If Angle > 90 Then
         oops=random (-2,1)
        End If
        If k<start Then
         oops=oops+2
        End If
        If oops <= 0 Then
         cnt= Spandrel2(0)
         pta= arrFrame(j-32,k-8-stp3)(0)
         ptb= arrFrame(j-48+stp2,k-16)(0)
         ptc= arrFrame(j-32,k-24+stp3)(0)
         ptd = arrFrame(j-16-stp2,k-16)(0)
         
         d= Rhino.Distance (pta, cnt)
         For q=0 To Ubound (arrstrSrf)
          If q<>p Then
           closestpt = Rhino.SurfaceClosestPoint (arrstrSrf(q), cnt)
           closestpt = Rhino.EvaluateSurface (arrstrSrf(q), closestpt)
           d2 = Rhino.Distance (cnt,closestpt)
           If d2<d*1.25 Then
            oops=oops+2
           End If
          End If
         Next
         If oops <= 0  Then
          For g=0 To Ubound (StreamCrvs)
           closestpt = rhino.CurveClosestPoint (StreamCrvs(g),cnt)
           closestpt = Rhino.EvaluateCurve (StreamCrvs(g), closestpt)
           d2= Rhino.Distance (cnt,closestpt)
           If d2<d Then
            oops=oops+1
           End If
          Next
          If oops <= 0 Then
           Call MakeWindow (Spandrel2, array(pta,ptb,ptc,ptd,pta), strSrf)
          End If
         End If
        End If
        If oops >0 Then

         
         
         pta= arrFrame(j-32-1,k-8-stp3)(0)
         ptb= arrFrame(j-48+stp2,k-16)(0)
         ptc= arrFrame(j-32-1,k-24+stp3)(0)
        
         ptd = arrFrame(j-32+1,k-8-stp3)(0)
         pte = arrFrame(j-16-stp2,k-16)(0)
         ptf = arrFrame(j-32+stp,k-24+stp3)(0)
        
         ptg = arrFrame(j-32,k-24+stp3+1)(0)
        
         d= Rhino.Distance (pta,ptc)
        
         line = Rhino.AddInterpCrvOnSrf (strSrf, array(pta,ptb,ptc))
         line2 = Rhino.AddInterpCrvOnSrf (strSrf,array(pta,ptg))
         line3 = Rhino.AddInterpCrvOnSrf (strSrf, array(ptd,pte,ptf))
        
        
         div= Rhino.DivideCurve (line, 25)
         div2= Rhino.DivideCurve (line2, 25)
         div3 = Rhino.DivideCurve (line3,25)
         For r=0 To Ubound (div)
          Rhino.AddInterpCurve array(div(r),div2(r),div3(r))
         Next
         Rhino.DeleteObjects array(line,line2,line3)
         
         
         ‘line = Rhino.AddInterpCrvOnSrf (strSrf, array(arrFrame(j-15,k-12)(0), arrFrame(j-10,k-8)(0), arrFrame(j-15,k-4)(0)))
         ‘line2 = Rhino.AddInterpCrvOnSrf (strSrf, array(arrFrame(j-17,k-12)(0), arrFrame(j-22,k-8)(0), arrFrame(j-17,k-4)(0)))
        End If
       End If
     
      End If
     Next

   
     line = Rhino.AddInterpCrvOnSrf (strSrf, pts)
     ‘Rhino.AddInterpCurve pts
     ‘Rhino.AddInterpCurve pts2
     line2 = Rhino.AddInterpCrvOnSrf (strSrf, pts2)
     FlatMIdpt= Rhino.PointAdd (Trackcnt, array(Trackcnt(0),Trackcnt(1),-1*Trackcnt(2)))
     For f=0 To Ubound(pts)
      ReDim Preserve newpts(f)
      amypt = Rhino.PointAdd (pts(f),array(pts(f)(0),pts(f)(1),-1*pts(f)(2)))
      vect= Rhino.VectorCreate (FlatMIdpt,amypt)
      vect = Rhino.VectorUnitize (vect)
      vect = Rhino.VectorScale (vect, 2)
      newpts(f) = Rhino.PointAdd (pts(f),vect)
     Next
     Rhino.AddInterpCurve newpts
     For f=0 To Ubound(pts2)
      ReDim Preserve newpts(f)
      amypt = Rhino.PointAdd (pts2(f),array(pts2(f)(0),pts2(f)(1),-1*pts2(f)(2)))
      vect= Rhino.VectorCreate (FlatMIdpt,amypt)
      vect = Rhino.VectorUnitize (vect)
      vect = Rhino.VectorScale (vect, 2)
      newpts(f) = Rhino.PointAdd (pts2(f),vect)
     Next
     
     Rhino.AddInterpCurve newpts
     ReDim pts (0)
     ReDim pts2 (0)
    End If

   Next
  Next
  Rhino.EnableRedraw (True)
 Next
 
 
 If strDelete = “yes” Then
  Rhino.deleteobject strSrf
  Rhino.Print(“Surface deleted”)
 End If
 Rhino.Print(“Script completed”)
End Sub
Function MakeWindow (Spandrel, arrpts, strSrf)
 
 
 Dim arrcrvs(2),cnt,d,WorldPlane,NormalVect,NorthVect,i, vect, movpts1(),movpts2(), ZenithVect, srf, pt
 Dim j, line, mid, try, isopts, CrazyVect,Rand
 Rand = random (0.35,0.5)
 cnt = Spandrel(0)
 d= Rhino.Distance (arrpts(0),cnt)
 WorldPlane = Rhino.WorldXYPlane ()
 NormalVect = Spandrel(3)
 NormalVect = Rhino.VectorUnitize (NormalVect)
 NormalVect = Rhino.VectorScale (NormalVect, random(d*0.05,d*0.12))
 NorthVect = WorldPlane(2)
 NorthVect = Rhino.VectorUnitize (NorthVect)
 NorthVect = Rhino.VectorScale (NorthVect, d*0.05)
 CrazyVect = Spandrel(1) 
 CrazyVect = Rhino.VectorUnitize (CrazyVect)
 CrazyVect = Rhino.VectorScale (CrazyVect, random(-0.1*d,0.1*d))
 
 ZenithVect = WorldPlane (3)
 ZenithVect = Rhino.VectorUnitize (ZenithVect)
 ZenithVect = Rhino.VectorScale (ZenithVect, random(d*0.2,d*0.25))
 
 arrcrvs (0) = Rhino.AddInterpCrvOnSrf (strSrf,arrpts)
 
 For i=0 To Ubound (arrpts)
  ReDim Preserve movpts1(i)
  ReDim Preserve movpts2(i)
  vect = Rhino.VectorCreate (cnt,arrpts(i))
  vect = Rhino.VectorScale (vect, Rand)
  movpts1(i) = Rhino.PointAdd (arrpts(i), vect)
  movpts2(i) = Rhino.PointAdd (movpts1(i), NormalVect)
  
 
  movpts2(i) = Rhino.PointAdd (movpts2(i), NorthVect)
  movpts2(i) = Rhino.PointAdd (movpts2(i), ZenithVect)
  movpts2(i) = Rhino.PointAdd (movpts2(i), NormalVect)
  movpts2(i) = Rhino.PointAdd (movpts2(i), CrazyVect)
 Next
 arrcrvs(1) = Rhino.AddInterpCurve (movpts1)
 arrcrvs(2) = Rhino.AddInterpCurve (movpts2)
 try =Rhino.RebuildCurve (arrcrvs(2),3,4)
 srf = Rhino.AddLoftSrf (arrcrvs,,,1)
 ‘try = Rhino.RebuildSurface  (srf(0),array(3,3),array(4,3))
 
 isopts = Rhino.DivideCurve (arrcrvs(0),30)
 For j=0 To Ubound (isopts)
  pt = Rhino.SurfaceClosestPoint (srf(0), isopts(j))
  Rhino.ExtractIsoCurve srf(0) , pt, 0
 Next
 

 Rhino.DeleteObjects arrcrvs
 Rhino.DeleteObject srf(0)
 
 
 
End Function

Function Find_isocurves (arrPaths,srf)

 Dim endpt,check, parms(), OrderedParms(),max,min
 Dim b,n,i
 

 n=0
 For b=0 To Ubound (arrPaths)
  endpt = Rhino.CurveEndPoint (arrPaths(b))
  check = Rhino.IsPointOnSurface (srf,endpt)
  If check = True Then
   ReDim Preserve parms (n)
   parms(n) = Rhino.SurfaceClosestPoint (srf, endpt)
   n=n+1
  End If
 Next
  
 
 max = Rhino.Max (array(parms(0)(0),parms(1)(0),parms(2)(0)))
 min = Rhino.Min (array(parms(0)(0),parms(1)(0),parms(2)(0)))
  
 ReDim OrderedParms (2)
 If parms(0)(0)=min Then
  OrderedParms(0) = parms(0)
 End If
 If parms(1)(0)=min Then
  OrderedParms(0) = parms(1)
 End If
 If parms(2)(0)=min Then
  OrderedParms(0) = parms(2)
 End If
 If parms(0)(0)=max Then
  OrderedParms(2) = parms(0)
 End If
 If parms(1)(0)=max Then
  OrderedParms(2) = parms(1)
 End If
 If parms(2)(0)=max Then
  OrderedParms(2) = parms(2)
 End If
 If parms(0)(0)<>min And parms(0)(0) <>max Then
  OrderedParms(1) = parms(0)
 End If
 If parms(1)(0)<>min And parms(1)(0) <>max Then
  OrderedParms(1) = parms(1)
 End If
 If parms(2)(0)<>min And parms(2)(0) <>max Then
  OrderedParms(1) = parms(2)
 End If
  
 ‘For i=0 To Ubound (OrderedParms)
 ‘Rhino.ExtractIsoCurve srf,OrderedParms(i),1
 ‘Next

 Find_isocurves = OrderedParms
 
 
End Function
Function FindCenter (arrpts)

 Dim i, Objpts(), arrBBox, arrCntrPt, j
 
 
 For i=0 To Ubound(arrpts)
  If IsNull (arrpts(i)) Then
   FindCenter = Null
   Exit Function
  End If
  ReDim Preserve Objpts(i)
  Objpts(i)= Rhino.AddPoint (arrpts(i))
 Next
 
 
 
 
 arrBBox = Rhino.BoundingBox(Objpts)
 arrCntrPt = array((((arrBBox(2)(0)) + (arrBBox(0)(0))) / 2), (((arrBBox(2)(1)) + (arrBBox(0)(1))) / 2), (((arrBBox(0)(2)) + (arrBBox(4)(2))) / 2))
 
 FindCenter = arrCntrPt
 
 For j = 0 To Ubound(objpts)
  Rhino.DeleteObject objpts(j)
 Next
 
End Function
Function VectorAngle(v0, v1)
 Dim u0  : u0  = Rhino.VectorUnitize(v0)
 Dim u1  : u1  = Rhino.VectorUnitize(v1) 
 Dim dot : dot = Rhino.VectorDotProduct(u0, u1)
 ‘ Force the dot product of the two input vectors to
 ‘ fall within the domain for inverse cosine, which
 ‘ is -1 <= x <= 1. This will prevent runtime
 ‘ “domain error” math exceptions.
 If (dot < -1.0) Then
  dot = -1.0
 ElseIf (dot > 1.0) Then
  dot = 1.0
 End If
 VectorAngle = Rhino.ToDegrees(Rhino.ACos(dot))
End Function

 

Function random(min,max)
 Randomize
 random = (max-min) * Rnd + min
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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s