1 """Generate simple JSON scenario.
3 The scenario contains at least:
5 - `init` -- the init car position,
7 - `slot` -- the parking slot,
9 - `obst` -- the list of (convex polygon) obstacles.
11 from json import dumps, loads
12 from math import cos, pi, sin
13 from random import random, uniform
19 MTR = ((CTC / 2)**2 - WB**2)**0.5 - W / 2
27 """Generate car init position."""
28 # TODO if changed, change ``gen_slot`` accordingly
31 def gen_slot(l=5.3, w=2.4):
32 """Generate parking slot."""
33 parallel = True if random() < 0.5 else False
34 if parallel and l == 5.3 and w == 2.4:
41 right = 1.0 if random() < 0.5 else -1.0
43 angl = uniform(0, 2 * pi)
46 h = uniform(0, 2 * pi)
50 x + l/2 * cos(h - pi/2 * right),
51 y + l/2 * sin(h - pi/2 * right),
54 x + w * cos(h) + l/2 * cos(h - pi/2 * right),
55 y + w * sin(h) + l/2 * sin(h - pi/2 * right),
58 x + w * cos(h) + l/2 * cos(h + pi/2 * right),
59 y + w * sin(h) + l/2 * sin(h + pi/2 * right),
62 x + l/2 * cos(h + pi/2 * right),
63 y + l/2 * sin(h + pi/2 * right),
69 x + w/2 * cos(h - pi/2 * right),
70 y + w/2 * sin(h - pi/2 * right),
73 x + l * cos(h) + w/2 * cos(h - pi/2 * right),
74 y + l * sin(h) + w/2 * sin(h - pi/2 * right),
77 x + l * cos(h) + w/2 * cos(h + pi/2 * right),
78 y + l * sin(h) + w/2 * sin(h + pi/2 * right),
81 x + w/2 * cos(h + pi/2 * right),
82 y + w/2 * sin(h + pi/2 * right),
87 """Generate obstacles array."""
89 min_r = ((W/2)**2 + ((WB+L)/2)**2)**0.5 + (OBST_W**2 + OBST_L**2)**0.5 / 2
90 for i in range(OBST_COUNT):
93 angl = uniform(0, 2 * pi)
94 r = uniform(min_r**2, (SLOT_RADI - 5)**2)**0.5
97 h = uniform(0, 2 * pi)
100 x + w/2 * cos(h - pi/2) + l/2 * cos(h),
101 y + w/2 * sin(h - pi/2) + l/2 * sin(h),
104 x + w/2 * cos(h - pi/2) - l/2 * cos(h),
105 y + w/2 * sin(h - pi/2) - l/2 * sin(h),
108 x + w/2 * cos(h + pi/2) - l/2 * cos(h),
109 y + w/2 * sin(h + pi/2) - l/2 * sin(h),
112 x + w/2 * cos(h + pi/2) + l/2 * cos(h),
113 y + w/2 * sin(h + pi/2) + l/2 * sin(h),
116 x + w/2 * cos(h - pi/2) + l/2 * cos(h),
117 y + w/2 * sin(h - pi/2) + l/2 * sin(h),
122 if __name__ == "__main__":