-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathNavUtils.py
77 lines (64 loc) · 2.17 KB
/
NavUtils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'''
(c) 2015 Georgia Tech Research Corporation
This source code is released under the New BSD license. Please see the LICENSE.txt file included with this software for more information
authors: Arindam Bose ([email protected]), Tucker Balch ([email protected])
'''
from LinearAlegebraUtils import *
import numpy as np
def getObstacleAvoidance(obstacles):
currObstacle = obstacles[0]
for obstacle in obstacles:
if np.linalg.norm(obstacle.position) < np.linalg.norm(currObstacle.position):
currObstacle = obstacle;
#distance to surface
distToSurface = np.linalg.norm(currObstacle.position) - currObstacle.radius;
if(distToSurface < 0.1):
distToSurface = 0.1
mag = 20/distToSurface;
direction = currObstacle.position * -1
if mag < 0:
mag = 0
return mag * direction;
def findNearestUnstunned(agents):
unstunned = []
for agent in agents:
if not agent.isStunned:
unstunned.append(agent)
#using a lambda function to get the agent closest
if(len(unstunned) > 0):
minAgent = min(unstunned, key = lambda a: np.linalg.norm(a.position))
else:
minAgent = agents[0]
return minAgent;
def getTeamAvoidance(team):
checkRange = 50
vecSum = np.array([0, 0, 0])
for agent in team:
dist = np.linalg.norm(agent.position)
if dist < checkRange:
vecSum += (agent.position * -1)
return vecSum ;
def getTeamNearestAvoidance(team):
currAgent = team[0]
for agent in team:
if np.linalg.norm(agent.position) < np.linalg.norm(currAgent.position):
currAgent = agent;
#distance to surface
distToSurface = np.linalg.norm(currAgent.position) - currAgent.colRadius;
if(distToSurface < 0.1):
distToSurface = 0.1
mag = 20/distToSurface;
direction = currAgent.position * -1
if mag < 0:
mag = 0
return mag * direction;
def getRestrictionField(originObject, restrictionRange):
pos = originObject.position
dist = np.linalg.norm(pos)
direction = normalize(pos)
mag = 0
if dist > (0.8)*restrictionRange:
mag = dist
else:
mag = 0
return mag*direction