(n)certainties

GSAPP- Fall 2010

(n)certainties header image 3

Code Fahrenheit 122

Option Explicit
Call Main()
Sub Main()
Dim arrAttractorsCrvs : arrAttractorsCrvs = Rhino.GetObjects("pls select the attractors",4)
Dim arrShadowPolySrfs : arrShadowPolySrfs = Rhino.GetObjects("pls select the buildings and the shadow volumes",16)
Dim arrOrigin : arrOrigin = Rhino.GetPoint("clikc on the origin for the environment grid")

Call CheckAttractorNamesForHotness(arrAttractorsCrvs)

Dim i

ReDim arrAttractors(Ubound(arrAttractorsCrvs)) 'dimarei ton arrAttractors wste na exei oses theseis exei o arrAttractorsCrvs

'gia na min allaksoume to proigoumeno script opou oi attactors itan epilegmenoi apo tio xristi, tautizoume ton arrAttractors me ton arrAttractorsCrvs
For i = 0 To Ubound(arrAttractors)
arrAttractors(i) = Rhino.AddPoint(Rhino.CurveStartPoint(arrAttractorsCrvs(i)))
'ston pinaka arrAttractors apouhkeuei simeia pou ta briskei mesw tou prwtou simeiou
'tis kamulis pou exei paothikeusei stin metabliti arrAttrCrvs
Call Rhino.ObjectName(arrAttractors(i),Rhino.ObjectName(arrAttractorsCrvs(i)))
'kalei tin object name gia na onomatisei ta
'simeia pou molis ebale ston arrAttractors. ta baftizei me To idio onoma mou baftizei ta simeia tis kamulis
Next

Dim arrAlloyPolyLines : arrAlloyPolyLines = Rhino.GetObjects("select the alloy polylines",4)
Dim strAlloyPolyLine

'ta test points--->diladi ayta pou tha kinithoun
'Dim arrMyStrPoints : arrMyStrPoints = Rhino.GetObjects("pls select my points",1)
Dim arrMyPoints
'arrMyPoints = PointCoordinatesOfArray(arrMyStrPoints) 'edw kalei mia function gia na dwsei coordi
Dim dblRadious : dblRadious = rhino.GetReal("please type the radious of vision for each point",5)
Dim intGenerations : intGenerations = rhino.GetInteger("please type the ammount of times to move",5)
Dim dblStep : dblStep = rhino.GetReal("please type the step",2)
Dim dblThres : dblThres = Rhino.GetReal("please type the freezing threshold",.001)
'Dim arrData : arrData = CreateEnviromentGrid(arrOrigin, 7, 25, 20, 2, arrAttractors, True) 'kalei mia function, tin environment grid kai tis dinei times,,,, false an den thelw na ginetai draw o grid

Dim arrData : arrData = CreateEnviromentGridWithShadows(arrOrigin, 7, 14, 14, 1, arrAttractors, True, arrShadowPolySrfs) 'kalei mia function, tin environment grid kai tis dinei times,,,, false an den thelw na ginetai draw o grid

Dim j,k,e,f,g

For k=0 To intGenerations-1
f = 0
Rhino.EnableRedraw(False)
For Each strAlloyPolyLine In arrAlloyPolyLines

arrMyPoints = Rhino.CurvePoints(strAlloyPolyLine)

For e=0 To Ubound(arrAttractors)
Dim arrNewPos : arrNewPos = Rhino.DivideCurve(arrAttractorsCrvs(e),intGenerations) (k)
'topothetei tous attractors sti nea tous thesi i opoia anikei sto epomeno divvison tis kamopulis twn thermokrasiwn
Call Rhino.MoveObject(arrAttractors(e),Rhino.PointCoordinates(arrAttractors(e)),arrNewPos)
'metakinei tous attractos apo tin proigoumeni thesi tous (point coordinates) stin epomeni thesi tis kampulis
Next

'arrData = UpdateEnviromentGrid(arrOrigin, arrData, arrAttractors)

arrData = UpdateEnviromentGridWithShadows(arrOrigin, arrData, arrAttractors, arrShadowPolySrfs, f+1)

