]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blobdiff - src/bcar.cc
Add generate for gnuplot method and example code
[hubacji1/bcar.git] / src / bcar.cc
index 1e205a7f1a1d51ffafa683c5c1a03343058fc49e..0b9062a0b793c6b0f9ac0874bfc069d3133efd1e 100644 (file)
@@ -137,6 +137,12 @@ Point::edist(Point const& p) const
        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)
 {
@@ -972,4 +978,97 @@ BicycleCar::next()
        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