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
12 from math import cos, pi, sin
13 from random import random, uniform
19 MTR = ((CTC / 2)**2 - WB**2)**0.5 - W / 2
28 """Generate car init position."""
29 # TODO if changed, change ``gen_slot`` accordingly
33 def gen_slot(l=5.3, w=2.4):
34 """Generate parking slot."""
35 parallel = True if random() < 0.5 else False
36 if parallel and l == 5.3 and w == 2.4:
43 right = 1.0 if random() < 0.5 else -1.0
45 angl = uniform(0, 2 * pi)
48 h = uniform(0, 2 * pi)
52 x + l/2 * cos(h - pi/2 * right),
53 y + l/2 * sin(h - pi/2 * right),
56 x + w * cos(h) + l/2 * cos(h - pi/2 * right),
57 y + w * sin(h) + l/2 * sin(h - pi/2 * right),
60 x + w * cos(h) + l/2 * cos(h + pi/2 * right),
61 y + w * sin(h) + l/2 * sin(h + pi/2 * right),
64 x + l/2 * cos(h + pi/2 * right),
65 y + l/2 * sin(h + pi/2 * right),
71 x + w/2 * cos(h - pi/2 * right),
72 y + w/2 * sin(h - pi/2 * right),
75 x + l * cos(h) + w/2 * cos(h - pi/2 * right),
76 y + l * sin(h) + w/2 * sin(h - pi/2 * right),
79 x + l * cos(h) + w/2 * cos(h + pi/2 * right),
80 y + l * sin(h) + w/2 * sin(h + pi/2 * right),
83 x + w/2 * cos(h + pi/2 * right),
84 y + w/2 * sin(h + pi/2 * right),
90 """Generate obstacles array."""
92 min_r = ((W/2)**2 + ((WB+L)/2)**2)**0.5 + (OBST_W**2 + OBST_L**2)**0.5 / 2
93 for i in range(OBST_COUNT):
96 angl = uniform(0, 2 * pi)
97 r = uniform(min_r**2, (SLOT_RADI - 5)**2)**0.5
100 h = uniform(0, 2 * pi)
103 x + w/2 * cos(h - pi/2) + l/2 * cos(h),
104 y + w/2 * sin(h - pi/2) + l/2 * sin(h),
107 x + w/2 * cos(h - pi/2) - l/2 * cos(h),
108 y + w/2 * sin(h - pi/2) - l/2 * sin(h),
111 x + w/2 * cos(h + pi/2) - l/2 * cos(h),
112 y + w/2 * sin(h + pi/2) - l/2 * sin(h),
115 x + w/2 * cos(h + pi/2) + l/2 * cos(h),
116 y + w/2 * sin(h + pi/2) + l/2 * sin(h),
119 x + w/2 * cos(h - pi/2) + l/2 * cos(h),
120 y + w/2 * sin(h - pi/2) + l/2 * sin(h),
126 if __name__ == "__main__":