Rh3_Pau: "Rnd recess onto slab"
![](http://photos1.blogger.com/blogger/1896/1964/400/005.jpg)
![](http://photos1.blogger.com/blogger/1896/1964/400/004.jpg)
Option Explicit
'------------------------------------------------------------------------------
' Marc Fornes /// theverymany
' Subroutine: fromSurface
' 050611: Creates form a surface an array of normals & Circles from different diameters.
'------------------------------------------------------------------------------
Sub fromSurface()
Dim strObjects
Dim strObject, nLONGITUDE, nTRANSVERSAL
Dim U, V, i, j, arrParam(1)
Dim arrParamNormal, arrNormal', Normal_Line
Dim intDeltaHeight, intHeight_h02, intHeight_h03, intHeight_h04
Dim dblRadius
Dim intPercentage_Rnd
Dim h: h = 0
' ---------------------------------------------------------------------------------
' [ Get SURFACE object ]
strObjects = Rhino.GetObjects("Select surface", 8)
If IsNull(strObject) Then Exit Sub
' [ PROPERTY LIST BOX ]
' set variables
Dim arrParameters, arrResults, arrValues
' set paramters names
arrParameters = array("i: rows/sections (>1)", "j: columns/isoParms (>1)", "NORMAL: _height (<>0 & >_h03)",_
"CIRCLES: _radius", "CIRCLES: _%Rnd", "CIRCLES: _h02", "CIRCLES: _h03", "CIRCLES: _h04")
' set default values
arrValues = array("6", "6", "0.5", "0.28", "60", "0.05", "0.12", "0.15")
' create "Property list box"
arrResults = Rhino.PropertyListBox(arrParameters, arrValues, "Parameters", "/////////ZOOYORK/////////" )
If IsArray(arrResults) Then
' NUMBER of rows/sections:
nLONGITUDE = FormatNumber(arrResults(0))
If IsNull(nLONGITUDE) Then Exit Sub
nLONGITUDE = nLONGITUDE - 1
' NUMBER of columns:
nTRANSVERSAL = FormatNumber(arrResults(1))
If IsNull(nTRANSVERSAL) Then Exit Sub
nTRANSVERSAL = nTRANSVERSAL - 1
' NORMAL: _height
intDeltaHeight = FormatNumber(arrResults(2))
If IsNull(intDeltaHeight) Then Exit Sub
intDeltaHeight = intDeltaHeight - 1
' CIRCLE: _diameter
dblRadius = FormatNumber(arrResults(3))
If IsNull(dblRadius) Then Exit Sub
dblRadius = dblRadius '- 1
' CIRCLE: _%Rnd
intPercentage_Rnd = FormatNumber(arrResults(4))
If IsNull(intPercentage_Rnd) Then Exit Sub
intPercentage_Rnd = intPercentage_Rnd - 1
' NORMAL: _height_h02
intHeight_h02 = FormatNumber(arrResults(5))
If IsNull(intHeight_h02) Then Exit Sub
intHeight_h02 = intHeight_h02 - 1
' NORMAL: _height_h03
intHeight_h03 = FormatNumber(arrResults(6))
If IsNull(intHeight_h03) Then Exit Sub
intHeight_h03 = intHeight_h03 - 1
' NORMAL: _height_h04
intHeight_h04 = FormatNumber(arrResults(7))
If IsNull(intHeight_h04) Then Exit Sub
intHeight_h04 = intHeight_h04 - 1
End If
' ---------------------------------------------------------------------------------
' ---------------------------------------------------------------------------------
For Each strObject In strObjects
' ---------------------------------------------------------------------------------
' GET DOMAIN OF SURFACE
U = Rhino.SurfaceDomain(strObject, 0)
V = Rhino.SurfaceDomain(strObject, 1)
If Not IsArray(U) Or Not IsArray(V) Then Exit Sub
' ---------------------------------------------------------------------------------
' FOR each rows/sections:
' ---------------------------------------------------------------------------------
For i = 0 To nLONGITUDE
arrParam(0) = U(0) + (((U(1) - U(0)) / nLONGITUDE) * i)
' --------------------------------------------------------------------------------
' FOR each columns/isoParms
' ---------------------------------------------------------------------------------
For j = 0 To nTRANSVERSAL
arrParam(1) = V(0) + (((V(1) - V(0)) / nTRANSVERSAL) * j)
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' [ GRID POINT ON SURFACE ]
ReDim Preserve arrPt_onSurf(nLONGITUDE,nTRANSVERSAL)
arrPt_onSurf(i,j) = Rhino.EvaluateSurface(strObject, arrParam)
'Rhino.AddPoint arrPt_onSurf(i,j)
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' [ ADD NORMAL ]
' (arrNormal(0) Is point On surf & arrNromal(1) Is End of Normal)
arrNormal = Rhino.SurfaceNormal(strObject, arrParam)
' Normal End Pt: FUNCTION: translate along arrNormal_VECTOR and multiply by factor
ReDim Preserve arrNormal_ScaledEndPt(nLONGITUDE,nTRANSVERSAL)
arrNormal_ScaledEndPt(i,j) = FUNCT_Normal_Height_Scale(arrNormal, intDeltaHeight)
' Normal addLine
ReDim Preserve Normal_Line(nLONGITUDE,nTRANSVERSAL)
'Normal_Line(i,j) = Rhino.addLine (arrNormal(0), arrNormal_ScaledEndPt(i,j))
'Rhino.objectColor Normal_Line(i,j), RGB(255, 0, 255)
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' ---------------------------------------------------------------------------------
' [ RANDOM ]
' set: random number
Dim randomFactor: randomFactor = Rnd
' if: not on any border and: random number > random number input
If i>0 And i
' [ ADD CIRCLES ] [ original ]
ReDim Preserve arrCircle(nLONGITUDE,nTRANSVERSAL)
arrCircle(i,j) = Rhino.AddCircle ( arrPt_onSurf(i,j), (dblRadius*randomFactor), arrNormal_ScaledEndPt(i,j) )
'Rhino.objectColor arrCircle(i,j), RGB((randomFactor*255), 0, (randomFactor*255))
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' { get circle starting point }
'ReDim Preserve arrCircle_startPoint(nLONGITUDE,nTRANSVERSAL)
'arrCircle_startPoint(i,j) = Rhino.CurveStartPoint(arrCircle(i,j))
'Rhino.AddPoint arrCircle_startPoint(i,j)
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' [ ADD CIRCLES ] [ _h02 ]
' set origine next circle along normal
ReDim Preserve arrNormal_ScaledEndPt_h02(nLONGITUDE,nTRANSVERSAL)
arrNormal_ScaledEndPt_h02(i,j) = FUNCT_Normal_Height_Scale(arrNormal, intHeight_h02)
' next circle
ReDim Preserve arrCircle_h02(nLONGITUDE,nTRANSVERSAL)
arrCircle_h02(i,j) = Rhino.AddCircle ( arrNormal_ScaledEndPt_h02(i,j), ((dblRadius*randomFactor)-0.05), arrNormal_ScaledEndPt(i,j) )
'Rhino.objectColor arrCircle_h02(i,j), RGB((randomFactor*200), 0, (randomFactor*200))
' [ ADD CIRCLES ] [ _h03 ]
' set origine next circle along normal
ReDim Preserve arrNormal_ScaledEndPt_h03(nLONGITUDE,nTRANSVERSAL)
arrNormal_ScaledEndPt_h03(i,j) = FUNCT_Normal_Height_Scale(arrNormal, intHeight_h03)
' next circle
ReDim Preserve arrCircle_h03(nLONGITUDE,nTRANSVERSAL)
arrCircle_h03(i,j) = Rhino.AddCircle ( arrNormal_ScaledEndPt_h03(i,j), ((dblRadius*randomFactor)-0.05), arrNormal_ScaledEndPt(i,j) )
'Rhino.objectColor arrCircle_h03(i,j), RGB((randomFactor*150), 0, (randomFactor*150))
' [ ADD CIRCLES ] [ _h04 ]
' set origine next circle along normal
ReDim Preserve arrNormal_ScaledEndPt_h04(nLONGITUDE,nTRANSVERSAL)
arrNormal_ScaledEndPt_h04(i,j) = FUNCT_Normal_Height_Scale(arrNormal, intHeight_h04)
' next circle
ReDim arrCircle_h04_toBeArrayOneDimension(0):
arrCircle_h04_toBeArrayOneDimension(0) = Rhino.AddCircle (arrNormal_ScaledEndPt_h04(i,j), ((dblRadius*randomFactor)-0.1), arrNormal_ScaledEndPt(i,j) )
ReDim Preserve arrCircle_h04(nLONGITUDE,nTRANSVERSAL)
'arrCircle_h04(i,j) = Rhino.AddCircle ( arrNormal_ScaledEndPt_h04(i,j), ((dblRadius*randomFactor)-0.1), arrNormal_ScaledEndPt(i,j) )
arrCircle_h04(i,j) = arrCircle_h04_toBeArrayOneDimension(0)
'Rhino.objectColor arrCircle_h04(i,j), RGB((randomFactor*150), 0, (randomFactor*150))
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' [ ADD LOFT ]
ReDim Preserve arrLoft(nLONGITUDE,nTRANSVERSAL)
arrLoft(i,j) = Rhino.AddLoftSrf ( array(arrCircle(i,j), arrCircle_h02(i,j), arrCircle_h03(i,j), arrCircle_h04(i,j)), , ,2,1,10, False)
Rhino.SurfaceIsocurveDensity arrLoft(i,j), -1
'Rhino.objectColor arrLoft(i,j), RGB(0, 0, 0)
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' [ ADD CAP ] { planar surf }
ReDim Preserve arrCap(nLONGITUDE,nTRANSVERSAL)
arrCap(i,j) = Rhino.AddPlanarSrf (arrCircle_h04_toBeArrayOneDimension)
Rhino.SurfaceIsocurveDensity arrCap(i,j), -1
'Rhino.objectColor arrCap(i,j), RGB(0, 0, 0)
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' delete cirlces
Rhino.deleteObjects array(arrCircle(i,j), arrCircle_h02(i,j), arrCircle_h03(i,j), arrCircle_h04(i,j))
Rhino.deleteObjects arrCircle_h04_toBeArrayOneDimension
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
End If
' ---------------------------------------------------------------------------------
' ---------------------------------------------------------------------------------
Next
' ---------------------------------------------------------------------------------
' ---------------------------------------------------------------------------------
Next
' ---------------------------------------------------------------------------------
h = h + 1
' ---------------------------------------------------------------------------------
Next
' ---------------------------------------------------------------------------------
' ---------------------------------------------------------------------------------
' ---------------------------------------------------------------------------------
End Sub
fromSurface
Function FUNCT_Normal_Height_Scale (point_A, factor)
' Normal as Vector
Dim VECTOR
VECTOR = array( (point_A(1)(0))-(point_A(0)(0)), _
(point_A(1)(1))-(point_A(0)(1)), _
(point_A(1)(2))-(point_A(0)(2)) )
' Normal End Pt: translate along arrNormal_VECTOR and multiply by factor
' = origine point + ( NormalVector * height)
FUNCT_Normal_Height_Scale = array( (point_A(1)(0))+(VECTOR(0)*factor), _
(point_A(1)(1))+(VECTOR(1)*factor), _
(point_A(1)(2))+(VECTOR(2)*factor) )
End Function
Function FUNCT_Height_Scale (point_A, point_B, factor)
FUNCT_Height_Scale = array( (point_A(0))+(point_B(0)*factor), _
(point_A(1))+(point_B(1)*factor), _
(point_A(2))+(point_B(2)*factor) )
End Function
<< Home