/*! Return Euclidean distance to `p`. */
double edist(Point const& p) const;
+ /*! Generate output for plotting with gnuplot. */
+ void gen_gnuplot_to(std::ostream& out);
+
bool operator==(Point const& p);
friend std::ostream& operator<<(std::ostream& out, Point const& p);
};
/*! Next car position based on speed `sp` and steer `st`. */
void next();
+
+ /*! Options for generating output for gnuplot. */
+ class GenPlotOpts {
+ public:
+ static bool LEFT;
+ static bool RIGHT;
+ static bool REAR;
+ static bool FRONT;
+ static bool FRAME;
+ static bool ARROW;
+ static bool CROSS;
+ static bool CAR;
+ static bool LEFT_MIRROR;
+ static bool RIGHT_MIRROR;
+ static bool MIRRORS;
+ static bool ALL;
+ };
+
+ /*! Generate output for plotting with gnuplot. */
+ void gen_gnuplot_to(std::ostream& out, GenPlotOpts const& opts);
};
} // namespace bcar
return sqrt(pow(p.x() - this->_x, 2.0) + pow(p.y() - this->_y, 2.0));
}
+void
+Point::gen_gnuplot_to(std::ostream& out)
+{
+ out << this->_x << " " << this->_y << std::endl;
+}
+
bool
Point::operator==(Point const& p)
{
this->h(this->h() + this->sp() / this->wb() * tan(this->st()));
}
+bool BicycleCar::GenPlotOpts::LEFT = false;
+bool BicycleCar::GenPlotOpts::RIGHT = false;
+bool BicycleCar::GenPlotOpts::REAR = false;
+bool BicycleCar::GenPlotOpts::FRONT = false;
+bool BicycleCar::GenPlotOpts::FRAME = false; // LEFT, RIGHT, REAR, FRONT
+bool BicycleCar::GenPlotOpts::ARROW = false;
+bool BicycleCar::GenPlotOpts::CROSS = false;
+bool BicycleCar::GenPlotOpts::CAR = false; // CROSS, ARROW, FRAME
+bool BicycleCar::GenPlotOpts::LEFT_MIRROR = false;
+bool BicycleCar::GenPlotOpts::RIGHT_MIRROR = false;
+bool BicycleCar::GenPlotOpts::MIRRORS = false; // RIGHT_MIRROR, LEFT_MIRROR
+bool BicycleCar::GenPlotOpts::ALL = true; // MIRRORS, CAR
+
+void
+BicycleCar::gen_gnuplot_to(std::ostream& out, GenPlotOpts const& opts)
+{
+ if (opts.ALL) {
+ opts.CAR = true;
+ opts.MIRRORS = true;
+ }
+ if (opts.MIRRORS) {
+ opts.LEFT_MIRROR = true;
+ opts.RIGHT_MIRROR = true;
+ }
+ if (opts.CAR) {
+ opts.FRAME = true;
+ opts.CROSS = true;
+ opts.ARROW = true;
+ }
+ if (opts.FRAME) {
+ opts.LEFT = true;
+ opts.RIGHT = true;
+ opts.REAR = true;
+ opts.FRONT = true;
+ }
+ if (opts.LEFT) {
+ this->lf().gen_gnuplot_to(out);
+ this->lr().gen_gnuplot_to(out);
+ out << std::endl;
+ }
+ if (opts.RIGHT) {
+ this->rf().gen_gnuplot_to(out);
+ this->rr().gen_gnuplot_to(out);
+ out << std::endl;
+ }
+ if (opts.REAR) {
+ this->lr().gen_gnuplot_to(out);
+ this->rr().gen_gnuplot_to(out);
+ out << std::endl;
+ }
+ if (opts.FRONT) {
+ this->lf().gen_gnuplot_to(out);
+ this->rf().gen_gnuplot_to(out);
+ out << std::endl;
+ }
+ if (opts.ARROW) {
+ this->cf().gen_gnuplot_to(out);
+ this->lfa().gen_gnuplot_to(out);
+ this->rfa().gen_gnuplot_to(out);
+ this->cf().gen_gnuplot_to(out);
+ out << std::endl;
+ }
+ if (opts.CROSS) {
+ double lx = this->x() + 0.2 * cos(this->h() + M_PI/2);
+ double rx = this->x() - 0.2 * cos(this->h() + M_PI/2);
+ double fx = this->x() + 0.2 * cos(this->h());
+ double bx = this->x() - 0.2 * cos(this->h()); // rear is back
+ double ly = this->y() + 0.2 * sin(this->h() + M_PI/2);
+ double ry = this->y() - 0.2 * sin(this->h() + M_PI/2);
+ double fy = this->y() + 0.2 * sin(this->h());
+ double by = this->y() - 0.2 * sin(this->h()); // rear is back
+ out << lx << " " << ly << std::endl;
+ out << rx << " " << ry << std::endl;
+ out << std::endl;
+ out << fx << " " << fy << std::endl;
+ out << bx << " " << by << std::endl;
+ out << std::endl;
+ }
+ if (opts.LEFT_MIRROR) {
+ this->lf().gen_gnuplot_to(out);
+ this->lfm().gen_gnuplot_to(out);
+ this->lr().gen_gnuplot_to(out);
+ out << std::endl;
+
+ }
+ if (opts.RIGHT_MIRROR) {
+ this->rf().gen_gnuplot_to(out);
+ this->rfm().gen_gnuplot_to(out);
+ this->rr().gen_gnuplot_to(out);
+ out << std::endl;
+ }
+}
+
} // namespace bcar