Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DataScienceSWP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
phwitte
DataScienceSWP
Commits
c9fede92
Commit
c9fede92
authored
7 years ago
by
markr
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
81426ab7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Final/python files/check_boundarys.py
+83
-0
83 additions, 0 deletions
Final/python files/check_boundarys.py
with
83 additions
and
0 deletions
Final/python files/check_boundarys.py
0 → 100644
+
83
−
0
View file @
c9fede92
from
graphics
import
*
# get here: http://mcsp.wartburg.edu/zelle/python/graphics.py
import
math
# check for window boundaries and move agent
# window walls "reflect" agents
def
checkBoundary
(
agent
,
winWidth
,
winHeight
):
point
=
agent
.
point
point
.
move
(
agent
.
x_velocity
,
agent
.
y_velocity
)
x
=
point
.
getX
()
y
=
point
.
getY
()
# agent is in window
if
x
>
0
and
y
<
winHeight
and
x
<
winWidth
and
y
>
0
:
agent
.
set_point
(
point
)
# window walls "reflect" agents
elif
x
<=
0
or
x
>=
winWidth
:
agent
.
set_xvelocity
(
agent
.
x_velocity
*
(
-
1
))
agent
.
point
.
move
(
agent
.
x_velocity
,
agent
.
y_velocity
)
elif
y
<=
0
or
y
>=
winHeight
:
agent
.
set_yvelocity
(
agent
.
y_velocity
*
(
-
1
))
agent
.
point
.
move
(
agent
.
x_velocity
,
agent
.
y_velocity
)
return
agent
# check for window boundaries and move agent
# agents swim through window walls(wraparound)
def
checkBoundary_free
(
agent
,
winWidth
,
winHeight
):
point
=
agent
.
point
point
.
move
(
agent
.
x_velocity
,
agent
.
y_velocity
)
x
=
point
.
getX
()
y
=
point
.
getY
()
# agent is in window
if
x
>
0
and
y
<
winHeight
and
x
<
winWidth
and
y
>
0
:
agent
.
set_point
(
point
)
# wraparound
elif
x
<=
0
or
x
>=
winWidth
:
agent
.
point
.
undraw
()
x
=
agent
.
point
.
getX
()
%
winWidth
agent
.
set_point
(
Point
(
x
,
y
))
elif
y
<=
0
or
y
>=
winHeight
:
agent
.
point
.
undraw
()
y
=
agent
.
point
.
getY
()
%
winHeight
agent
.
set_point
(
Point
(
x
,
y
))
return
agent
# check if rotation is in range of maxTurn, set to +/-maxturn if not,
# else make velocity = tempvelocity
def
move_agent_couzin
(
agent
,
maxTurn
,
radTurn
,
negRadTurn
):
angle_old
=
math
.
atan2
(
agent
.
y_velocity
,
agent
.
x_velocity
)
angle_new
=
math
.
atan2
(
agent
.
tempvelocity
[
1
],
agent
.
tempvelocity
[
0
])
alpha
=
math
.
degrees
(
angle_old
-
angle_new
)
# test if in range of maxturn, if not rotate angle by maxTurn in
# direction of new direction
if
abs
(
alpha
)
>
180
:
if
alpha
<
0
:
alpha
+=
360
else
:
alpha
-=
360
if
abs
(
alpha
)
<
maxTurn
:
x
=
agent
.
tempvelocity
[
0
]
y
=
agent
.
tempvelocity
[
1
]
elif
alpha
<
0
:
x
=
agent
.
x_velocity
*
math
.
cos
(
radTurn
)
-
agent
.
y_velocity
*
math
.
sin
(
radTurn
)
y
=
agent
.
x_velocity
*
math
.
sin
(
radTurn
)
+
agent
.
y_velocity
*
math
.
cos
(
radTurn
)
else
:
x
=
agent
.
x_velocity
*
math
.
cos
(
negRadTurn
)
-
agent
.
y_velocity
*
math
.
sin
(
negRadTurn
)
y
=
agent
.
x_velocity
*
math
.
sin
(
negRadTurn
)
+
agent
.
y_velocity
*
math
.
cos
(
negRadTurn
)
agent
.
x_velocity
=
x
agent
.
y_velocity
=
y
return
agent
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment