]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/commitdiff
Add point inside of circle check
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 20 Jan 2022 21:41:20 +0000 (22:41 +0100)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 20 Jan 2022 21:41:20 +0000 (22:41 +0100)
incl/bcar.hh
src/bcar.cc

index 95d67dfa6e1df4f1d7e4a5dea2619ca1ee52d32c..49122977b42e9d1e762a1e985f52a211253c4fbe 100644 (file)
@@ -55,6 +55,12 @@ public:
         */
        bool inside_of(std::vector<Point> const& poly) const;
 
+       /*! \brief Return `true` if `this` point is inside the circle `c`, `r`.
+        *
+        * \see * https://math.stackexchange.com/questions/198764/how-to-know-if-a-point-is-inside-a-circle#198769
+        */
+       bool inside_of(Point const& c, double const r) const;
+
        /*! \brief Return `true` if on the right side of the plane.
         *
         * The plane is given by the line `li`, where `li->b()` is the base
index 4e635d6c395a9a8f72519f1c94ea6d2fb7b5252b..8234b6261b85b0b2ed14e44d906471dcd460ade3 100644 (file)
@@ -85,6 +85,14 @@ Point::inside_of(std::vector<Point> const& poly) const
        return c;
 }
 
+bool
+Point::inside_of(Point const& c, double const r) const
+{
+       double dx = this->x() - c.x();
+       double dy = this->y() - c.y();
+       return pow(dx, 2.0) + pow(dy, 2.0) < pow(r, 2.0);
+}
+
 bool
 Point::on_right_side_of(Line const& li) const
 {