For i=0 To Ubound(arrMyPoints)
ReDim arrCloseEnoughPtsOfGrid(-1)
For j = 0 To Ubound(arrData(0))
Dim dblDistance : dblDistance = Rhino.Distance(arrMyPoints(i), arrData(0)(j)) 'apostasi twn simeiwn tou kanabou apo ta simeia test
If dblDistance < dblRadious Then 'an i apostasi einai mikroteri apo to radious pou blepoyn ta simeia mou tote---ra einai entos tis aktinas twn points mou ReDim Preserve arrCloseEnoughPtsOfGrid(Ubound(arrCloseEnoughPtsOfGrid)+1) 'ftiaxnei enan pinaka me ta kontuna simeia tou kanabou moy, alla leei preserve gia na mi xathoun oi suntetagmenes twn simeiwn aytwn arrCloseEnoughPtsOfGrid(Ubound(arrCloseEnoughPtsOfGrid)) = j End If Next Dim Hot : Hot = - 1 Dim hotestClosest For j = 0 To Ubound(arrCloseEnoughPtsOfGrid) If arrData(1)(arrCloseEnoughPtsOfGrid(j)) > Hot Then 'kathe fora elegxei an i timi tis thermakrasias twn kontunoterwn simeiwn einai megalyteri apo mia timi arxika orismeni ws -1. i timi ayti ginetai sunexws update kai lammbavnei tin timi toi ekastote simeioyu pros elegxo
Hot = arrData(1)(arrCloseEnoughPtsOfGrid(j))
hotestClosest = arrCloseEnoughPtsOfGrid(j)
End If
Next

ReDim arrClosestPts(-1)

For g=0 To Ubound(arrAlloyPolyLines)
If Not g = f Then
Dim dblParamCl : dblParamCl = Rhino.CurveClosestPoint(arrAlloyPolyLines(g),arrMyPoints(i))
ReDim Preserve arrClosestPts(Ubound(arrClosestPts)+1)
arrClosestPts(Ubound(arrClosestPts)) = Rhino.EvaluateCurve(arrAlloyPolyLines(g),dblParamCL)
End If
Next

Dim arrTHEClosestPt : arrTHEClosestPt = arrClosestPts(Rhino.PointArrayClosestPoint(arrClosestPts,arrMyPoints(i)))

Dim dblDistanceToClosestPt : dblDistanceToClosestPt = Rhino.Distance(arrMyPoints(i), arrTHEClosestPt)

If dblDistanceToClosestPt > dblThres Then
'Call Rhino.AddLine(arrMyPoints(i), arrData(0)(hotestClosest))
Dim vec : vec = Rhino.VectorCreate(arrData(0)(hotestClosest), arrMyPoints(i))

'Dim dblDistanceToHotest : dblDistanceToHotest = Rhino.VectorLength(vec)
Dim dblTemperatureOfHotest : dblTemperatureOfHotest = arrData(1)(hotestClosest)

vec = Rhino.VectorUnitize(vec)
vec = Rhino.VectorScale(vec, dblStep*dblTemperatureOfHotest)

Dim arrNewPt : arrNewPt = Rhino.PointAdd(arrMyPoints(i), vec)

'Call Rhino.AddLine(arrMyPoints(i),arrNewPt)
arrMyPoints(i) = arrNewPt

End If
Next
Call Rhino.DeleteObject(strAlloyPolyLine)
arrAlloyPolyLines(f) = Rhino.AddCurve(arrMyPoints)
f = f + 1
Next
Rhino.EnableRedraw(True)
dblThres = dblThres + .1
Next
'Call Rhino.AddPointCloud(arrMyPoints)
End Sub

Function CreateEnviromentGrid(arrOrigin, intHowManyInX, intHowManyInY, intHowManyInZ, dblStep, arrHotAttractors, blnDraw)
' this function sets up a grid of points and tempratures from "hot" attractors takes as inputs:

' intHowManyinX (for how many Points)
' intHowManyinY (for how many Points)
' intHowManyinZ (for how many Points)
' dblStep for the step of the grid
' arrHotAttractors is the ids of the points as attractors
' blnDraw = True if you want to draw the grid points in the screen

' it returns an array with two main slots/positions:
' slot/position (0) has all the points (x,y,z)
' slot/position (1) has all the temperatures

CreateEnviromentGrid = Null
Call Rhino.EnableRedraw(vbFalse)
ReDim arrEnvironmentPos(-1)
ReDim arrEnvironmentTemp(-1)
Dim i,j,k, e
For i=0 To intHowManyInZ-1
For j=0 To intHowManyInY-1
For k=0 To intHowManyInX-1
ReDim Preserve arrEnvironmentPos(Ubound(arrEnvironmentPos)+1)
arrEnvironmentPos(Ubound(arrEnvironmentPos))= array(arrOrigin(0) + i*dblStep,arrOrigin(1) + j*dblStep,arrOrigin(2) + k*dblStep)
'ftiaxnei to grid me step
If blnDraw Then
Dim strPoint : strPoint = Rhino.AddPoint(arrEnvironmentPos(Ubound(arrEnvironmentPos)))
'an to exw na einai true to boolean draw tote bazei kai simeio sto grid
End If
Dim dblTemperature : dblTemperature = 0
For e=0 To Ubound(arrHotAttractors)
Dim strAttractorName : strAttractorName = rhino.ObjectName(arrHotAttractors(e))
Dim dblDistance : dblDistance = rhino.Distance(arrEnvironmentPos(Ubound(arrEnvironmentPos)), rhino.PointCoordinates(arrHotAttractors(e)))
dblTemperature = dblTemperature + CDbl(strAttractorName)/dblDistance
Next
ReDim Preserve arrEnvironmentTemp(Ubound(arrEnvironmentTemp)+1)
arrEnvironmentTemp(Ubound(arrEnvironmentTemp))= dblTemperature
If blnDraw Then
Call Rhino.ObjectColor(strPoint,rgb(dblTemperature*50,0,0))
End If
Next
Next
Next

