return this->dnodes_;
}
+PolygonObstacle &RRTBase::frame()
+{
+ return this->frame_;
+}
+
std::vector<RRTNode *> &RRTBase::samples()
{
return this->samples_;
float dist_to(RRTNode *n);
};
+class PolygonObstacle : public Obstacle {
+ private:
+ std::vector<RRTNode *> bnodes_;
+ public:
+ void add_bnode(RRTNode *n);
+ bool collide(RRTNode *n);
+ bool collide(RRTEdge *e);
+ bool collide(std::vector<RRTEdge *> &edges);
+ float dist_to(RRTNode *n);
+
+ // getter
+ std::vector<RRTNode *> &bnodes();
+};
+
class SegmentObstacle : public RRTEdge, Obstacle {
public:
using RRTEdge::RRTEdge;
std::vector<RRTNode *> nodes_;
std::vector<RRTNode *> dnodes_;
+ PolygonObstacle frame_;
std::vector<RRTNode *> samples_;
std::vector<CircleObstacle> *cobstacles_;
std::vector<SegmentObstacle> *sobstacles_;
RRTNode *goal();
std::vector<RRTNode *> &nodes();
std::vector<RRTNode *> &dnodes();
+ PolygonObstacle &frame();
std::vector<RRTNode *> &samples();
std::vector<RRTNode *> iy_[IYSIZE];
Cell ixy_[IXSIZE][IYSIZE];
return (float) (sqrt(xx + yy) - this->r());
}
+void PolygonObstacle::add_bnode(RRTNode *n)
+{
+ this->bnodes_.push_back(n);
+}
+
+bool PolygonObstacle::collide(RRTNode *n)
+{
+ // From substack/point-in-polygon, see
+ // https://github.com/substack/point-in-polygon/blob/master/index.js
+ bool inside = false;
+ unsigned int i;
+ int j;
+ for (i = 0, j = this->bnodes_.size() - 1;
+ i < this->bnodes_.size();
+ j = i++) {
+ float xi = this->bnodes_[i]->x();
+ float yi = this->bnodes_[i]->y();
+ float xj = this->bnodes_[j]->x();
+ float yj = this->bnodes_[j]->y();
+ bool intersect = ((yi > n->y()) != (yj > n->y())) &&
+ (n->x() < (xj - xi) * (n->y() - yi) / (yj - yi) + xi);
+ if (intersect)
+ inside = !inside;
+ }
+ return inside;
+}
+
+bool PolygonObstacle::collide(RRTEdge *e)
+{
+ return false;
+}
+
+bool PolygonObstacle::collide(std::vector<RRTEdge *> &edges)
+{
+ return false;
+}
+
+float PolygonObstacle::dist_to(RRTNode *n)
+{
+ return 0;
+}
+
+std::vector<RRTNode *> &PolygonObstacle::bnodes()
+{
+ return this->bnodes_;
+}
+
bool SegmentObstacle::collide(RRTNode *n)
{
return false;