From: Jiri Vlasak Date: Sun, 19 Mar 2023 21:27:22 +0000 (+0100) Subject: Add arc len computation method to point X-Git-Url: https://rtime.felk.cvut.cz/gitweb/hubacji1/iamcar2.git/commitdiff_plain/2921634dd3f757e8f6389b7890995d1839c3491e Add arc len computation method to point --- diff --git a/bcar/incl/bcar.hh b/bcar/incl/bcar.hh index 3afde08..ebe6557 100644 --- a/bcar/incl/bcar.hh +++ b/bcar/incl/bcar.hh @@ -92,6 +92,12 @@ public: /*! Return Euclidean distance to `p`. */ double edist(Point const& p) const; + /*! Return length of arc between two points when radius is kwown. + * + * \see https://math.stackexchange.com/questions/1595872/arclength-between-two-points-on-a-circle-not-knowing-theta + */ + double arc_len(Point const& p, double r); + /*! Generate output for plotting with gnuplot. */ void gen_gnuplot_to(std::ostream& out); diff --git a/bcar/src/bcar.cc b/bcar/src/bcar.cc index 44763d7..01f479c 100644 --- a/bcar/src/bcar.cc +++ b/bcar/src/bcar.cc @@ -145,6 +145,12 @@ Point::edist(Point const& p) const return sqrt(pow(p.x() - this->_x, 2.0) + pow(p.y() - this->_y, 2.0)); } +double +Point::arc_len(Point const& p, double r) +{ + return 2 * r * asin(this->edist(p) / 2 / r); +} + void Point::gen_gnuplot_to(std::ostream& out) {