CreateEnviromentGrid = array(arrEnvironmentPos, arrEnvironmentTemp)
Call Rhino.EnableRedraw(vbTrue)
End Function

Function CreateEnviromentGridWithShadows(arrOrigin, intHowManyInX, intHowManyInY, intHowManyInZ, dblStep, arrHotAttractors, blnDraw, arrShadowPolySrfs)
' this function sets up a grid of points and tempratures from "hot" attractors takes as inputs:

' intHowManyinX (for how many Points)
' intHowManyinY (for how many Points)
' intHowManyinZ (for how many Points)
' dblStep for the step of the grid
' arrHotAttractors is the ids of the points as attractors
' blnDraw = True if you want to draw the grid points in the screen

' it returns an array with two main slots/positions:
' slot/position (0) has all the points (x,y,z)
' slot/position (1) has all the temperatures

CreateEnviromentGridWithShadows = Null
Call Rhino.EnableRedraw(vbFalse)
ReDim arrEnvironmentPos(-1)
ReDim arrEnvironmentTemp(-1)
Dim i,j,k,e, l
For i=0 To intHowManyInZ-1
For j=0 To intHowManyInY-1
For k=0 To intHowManyInX-1
ReDim Preserve arrEnvironmentPos(Ubound(arrEnvironmentPos)+1)
arrEnvironmentPos(Ubound(arrEnvironmentPos))= array(arrOrigin(0) + i*dblStep,arrOrigin(1) + j*dblStep,arrOrigin(2) + k*dblStep)
Dim blnIsInside : blnIsInside = False
For l=0 To Ubound(arrShadowPolySrfs)
Dim strShadowPolySrf : strShadowPolySrf = arrShadowPolySrfs(l) 'to bazei se string giati to IsPointSurface thelei string gia prwti
If Rhino.ObjectName(strShadowPolySrf) = 0 Then
Dim blnTest : blnTest = Rhino.IsPointInSurface (strShadowPolySrf,arrEnvironmentPos(Ubound(arrEnvironmentPos)))
If blnTest Then blnIsInside = True
End If
Next

If blnIsInside Then
ReDim Preserve arrEnvironmentTemp(Ubound(arrEnvironmentTemp)+1)
arrEnvironmentTemp(Ubound(arrEnvironmentTemp))= -50
Else
'ftiaxnei to grid me step
If blnDraw Then
Dim strPoint : strPoint = Rhino.AddPoint(arrEnvironmentPos(Ubound(arrEnvironmentPos)))
'an to exw na einai true to boolean draw tote bazei kai simeio sto grid
End If
Dim dblTemperature : dblTemperature = 0
For e=0 To Ubound(arrHotAttractors)
Dim strAttractorName : strAttractorName = rhino.ObjectName(arrHotAttractors(e))
Dim dblDistance : dblDistance = rhino.Distance(arrEnvironmentPos(Ubound(arrEnvironmentPos)), rhino.PointCoordinates(arrHotAttractors(e)))
dblTemperature = dblTemperature + CDbl(strAttractorName)/dblDistance
Next
ReDim Preserve arrEnvironmentTemp(Ubound(arrEnvironmentTemp)+1)
arrEnvironmentTemp(Ubound(arrEnvironmentTemp))= dblTemperature
If blnDraw Then
Call Rhino.ObjectColor(strPoint,rgb(dblTemperature*50,0,0))
End If
End If
Next
Next
Next

CreateEnviromentGridWithShadows = array(arrEnvironmentPos, arrEnvironmentTemp)
Call Rhino.EnableRedraw(vbTrue)
End Function

Function UpdateEnviromentGrid(arrOrigin, arrData, arrHotAttractors)
' this function updates a grid of points and tempratures from "hot" attractors takes as inputs:

' intHowManyinX (for how many Points)
' intHowManyinY (for how many Points)
' intHowManyinZ (for how many Points)
' dblStep for the step of the grid
' arrHotAttractors is the ids of the points as attractors
' blnDraw = True if you want to draw the grid points in the screen

