Liang Zheng, Jin Xiangyu,Yin Zhao, Jayden
From KokkugiaWiki
project development
new development
We have come up with some new strategy with the influences between agents and branches.
We assume that the agents are the circulations and the branches represent the structure of buildings.
There are four influences between agents and branches:
1.Agents' influence on Branches.
2.Branches' influence on Agents.
3.Agents' influence on Agents.
4.Branches' influence on Branches.
This is the part of the Script(Branches' influence on Agents) and we need some help in some parts.
Call Main()
Sub Main()
Dim line, angle, scale, newLines
'user input: line, angle, scale
newLines = rhino.GetObjects ("select the first branch")
angle = rhino.GetReal ("angle of the new branch", 60)
scale = rhino.GetReal ("scale of the branch", 0.8)
Dim startagents, iterations, pos, endpt, vel, arragents(), maxvel, maxforce, i, Radius
Dim arragentpos() , ptcloud
startagents = rhino.GetObjects("select the startagents",4)
iterations = rhino.GetInteger ("how many steps do u want",200)
maxVel = 1
maxForce = 0.2
Radius = 10
'compile an array of all the agents
'agent(pos,vel ,maxvel, maxforce)
'arragents(agent1,agent2.....)
'arragents( (pos, vel,maxvel, maxForce),(pos, vel,maxvel, maxForce)...... )
For i = 0 To ubound(startagents)
pos = rhino.CurveStartPoint(startagents(i))
endpt = rhino.CurveEndPoint(startagents(i))
vel = rhino.VectorCreate(endpt,pos)
ReDim Preserve arragents(i)
arragents(i) = array(pos, vel, maxvel, maxForce)
Next
'loop through steps
For i = 0 To iterations-1
Dim acc, vecali, j,vecsep
' call branch
If i Mod 10 = 0 Then
newLines = branch(newLines, angle, scale)
End If
'--------------THE PART BELOW IS WHERE WE NEED HELP----------------------
'call getBranchAttractors(newLines)
Dim j, branchAtt, branchAtt1, branchAtt2, branchAtt3, sumvect
branchAtt = getBranchAttractors(newLines)
branchAtt1 = branchAtt(0)
branchAtt2 = branchAtt(1)
branchAtt3 = branchAtt(2)
count = 0
' loop through branches
For j = 0 To Ubound(newLines)
' get end points
'GET THE END POINTS OF EACH LINE EG. Rhino.CurveEndPoint(newLines(j))
arrEndpts = endpt
' dist between pts
Dis = rhino.Distance (agent(0),arrEndpts)
'give the agent a radius to test
If Dis < radius And Dis > 0 Then
'Count the number of branches
'TRY USING A COUNTER EG. ptNumber = ptNumber + 1
PtNumber = the number of the arrEndpts
'Attract the agent based On the different situations
If PtNumber < 50 And PtNumber >0 Then
'attract the agent
'WHAT IS sumvec? I DON'T UNDERSTAND WHERE IT COMES FROM
sumvect = rhino.VectorAdd(sumvec, BranchAttGroup(0))
Else If PtNumber >50 And PtNumber < 100 Then
'slow down the agent
sumvect = rhino.VectorAdd(sumvec, BranchAttGroup(1))
sumvect = rhino.VectorScale(sumvec, 0.5)
Else
'repel the agent
sumvect = rhino.VectorAdd(sumvec, -BranchAttGroup(2))
End If
count = count+1
End If
If count > 0 Then
sumvect = rhino.VectorDivide(sumvect, count)
End If
Next
' HERE YOU ASSIGN A VALUE TO vel BUT THEN YOU WRITE OVER IT ABOUT 20 LINES BELOW
' I THINK YOU SHOULD RESTRUCTURE THE CODE SO THAT THE INFLUENCE OF THE BRANCHES IS HANDLED BY A DIFFERENT FUNCTION WHICH RETURNS A VECTOR WHICH IS ADDED TO acc IN THE SAME WAY THAT THE align FUNCTION RETURNS A VECTOR AND ADDS IT TO acc. THIS IS THE GENERAL STRUCTURE OF AGENT CODE. RATHER THAN DOING IT AS YOU HAVE ABOVE
vel = sumvect
'--------------THE PART ABOVE IS WHERE WE NEED HELP------------------
' loop through for each agent
For j =0 To ubound(arragents)
'reset acc to 0
acc = array(0,0,0)
'call the behavior functions - align etc
vecali = align(arragents(j),arragents, 10)
'weight - priority
vecali = rhino.VectorScale(vecali,3)
'update the agents position
acc = rhino.VectorAdd(acc, vecali)
'add acc to vel
vel = rhino.VectorAdd(arragents(j)(1),acc)
'limit vel to maxvel
vel = vectorlimit(vel, arragents(j)(2))
'update the array
arragents(j)(0) = rhino.VectorAdd(arragents(j)(0),vel)
arragents(j)(1) = vel
Next
'loop to make an array of positions
For j= 0 To ubound(arragents)
ReDim Preserve arragentpos(j)
arragentpos(j) = arragents(j)(0)
Next
'delete the previous pointcloud
If i>0 Then
Call rhino.DeleteObject(ptcloud)
End If
'update the point cloud
ptcloud = rhino.AddPointCloud(arragentpos)
Next
End Sub
Function align(agent, arragents, rangeOFVis)
Dim j, dist, sumvec, count
sumvec = array(0,0,0)
count = 0
For j = 0 To ubound(arragents)
dist = rhino.Distance(agent(0),arragents(j)(0))
If dist < rangeofvis And dist > 0 Then
'adding all the vel vectors to the sumvec
sumvec = rhino.VectorAdd(sumvec, arragents(j)(1))
count = count+1
End If
Next
'divide sumvec by the number of vector in the rangeofvis
If count > 0 Then
sumvec = rhino.VectorDivide(sumvec, count)
End If
'return the scaled vector
align = sumvec '
End Function
Function vectorlimit(vec, maxlength)
Dim veclength
veclength = rhino.VectorLength (vec)
If veclength > maxlength Then
'unitize
vec = rhino.VectorUnitize (vec)
'scale by maxlength
vec = rhino.VectorScale(vec, maxlength)
End If
vectorlimit = vec
End Function
Function branch(arrLines, angle, scale)
Dim linelength,startpt,endpt, vec, vec1, newpt1, line1, count, line2, newPt2, vec2, i
count = 0
For i = 0 To UBound(arrLines)
' calculate vector for the line
startpt = rhino.CurveStartPoint (arrLines(i))
endpt = rhino.CurveEndPoint (arrLines(i))
vec = rhino.VectorCreate (endpt, startpt)
' scale vector
vec = rhino.VectorScale (vec, scale)
' rotate vector
vec1 = rhino.VectorRotate (vec, angle , array(1,1,1))
vec2 = rhino.VectorRotate (vec, -angle , array(1,1,1))
' add vector to the endPt
newpt1 = rhino.VectorAdd (vec1, endpt)
newpt2 = rhino.VectorAdd (vec2, endpt)
' draw line
line1 = rhino.AddLine (endpt, newpt1)
ReDim Preserve newLines(count)
newLines(count) = line1
count = count + 1
line2 = rhino.AddLine (endPt, newPt2)
ReDim Preserve newLines(count)
newLines(count) = line2
count = count + 1
Next
branch = newLines
End Function
'--------------THE PART BELOW IS WHERE WE NEED HELP----------------------
Function getBranchAttractors(newLines)
Dim j, arrEndpts, Dis, Radius, BranchAttGroup()
count = 0
' loop through branches
For j = 0 To Ubound(newLines)
' get end points
'THIS IS NOT A FUNCTION. TRY: arrEndpts = Rhino.CurveEndPoint(newLines(j))
arrEndpts = endpt
' dist between pts
Dis = rhino.Distance (agent(0),arrEndpts)
'give the agent a radius to test
Radius = 10
If Dis < radius And Dis > 0 Then
' count the number of branches(endpts)
'USE A COUNTER AS SUGGESTED IN THE SUB ROUTINE
PtNumber = the number of the arrEndpts
If PtNumber < 50 And PtNumber >0 Then
BranchAttGroup(0) = arrEndpts 'put these points into branchAtt(0)
sumvec = rhino.VectorAdd(sumvec, BranchAttGroup(0))
Else If PtNumber >50 And PtNumber < 100 Then
BranchAttGroup(1) = arrEndpts 'put these points into branchAtt(1)
sumvec = rhino.VectorAdd(sumvec, BranchAttGroup(1))
sumvec =
Else
BranchAttGroup(2) = arrEndpts 'put these points into branchAtt(2)
sumvec = rhino.VectorAdd(sumvec, -BranchAttGroup(2))
End If
count = count+1
End If
' retun an array with 3 arrays of att points
' I DONT UNDERSTAND WHAT YOU ARE DOING WITH THIS FUNCTION - ARE YOU JUST TRY TO RETURN ARRAYS OF POINTS WHICH ARE END POINTS OF BRANCHES? IF SO YOU DON'T NEED ANY OF THE VECTOR FUNCTIONS
Next
getBranchAttractors = BranchGroup
End Function
'--------------THE PART ABOVE IS WHERE WE NEED HELP------------------
COMENTS 5 NOV
the logic of the mutual interaction of the agents and the branches should yield significant potential. however the critical issue is what behavior emerges from the system - it is important to be able to critically evaluate the qualitative aspects of the results - design through the system. i think it is important that you are generating what you consider to be desirable outcomes from each system individually before you have them interacting. this will help you calibrate the interaction. you should also consider whether the branches grow in response to the agents of just modify their geometry after they have grown.
at this stage you are still considering the branch and the agents to be relatively generic. the algorithm you are working on is a growth algorithm, whether it produces branches or another entirely different type of geometry is up to you - consider this carefully and design the resultant geometry.
i have included a few comments (in caps) in your code which should help you to progress.











