20 rng = std::minstd_rand(seed);
28 result.landmarks_.push_back(pC);
44 if (
p.size() !=
size())
return false;
53 cout <<
"SimPolygon " <<
s <<
": " << endl;
54 for(
const Point2&
p: landmarks_)
61 for (
size_t i=0;
i<
size()-1; ++
i)
69 vector<SimWall2D>
edges = walls();
70 bool initialized =
false;
71 bool lastSide =
false;
74 Point2 dab = ab.b() - ab.a();
76 double cross = dab.x() * dac.y() - dab.y() * dac.x();
79 bool side =
cross > 0;
96 for(
const Point2&
a: landmarks_)
108 if (poly.contains(
p))
116 if (poly.overlaps(
p))
123 double side_len,
double mean_side_len,
double sigma_side_len,
124 double min_vertex_dist,
double min_side_len,
const vector<SimPolygon2D>& existing_polys) {
127 double d2 = side_len/2.0;
134 lms.insert(lms.begin(), poly.vertices().begin(), poly.vertices().end());
139 Pose2 xA(randomAngle(), randomBoundedPoint2(side_len, lms, existing_polys, min_vertex_dist));
142 double dAB = randomDistance(mean_side_len, sigma_side_len, min_side_len);
143 double tABC = randomAngle().theta();
147 double dBC = randomDistance(mean_side_len, sigma_side_len, min_side_len);
157 const double thresh = mean_side_len / 2.0;
158 if ((dAB + dBC + thresh > dAC) &&
159 (dAB + dAC + thresh > dBC) &&
160 (dAC + dBC + thresh > dAB) &&
161 insideBox(side_len, test_tri.
landmark(0)) &&
162 insideBox(side_len, test_tri.
landmark(1)) &&
163 insideBox(side_len, test_tri.
landmark(2)) &&
165 !nearExisting(lms, test_tri.
landmark(0), min_vertex_dist) &&
166 !nearExisting(lms, test_tri.
landmark(1), min_vertex_dist) &&
167 !nearExisting(lms, test_tri.
landmark(2), min_vertex_dist) &&
168 !anyOverlaps(test_tri, existing_polys)) {
172 throw runtime_error(
"Could not find space for a triangle");
178 double side_len,
double mean_side_len,
double sigma_side_len,
179 double min_vertex_dist,
double min_side_len,
const vector<SimPolygon2D>& existing_polys) {
182 double d2 = side_len/2.0;
188 lms.insert(lms.begin(), poly.vertices().begin(), poly.vertices().end());
190 const Point2 lower_corner(-side_len,-side_len);
191 const Point2 upper_corner( side_len, side_len);
196 double height = randomDistance(mean_side_len, sigma_side_len, min_side_len);
197 double width = randomDistance(mean_side_len, sigma_side_len, min_side_len);
200 Point2 pA = randomBoundedPoint2(lower_corner, upper_corner -
Point2(width, height),
201 lms, existing_polys, min_vertex_dist);
207 if (insideBox(side_len, rect.
landmark(0)) &&
208 insideBox(side_len, rect.
landmark(1)) &&
209 insideBox(side_len, rect.
landmark(2)) &&
210 insideBox(side_len, rect.
landmark(3)) &&
211 !nearExisting(lms, rect.
landmark(0), min_vertex_dist) &&
212 !nearExisting(lms, rect.
landmark(1), min_vertex_dist) &&
213 !nearExisting(lms, rect.
landmark(2), min_vertex_dist) &&
214 !nearExisting(lms, rect.
landmark(3), min_vertex_dist) &&
215 !anyOverlaps(rect, existing_polys)) {
219 throw runtime_error(
"Could not find space for a rectangle");
225 std::uniform_real_distribution<> gen_t(-
s/2.0,
s/2.0);
232 std::uniform_real_distribution<> gen_r(-
M_PI,
M_PI);
238 std::normal_distribution<> norm_dist(
mu,
sigma);
245 cout <<
"Non viable distance: " <<
d <<
" with mu = " <<
mu <<
" sigma = " <<
sigma
246 <<
" min_dist = " << min_dist << endl;
247 throw runtime_error(
"Failed to find a viable distance");
253 const vector<SimPolygon2D>& obstacles) {
255 Point2 p = randomPoint2(boundary_size);
256 if (!anyContains(
p, obstacles))
259 throw runtime_error(
"Failed to find a place for a landmark!");
265 const Point2Vector& landmarks,
double min_landmark_dist) {
267 Point2 p = randomPoint2(boundary_size);
268 if (!nearExisting(landmarks,
p, min_landmark_dist))
271 throw runtime_error(
"Failed to find a place for a landmark!");
278 const vector<SimPolygon2D>& obstacles,
double min_landmark_dist) {
280 Point2 p = randomPoint2(boundary_size);
281 if (!nearExisting(landmarks,
p, min_landmark_dist) && !anyContains(
p, obstacles))
284 throw runtime_error(
"Failed to find a place for a landmark!");
292 const std::vector<SimPolygon2D>& obstacles,
double min_landmark_dist) {
294 std::uniform_real_distribution<> gen_x(0.0, UR_corner.x() - LL_corner.x());
295 std::uniform_real_distribution<> gen_y(0.0, UR_corner.y() - LL_corner.y());
299 if (!nearExisting(landmarks,
p, min_landmark_dist) && !anyContains(
p, obstacles))
302 throw runtime_error(
"Failed to find a place for a landmark!");
308 return Pose2(randomAngle(), randomBoundedPoint2(boundary_size, obstacles));
318 const Point2&
p,
double threshold) {