]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/commitdiff
Randomize slot generation
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Fri, 31 Jan 2020 14:32:58 +0000 (15:32 +0100)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Tue, 4 Feb 2020 17:11:27 +0000 (18:11 +0100)
scripts/generate_simple_json_scenario.py

index 92c18fceba0f99067ddf6c88165b8817a0ed48d7..4dc8af6e291d8ef04bfa7d59f73e32ecd47d641f 100644 (file)
@@ -9,6 +9,7 @@ The scenario contains at least:
 - `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
@@ -18,15 +19,36 @@ MTR = ((CTC / 2)**2 - WB**2)**0.5 - W / 2
 
 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():