def distance(x1, y1, x2, y2): """ Returns the distance between the twoo points """ p1 = vector(x1, 0, y1) p2 = vector(x2, 0, y2) return (p1 - p2).length()
def overlaps(x1, y1, r1, x2, y2, r2): """ Returns the amount the two circles overlap """ # print "do " + str(agent1) + " and " + str(agent2) + " overlap?" p1 = vector(x1, 0, y1) p2 = vector(x2, 0, y2) distance = (p1 - p2).get_length() distanceThreshold = (r1 + r2) # print "distanceTreshold: " + str(distanceThreshold) + " distance: " + str(distance) overlaps = distanceThreshold - distance if overlaps > 0: return overlaps else: return 0
def randPositionInWithoutColisions(self, xmin, xmax, zmin, zmax, radius): """ Returns a vector with position inside bounds """ tryTimes = 1000 xmin = xmin + radius xmax = xmax - radius zmin = zmin + radius zmax = zmax - radius agents = self.getAgents() agent = Agent() agent.set_radius(0.5) badLoc = False # random.seed(seed) for i in range(tryTimes): tmp_v = vector(random.uniform(xmin, xmax), 0, random.uniform(zmin, zmax)) # print tmp_v agent.set_position(tmp_v) for tmp_agent in agents: if agent.overlaps(tmp_agent): # agent overlaps another generate a new position badLoc = True break if badLoc: badLoc = False continue else: # made it though test with other agents so no overlapping break if i >= (tryTimes - 1): print "Gave up trying to find a placement without collisions" return tmp_v
def hallway_one_way(args, samples=1): pillars = chunks(args, 2) # print "args to hallway " + str(args) # print "pillars " + str(pillars) numAgents = 50 vec1 = vector(1, 0, 0) axis = vector(0, 1, 0) box = AxisAlignedBox(0, 30, 0, 1, -5, 5) # this is almost more like radius # scale = float(30) scenarios = [] seed = 10 random.seed(seed) for i in range(samples): scenario = TestCase() # print map_meta_data xmax = float(100) / 2 zmax = float(100) / 2 version = 1.0 scenario.addHeader("hallway one way", 1.0, -xmax, xmax, 0, 0, -zmax, zmax) add_noise = True seed = sample_agents(scenario, box, numAgents) # for vec in positions: # print vec scenario.addObstacle(box.get_xmin() - 20, box.get_xmax() + 20, 0, 1, box.get_zmin() - 5, box.get_zmin()) scenario.addObstacle(box.get_xmin() - 20, box.get_xmax() + 20, 0, 1, box.get_zmax(), box.get_zmax() + 5) for pillar in pillars: # print "pillar is " + str(pillar) scenario.addCircleObstacle(pillar[0], 0, pillar[1], 0.65, 1) scenarios.append(scenario) # print scenario.getAgents() return scenarios
def randPositionIn(self, xmin, xmax, zmin, zmax, radius): """ Returns a vector with position inside bounds """ xmin = xmin + radius xmax = xmax - radius zmin = zmin + radius zmax = zmax - radius tmp_v = vector(random.uniform(xmin, xmax), 0, random.uniform(zmin, zmax)) return tmp_v
def sample_agents(scenario, box, numAgents, seed=10): radius = 0.5 target = vector(-15, 0, 0) for i in range(numAgents): vectmp = scenario.randPositionInWithoutColisions( box.get_xmin(), box.get_xmax(), box.get_zmin(), box.get_zmax(), radius) scenario.addAgent(name="agent" + str(i), radius=radius, agentPos=vectmp, directionV=[1, 0, 0], speed=0, targetLocationV=target, desiredSpeed=1.33, timeDuration=1000.0)
def convertElementToAgent(self, element): agent = Agent() ic = element.find("./" + self._xmlns + "initialConditions") position = ic.find("./" + self._xmlns + "position") px = float(position.find("./" + self._xmlns + "x").text) py = float(position.find("./" + self._xmlns + "y").text) pz = float(position.find("./" + self._xmlns + "z").text) direction = ic.find("./" + self._xmlns + "direction") dx = float(direction.find("./" + self._xmlns + "x").text) dy = float(direction.find("./" + self._xmlns + "y").text) dz = float(direction.find("./" + self._xmlns + "z").text) radius = float(ic.find("./" + self._xmlns + "radius").text) speed = float(ic.find("./" + self._xmlns + "speed").text) pos = vector(px, py, pz) dir = vector(dx, dy, dz) agent.set_position(pos) agent.set_direction(dir) agent.set_radius(radius) agent.set_speed(speed) return agent
def __init__(self, position=vector(), direction=vector(), radius=0.5, speed=1.33): self._position=position self._direction=direction self._radius=radius self._speed=speed
from numpy import * import sys import random sys.path.append("../../") from steersuite.TestCase import TestCase sys.path.append("../") from tools.gameobjects.vector3 import Vector3 as vector # sudo apt-get install python-visual # http://vpython.org/contents/docs/vector.html agents = 240 vec1 = vector(1, 0, 0) axis = vector(0, 1, 0) thetaPart = float(360) / agents # this is almost more like radius # scale = float(30) extra_space = 1.1 noise_amount = 0.05 scale = (agents * extra_space) / ( 2 * pi) # calculates circumference and gives %15 extra space scenario = TestCase() # print map_meta_data xmax = float(100) / 2 zmax = float(100) / 2 version = 1.0 scenario.addHeader("concentric circles", 1.0, -xmax, xmax, 0, 0, -zmax, zmax) add_noise = True