]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blobdiff - src/bcar.cc
Add gen plot for lra and rra points
[hubacji1/bcar.git] / src / bcar.cc
index d5b6b020e19d0a08440ee335812aab5fb13d067f..4e635d6c395a9a8f72519f1c94ea6d2fb7b5252b 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)
 {
@@ -264,6 +270,14 @@ Line::h() const
        return atan2(this->_e.y() - this->_b.y(), this->_e.x() - this->_b.x());
 }
 
+void
+Line::gen_gnuplot_to(std::ostream& out)
+{
+       this->b().gen_gnuplot_to(out);
+       this->e().gen_gnuplot_to(out);
+       out << std::endl;
+}
+
 std::ostream&
 operator<<(std::ostream& out, Line const& li)
 {
@@ -465,6 +479,18 @@ CarSize::w(double w)
        this->_width = w;
 }
 
+double
+CarSize::wwm() const
+{
+       return this->_width_with_mirrors;
+}
+
+void
+CarSize::wwm(double w)
+{
+       this->_width_with_mirrors = w;
+}
+
 double
 CarSize::len() const
 {
@@ -537,13 +563,29 @@ CarSize::orradi() const
        return sqrt(mtrw2 + dr2);
 }
 
+double
+CarSize::imradi() const
+{
+       auto mtrw2 = pow(this->mtr() - this->wwm() / 2.0, 2.0);
+       auto df2 = pow(this->wb(), 2.0);
+       return sqrt(mtrw2 + df2);
+}
+
+double
+CarSize::omradi() const
+{
+       auto mtrw2 = pow(this->mtr() + this->wwm() / 2.0, 2.0);
+       auto df2 = pow(this->wb(), 2.0);
+       return sqrt(mtrw2 + df2);
+}
+
 double
 CarSize::perfect_parking_slot_len() const
 {
        auto r = this->ctc() / 2.0;
        auto l = this->wb();
        auto k = this->df() - this->wb();
-       auto w = this->w();
+       auto w = this->w(); // FIXME use wwm()?
        auto r2l2 = r * r - l * l;
        auto s = r2l2 + pow(l + k, 2.0) - pow(sqrt(r2l2) - w, 2.0);
        return this->len() + sqrt(s) - l - k;
@@ -868,6 +910,54 @@ BicycleCar::rfa() const
        return Point(this->rfax(), this->rfay());
 }
 
+double
+BicycleCar::lfmx() const
+{
+       double x = this->x();
+       x += (this->wwm() / 2.0) * cos(this->h() + M_PI / 2.0);
+       x += this->wb() * cos(this->h());
+       return x;
+}
+
+double
+BicycleCar::lfmy() const
+{
+       double y = this->y();
+       y += (this->wwm() / 2.0) * sin(this->h() + M_PI / 2.0);
+       y += this->wb() * sin(this->h());
+       return y;
+}
+
+double
+BicycleCar::rfmx() const
+{
+       double x = this->x();
+       x += (this->wwm() / 2.0) * cos(this->h() - M_PI / 2.0);
+       x += this->wb() * cos(this->h());
+       return x;
+}
+
+double
+BicycleCar::rfmy() const
+{
+       double y = this->y();
+       y += (this->wwm() / 2.0) * sin(this->h() - M_PI / 2.0);
+       y += this->wb() * sin(this->h());
+       return y;
+}
+
+Point
+BicycleCar::lfm() const
+{
+       return Point(this->lfmx(), this->lfmy());
+}
+
+Point
+BicycleCar::rfm() const
+{
+       return Point(this->rfmx(), this->rfmy());
+}
+
 double
 BicycleCar::cfx() const
 {
@@ -912,4 +1002,111 @@ BicycleCar::next()
        this->h(this->h() + this->sp() / this->wb() * tan(this->st()));
 }
 
+void
+BicycleCar::gen_gnuplot_to(std::ostream& out, GenPlotOpts 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.LF_POINT) {
+               this->lf().gen_gnuplot_to(out);
+       }
+       if (opts.LR_POINT) {
+               this->lr().gen_gnuplot_to(out);
+       }
+       if (opts.RR_POINT) {
+               this->rr().gen_gnuplot_to(out);
+       }
+       if (opts.RF_POINT) {
+               this->rf().gen_gnuplot_to(out);
+       }
+       if (opts.LFM_POINT) {
+               this->lfm().gen_gnuplot_to(out);
+       }
+       if (opts.RFM_POINT) {
+               this->rfm().gen_gnuplot_to(out);
+       }
+       if (opts.CRA_POINT || opts.CAR_POINT) {
+               Point::gen_gnuplot_to(out);
+       }
+       if (opts.LRA_POINT) {
+               this->lra().gen_gnuplot_to(out);
+       }
+       if (opts.RRA_POINT) {
+               this->rra().gen_gnuplot_to(out);
+       }
+       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