' it returns an array with two main slots/positions:
' slot/position (0) has all the points (x,y,z)
' slot/position (1) has all the temperatures

UpdateEnviromentGrid = Null
Call Rhino.EnableRedraw(vbFalse)
Dim arrEnvironmentPos : arrEnvironmentPos = arrData(0)
ReDim arrEnvironmentTemp(-1)
Dim i, e
For i=0 To Ubound(arrEnvironmentPos)
Dim dblTemperature : dblTemperature = 0
For e=0 To Ubound(arrHotAttractors)
Dim strAttractorName : strAttractorName = rhino.ObjectName(arrHotAttractors(e))
Dim dblDistance : dblDistance = rhino.Distance(arrEnvironmentPos(i), rhino.PointCoordinates(arrHotAttractors(e)))
dblTemperature = dblTemperature + CDbl(strAttractorName)/dblDistance
Next
ReDim Preserve arrEnvironmentTemp(Ubound(arrEnvironmentTemp)+1)
arrEnvironmentTemp(Ubound(arrEnvironmentTemp))= dblTemperature
Next
UpdateEnviromentGrid = array(arrEnvironmentPos, arrEnvironmentTemp)
Call Rhino.EnableRedraw(vbTrue)
End Function

Function UpdateEnviromentGridWithShadows(arrOrigin, arrData, arrHotAttractors, arrShadowPolySrfs, counter)
' this function updates a grid of points and tempratures from "hot" attractors takes as inputs:

' intHowManyinX (for how many Points)
' intHowManyinY (for how many Points)
' intHowManyinZ (for how many Points)
' dblStep for the step of the grid
' arrHotAttractors is the ids of the points as attractors
' blnDraw = True if you want to draw the grid points in the screen

' it returns an array with two main slots/positions:
' slot/position (0) has all the points (x,y,z)
' slot/position (1) has all the temperatures

UpdateEnviromentGridWithShadows = Null
Call Rhino.EnableRedraw(vbFalse)
Dim arrEnvironmentPos : arrEnvironmentPos = arrData(0)
ReDim arrEnvironmentTemp(-1)
Dim i, e, l
For i=0 To Ubound(arrEnvironmentPos)

Dim blnIsInside : blnIsInside = False
For l=0 To Ubound(arrShadowPolySrfs)
Dim strShadowPolySrf : strShadowPolySrf = arrShadowPolySrfs(l)
If Rhino.ObjectName(strShadowPolySrf) = counter Then
Dim blnTest : blnTest = Rhino.IsPointInSurface (strShadowPolySrf,arrEnvironmentPos(Ubound(arrEnvironmentPos)))
If blnTest Then blnIsInside = True
End If
Next

If blnIsInside Then
ReDim Preserve arrEnvironmentTemp(Ubound(arrEnvironmentTemp)+1)
arrEnvironmentTemp(Ubound(arrEnvironmentTemp))= -10
Else
Dim dblTemperature : dblTemperature = 0
For e=0 To Ubound(arrHotAttractors)
Dim strAttractorName : strAttractorName = rhino.ObjectName(arrHotAttractors(e))
Dim dblDistance : dblDistance = rhino.Distance(arrEnvironmentPos(i), rhino.PointCoordinates(arrHotAttractors(e)))
dblTemperature = dblTemperature + CDbl(strAttractorName)/dblDistance
Next
ReDim Preserve arrEnvironmentTemp(Ubound(arrEnvironmentTemp)+1)
arrEnvironmentTemp(Ubound(arrEnvironmentTemp))= dblTemperature
End If

Next
UpdateEnviromentGridWithShadows = array(arrEnvironmentPos, arrEnvironmentTemp)
Call Rhino.EnableRedraw(vbTrue)
End Function

Function PointCoordinatesOfArray(arrStrPoints)
PointCoordinatesOfArray = Null
ReDim arrPoints(Ubound(arrStrPoints)) 'eksiswnei ton arithmo thesewn tou pinaka strpoints me ton arrpoints
Dim i
For i = 0 To Ubound(arrStrPoints)
arrPoints(i) = Rhino.PointCoordinates(arrStrPoints(i)) 'ston arrPoints topothetei tis suntetagmenes twn simeiwn
Next
PointCoordinatesOfArray = arrPoints
End Function

Sub CheckAttractorNamesForHotness(arrAttractors)

Dim i
For i=0 To Ubound(arrAttractors)
Dim strAttractorName : strAttractorName = rhino.ObjectName(arrAttractors(i))
If IsNull(strAttractorName) Then
strAttractorName = rnd*100
Call rhino.ObjectName(arrAttractors(i),strAttractorName)
End If
Next

End Sub