]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/commitdiff
Add arc len computation method to point
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Sun, 19 Mar 2023 21:27:22 +0000 (22:27 +0100)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Mon, 20 Mar 2023 10:10:14 +0000 (11:10 +0100)
bcar/incl/bcar.hh
bcar/src/bcar.cc

index 3afde08906b74aebc75014d7bc5ab3b080a99181..ebe655724287e9e5963eaf9df749f84ae56491e1 100644 (file)
@@ -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);
 
index 44763d7c5a64fe7d89ee56f67f31e1e7c5f0e75a..01f479cd722198e87183e21c69b6702999debf1e 100644 (file)
@@ -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)
 {