Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ljc2177/85 #90

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions docs/agent_behavior/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ The code below implements some additional features to make it easier for you to

Once you're done implementing the challenges, paste your final code into the code block below and create a pull request on this page called `3-your_uni` (for example `3-dn2216`).

```python
```python 3-ljc2177
import Rhino.Geometry as rh

class Agent:
Expand Down Expand Up @@ -166,8 +166,27 @@ class Agent:

# method for checking distance to other instance and moving closer if they are not touching
def cluster(self, other):

d = self.cp.DistanceTo(other.cp)

if d > (self.radius + other.radius):

pt_2 = other.cp
pt_1 = self.cp

v = pt_2 - pt_1

v.Unitize()
v *= d - (self.radius + other.radius)
v *= beta

pass
t = rh.Transform.Translation(v)
pt_1.Transform(t)

v.Reverse()
t = rh.Transform.Translation(v)
pt_2.Transform(t)


def get_circle(self):
return rh.Circle(self.cp, self.radius)
Expand All @@ -182,16 +201,30 @@ for pt in pts:
for i in range(len(agents)):
agents[i].add_neighbor(agents[i-1])


for i in range(max_iters):

print i

for j,agent_1 in enumerate(agents):


if j == 0:
origin = rh.Point3d(agent_1.cp)

# cluster to all agent's neighbors
for agent_2 in agent_1.neighbors:
agent_1.cluster(agent_2)

# collide with all agents after agent in list
for agent_2 in agents[j+1:]:
agent_1.collide(agent_2)

if j == 0:
end = rh.Point3d(agent_1.cp)

if origin == end:
break


circles = []

Expand Down
Binary file added docs/projects/packing/.DS_Store
Binary file not shown.
Binary file modified docs/projects/packing/packing.3dm
Binary file not shown.
Binary file modified docs/projects/packing/packing.gh
Binary file not shown.
24 changes: 17 additions & 7 deletions docs/projects/packing/packing.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import Rhino.Geometry as rh


class Agent:

def __init__(self, pt, r):
def __init__(self, pt, r, nam, adj):

self.cp = pt
self.radius = r
self.name = nam
self.adjacency = adj
self.neighbors = []

# method for adding another instance to a list of neighbors
def add_neighbor(self, other):

self.neighbors.append(other)

# method for checking distance to other room object and moving apart if they are overlapping
Expand Down Expand Up @@ -91,17 +93,25 @@ def get_circle(self):
return rh.Circle(self.cp, self.radius)


def run(pts, radii, max_iters, alpha):
def run(pts, radii, names, adjacencies, max_iters, alpha):

agents = []

for i, pt in enumerate(pts):
my_agent = Agent(pt, radii[i])
my_agent = Agent(pt, radii[i], names[i], adjacencies[i])
agents.append(my_agent)

print agents[9].adjacency

# for each agent in the list, add the previous agent as its neighbor
# for each agent in the list, add any agent that has it within its adjacencies list as its neighbor
for i in range(len(agents)):
agents[i].add_neighbor(agents[i-1])

for j in range(len(agents)-1):

if agents[j].name in agents[i].adjacency:
agents[i].add_neighbor(agents[j])
else:
continue

for i in range(max_iters):

Expand All @@ -123,7 +133,7 @@ def run(pts, radii, max_iters, alpha):

iters = i

print("process ran for {} iterations".format(i))
# print("process ran for {} iterations".format(i))

circles = []

Expand Down
104 changes: 52 additions & 52 deletions docs/projects/packing/rooms.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
[
{
"name": "Entry",
"area": 50,
"adjacency": ["Living"]
},
{
"name": "Living",
"area": 200,
"adjacency": ["Entry", "Kitchen", "Hall"]
},
{
"name": "Kitchen",
"area": 150,
"adjacency": ["Living", "Dining"]
},
{
"name": "Dining",
"area": 120,
"adjacency": ["Kitchen", "Living"]
},
{
"name": "Hall",
"area": 80,
"adjacency": ["Living", "Bathroom", "Master Bed", "Bedroom 1", "Bedroom 2"]
},
{
"name": "Bathroom",
"area": 80,
"adjacency": ["Hall"]
},
{
"name": "Master Bed",
"area": 150,
"adjacency": ["Hall", "Master Bath"]
},
{
"name": "Master Bath",
"area": 80,
"adjacency": ["Master Bed"]
},
{
"name": "Bedroom 1",
"area": 100,
"adjacency": ["Hall"]
},
{
"name": "Bedroom 2",
"area": 100,
"adjacency": ["Hall"]
}
]
[
{
" ""name"": ""Entry"","
" ""area"": 50,"
" ""adjacency"": [""Living""]"
" },"
{
" ""name"": ""Living"","
" ""area"": 200,"
" ""adjacency"": [""Entry"", ""Kitchen"", ""Hall""]"
" },"
{
" ""name"": ""Kitchen"","
" ""area"": 150,"
" ""adjacency"": [""Living"", ""Dining""]"
" },"
{
" ""name"": ""Dining"","
" ""area"": 120,"
" ""adjacency"": [""Kitchen"", ""Living""]"
" },"
{
" ""name"": ""Hall"","
" ""area"": 80,"
" ""adjacency"": [""Living"", ""Bathroom"", ""Master Bed"", ""Bedroom 1"", ""Bedroom 2""]"
" },"
{
" ""name"": ""Bathroom"","
" ""area"": 80,"
" ""adjacency"": [""Hall""]"
" },"
{
" ""name"": ""Master Bed"","
" ""area"": 150,"
" ""adjacency"": [""Hall"", ""Master Bath""]"
" },"
{
" ""name"": ""Master Bath"","
" ""area"": 80,"
" ""adjacency"": [""Master Bed""]"
" },"
{
" ""name"": ""Bedroom 1"","
" ""area"": 100,"
" ""adjacency"": [""Hall""]"
" },"
{
" ""name"": ""Bedroom 2"","
" ""area"": 100,"
" ""adjacency"": [""Hall""]"
}
]
Loading