(n)certainties – Columbia – Fall 2007

070926_M.Bearak_MainStructureGeneration

robot :: perception

Man + Machine + well, another machine…

robotperception.jpg

Option Explicit
‘Script written by <mark bearak>
‘Script copyrighted by <dtls.architecture>
‘Script version Monday, September 24, 2007 11:41:45 AM

Call Main()

Sub Main()
Dim k,l
Dim u,v
Dim arrPoint
Dim arrContextPts()

Dim arrSrf : arrSrf = Rhino.GetObject (”Select a host surf”)

Dim intU : intU = 100
Dim intV : intV = 20

Dim UDomain : UDomain = Rhino.SurfaceDomain(arrSrf, 0)
Dim VDomain : VDomain = Rhino.SurfaceDomain(arrSrf, 1)

Dim UStep : UStep = (UDomain(1) – UDomain(0)) / intU
Dim VStep : VStep = (VDomain(1) – VDomain(0)) / intV

ReDim arrFrame(intU,intV)
ReDim arrPts(intU,intV)

Dim strPoly, strCrv, strCrv2, arrPtNormal
Dim m : m = 0
For k = 0 To intU-1
For l = 0 To intV
ReDim Preserve arrContextPts(m)
u = UDomain(0) + UStep * k
v = VDomain(0) + vStep * l
arrFrame(k,l) = Rhino.SurfaceFrame (arrSrf, array(U,V))
arrContextPts(m) = Rhino.AddPoints (array(arrFrame(k,l)(0)))
m = m+1
Next
Next

Dim i, j
Dim IntUpper : IntUpper = 100
Dim n: n=0
Dim arrMajorPointa()
Dim arrMajorPointb()
Dim arrMajorPointc()
Dim arrCenterPoint()
Dim arrMajorCross()
Dim arrMinorPointa(),arrMinorPointb(),arrMinorPointc(),arrMinorPointd()
Dim strLine
Dim strIntLinea(), strIntLineb(), strIntLinec(), strIntLined()
Dim strMajorLine()
Dim strPt
Dim arrpt
For i = 0 To IntUpper
ReDim Preserve arrMajorPointa(IntUpper)
ReDim Preserve arrMajorPointb(IntUpper)
ReDim Preserve arrMajorPointc(IntUpper)
ReDim Preserve arrCenterPoint(IntUpper)
ReDim Preserve arrMajorCross(IntUpper)
ReDim Preserve arrMinorPointa(IntUpper)
ReDim Preserve arrMinorPointb(IntUpper)
ReDim Preserve arrMinorPointc(IntUpper)
ReDim Preserve arrMinorPointd(IntUpper)
Dim dblSin : dblSin = (Sin(i/4)*3)
arrMajorPointa(i) = Rhino.PointCoordinates (Rhino.AddPoint (array(i,dblSin+(sin(i))/4,(sin(i))/4+1)))
arrMajorPointb(i) = Rhino.PointCoordinates (Rhino.AddPoint (array(i,dblSin+(sin(i))/4+.5,0)))
arrMajorPointc(i) = Rhino.PointCoordinates (Rhino.AddPoint (array(i,dblSin+(((sin(i))/4)*-1)-.5,0)))
arrMajorCross(i) = Rhino.AddInterpCurve (array(arrMajorPointa(i),arrMajorPointb(i),arrMajorPointc(i),arrMajorPointa(i)))
strPt = Rhino.CurveAreaCentroid(arrMajorCross(i))
arrPt = Rhino.PointCoordinates(Rhino.AddPoint(strPt(0)))
arrMinorPointa(i) = Rhino.PointCoordinates (Rhino.AddPoint (array(arrPt(0), arrPt(1) + (sin(i)*-1), arrPt(2) + (cos(i)*2))))
arrMinorPointb(i) = Rhino.PointCoordinates (Rhino.AddPoint (array(arrPt(0), arrPt(1) + (sin(i)*-1), arrPt(2) + (cos(i)*-2))))
arrMinorPointc(i) = Rhino.PointCoordinates (Rhino.AddPoint (array(arrPt(0), arrPt(1) + sin(i), arrPt(2) + (cos(i)*-2))))
arrMinorPointd(i) = Rhino.PointCoordinates (Rhino.AddPoint (array(arrPt(0), arrPt(1) + sin(i), arrPt(2) + (cos(i)*2))))
If (Rhino.Distance(arrPt,arrMinorPointa(i)))<= 1.75 Then
ReDim Preserve strIntLinea(n), strIntLineb(n), strIntLinec(n), strIntLined(n)
ReDim Preserve strMajorLine(n)
strIntLinea(n) = Rhino.AddLine (arrPt,arrMinorPointa(i))
strIntLineb(n) = Rhino.AddLine (arrPt,arrMinorPointb(i))
strIntLinec(n) = Rhino.AddLine (arrPt,arrMinorPointc(i))
strIntLined(n) = Rhino.AddLine (arrPt,arrMinorPointd(i))
strMajorLine(n) = arrMajorCross(i)
n= n+1
‘Dim arrNearest : arrNearest = NearestNeighbor (arrContextPts,arrMinorPointa(i))
‘Call Rhino.Print(arrNearest)
‘Call Rhino.AddLine (arrMinorPointa(i),arrNearest)
End If

