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)
{
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)
{
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
{
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;
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
{
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