- `obst` -- the list of (convex polygon) obstacles.
"""
from json import dumps, loads
+from math import cos, pi, sin
from random import random
W = 1.625
def gen_init():
"""Generate car init position."""
+ # TODO if changed, change ``gen_slot`` accordingly
return (0, 0, 0)
-def gen_slot():
+def gen_slot(l=5.3, w=2.4):
"""Generate parking slot."""
+ coord_min = 2 * MTR
+ coord_max = 20
+ coord_dif = coord_max - coord_min
+ x = random() * coord_dif + coord_min
+ x *= -1 if random() < 0.5 else 1
+ y = random() * coord_dif + coord_min
+ y *= -1 if random() < 0.5 else 1
+ h = random() * 2 * pi
return [[
- [10, 10],
- [13, 10],
- [13, 17],
- [10, 17],
+ [
+ x + w/2 * cos(h - pi/2),
+ y + w/2 * sin(h - pi/2),
+ ],
+ [
+ x + l * cos(h) + w/2 * cos(h - pi/2),
+ y + l * sin(h) + w/2 * sin(h - pi/2),
+ ],
+ [
+ x + l * cos(h) + w/2 * cos(h + pi/2),
+ y + l * sin(h) + w/2 * sin(h + pi/2),
+ ],
+ [
+ x + w/2 * cos(h + pi/2),
+ y + w/2 * sin(h + pi/2),
+ ],
]]
def gen_obst():