Next
Rhino.AddLoftSrf (arrMajorCross)
Call Rhino.AddInterpCurve (arrMajorPointa)
Call Rhino.AddInterpCurve (arrMajorPointb)
Call Rhino.AddInterpCurve (arrMajorPointc)
Call Rhino.AddInterpCurve (arrMinorPointa)
Call Rhino.AddInterpCurve (arrMinorPointb)
Call Rhino.AddInterpCurve (arrMinorPointc)
Call Rhino.AddInterpCurve (arrMinorPointd)
Rhino.Command (”selsrf “)
Dim arrSurface: arrSurface =Rhino.GetObject(, , vbTrue)
For j = 0 To UBound(strIntLinea)
Dim arrIntPta: arrIntPta = CCX(strIntLinea(j), strMajorLine(j))
Call Rhino.AddPoint (arrIntPta)
Dim strCrsLinea : strCrsLinea = Rhino.AddLine (arrIntPta, Rhino.CurveEndPoint(strIntLinea(j)))
Call Rhino.DeleteObject (strIntLinea(j))
Call Rhino.AddCylinder (Rhino.CurveStartPoint(strCrsLinea), Rhino.CurveEndPoint(strCrsLinea),(Rhino.Distance(Rhino.CurveStartPoint(strCrsLinea), Rhino.CurveEndPoint(strCrsLinea)))/30)
Next
For j = 0 To UBound(strIntLineb)
Dim arrIntPtb: arrIntPtb = CCX(strIntLineb(j), strMajorLine(j))
Call Rhino.AddPoint (arrIntPtb)
Dim strCrsLineb : strCrsLineb = Rhino.AddLine (arrIntPtb, Rhino.CurveEndPoint(strIntLineb(j)))
Call Rhino.DeleteObject (strIntLineb(j))
Call Rhino.AddCylinder (Rhino.CurveStartPoint(strCrsLineb), Rhino.CurveEndPoint(strCrsLineb),(Rhino.Distance(Rhino.CurveStartPoint(strCrsLineb), Rhino.CurveEndPoint(strCrsLineb)))/30)
Next
For j = 0 To UBound(strIntLinec)
Dim arrIntPtc: arrIntPtc = CCX(strIntLinec(j), strMajorLine(j))
Call Rhino.AddPoint (arrIntPtc)
Dim strCrsLinec : strCrsLinec = Rhino.AddLine (arrIntPtc, Rhino.CurveEndPoint(strIntLinec(j)))
Call Rhino.DeleteObject (strIntLinec(j))
Call Rhino.AddCylinder (Rhino.CurveStartPoint(strCrsLinec), Rhino.CurveEndPoint(strCrsLinec),(Rhino.Distance(Rhino.CurveStartPoint(strCrsLinec), Rhino.CurveEndPoint(strCrsLinec)))/30)
Next
For j = 0 To UBound(strIntLined)
Dim arrIntPtd: arrIntPtd = CCX(strIntLined(j), strMajorLine(j))
Call Rhino.AddPoint (arrIntPtd)
Dim strCrsLined : strCrsLined = Rhino.AddLine (arrIntPtd, Rhino.CurveEndPoint(strIntLined(j)))
Call Rhino.DeleteObject (strIntLined(j))
Call Rhino.AddCylinder (Rhino.CurveStartPoint(strCrsLined), Rhino.CurveEndPoint(strCrsLined),(Rhino.Distance(Rhino.CurveStartPoint(strCrsLined), Rhino.CurveEndPoint(strCrsLined)))/30)
Next
End Sub

Function CCX(strCurve, strSurface)
Dim arrCCX
If IsNull(strCurve) Or Rhino.IsCurve(strCurve) = False Then Exit Function
If IsNull(strSurface) Or Rhino.IsCurve(strSurface) = False Then Exit Function
arrCCX = Rhino.CurveCurveIntersection(strCurve, strSurface)
If Not IsArray(arrCCX) Then
Rhino.Print “Curve and curve do not intersect.”
Exit Function
End If
Dim i
For i = 0 To UBound(arrCCX)
If arrCCX(i,0) = 1 Then
Rhino.Print “Intersection point on curve: ” & Rhino.Pt2Str(arrCCX(i,1))
CCX = arrCCX(i,1)
End If
Next
End Function

Function NearestNeighbor(arrPts,index)
Dim n, dblDist
Dim dblDistMin : dblDistMin = 1000000
For n = 0 To UBound(arrPts)
dblDist = Rhino.Distance (index,arrPts(n))
If dblDist <> 0 And dblDist < dblDistMin Then
dblDistMin = dblDist
Dim arrPtNear : arrPtNear = arrPts(n)
End If
Next
NearestNeighbor = arrPtNear
End Function

Leave a Comment

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment