20 rng = std::minstd_rand(seed);
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)
62 result.push_back(
SimWall2D(landmarks_[
i], landmarks_[i+1]));
63 result.push_back(
SimWall2D(landmarks_[
size()-1], landmarks_[0]));
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;
128 lms.push_back(
Point2( d2, d2));
129 lms.push_back(
Point2(-d2, d2));
130 lms.push_back(
Point2(-d2,-d2));
131 lms.push_back(
Point2( d2,-d2));
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)) &&
164 distance2(test_tri.landmark(1), test_tri.landmark(2)) > min_side_len &&
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;
183 lms.push_back(
Point2( d2, d2));
184 lms.push_back(
Point2(-d2, d2));
185 lms.push_back(
Point2(-d2,-d2));
186 lms.push_back(
Point2( d2,-d2));
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) {
vector< MFAS::KeyPair > edges
bool equals(const SimPolygon2D &p, double tol=1e-5) const
const Point2 & t() const
translation
bool overlaps(const SimPolygon2D &p) const
static const double sigma
static double randomDistance(double mu, double sigma, double min_dist=-1.0)
double distance2(const Point2 &p, const Point2 &q, OptionalJacobian< 1, 2 > H1, OptionalJacobian< 1, 2 > H2)
distance between two points
static SimPolygon2D createTriangle(const Point2 &pA, const Point2 &pB, const Point2 &pC)
static Point2 randomBoundedPoint2(double boundary_size, const Point2Vector &landmarks, double min_landmark_dist)
static std::minstd_rand rng
Polygons for simulation use.
static Rot2 randomAngle()
Point3 cross(const Point3 &p, const Point3 &q, OptionalJacobian< 3, 3 > H1, OptionalJacobian< 3, 3 > H2)
cross product
std::vector< Point2, Eigen::aligned_allocator< Point2 > > Point2Vector
static SimPolygon2D createRectangle(const Point2 &p, double height, double width)
static Pose2 randomFreePose(double boundary_size, const std::vector< SimPolygon2D > &obstacles)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static SimPolygon2D randomRectangle(double side_len, double mean_side_len, double sigma_side_len, double min_vertex_dist, double min_side_len, const std::vector< SimPolygon2D > &existing_polys)
std::vector< SimWall2D > walls() const
static bool anyOverlaps(const SimPolygon2D &p, const std::vector< SimPolygon2D > &obstacles)
Class retract(const TangentVector &v) const
retract as required by manifold concept: applies v at *this
bool contains(const Point2 &p) const
static Rot2 fromAngle(double theta)
Named constructor from angle in radians.
void print(const std::string &s="") const
static void seedGenerator(unsigned long seed)
const Point2 & landmark(size_t i) const
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
static SimPolygon2D randomTriangle(double side_len, double mean_side_len, double sigma_side_len, double min_vertex_dist, double min_side_len, const std::vector< SimPolygon2D > &existing_polys)
static bool anyContains(const Point2 &p, const std::vector< SimPolygon2D > &obstacles)
static bool insideBox(double s, const Point2 &p)
static bool nearExisting(const Point2Vector &S, const Point2 &p, double threshold)
static Point2 randomPoint2(double s)