bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
circle.h
Go to the documentation of this file.
1#ifndef BITSIM_GEOMETRY_SHAPES_CIRCLE_H
2#define BITSIM_GEOMETRY_SHAPES_CIRCLE_H
3
7
8#include <cmath>
9
10namespace bitsim
11{
12namespace geometry
13{
14
18class Circle
19{
20 public:
24 explicit Circle(real_t r);
25
30
34 real_t radius() const noexcept { return r_; }
35
39 GeomPoint<2> center() const noexcept { return center_; }
40
44 real_t area() const;
45
49 bool is_inside(const GeomPoint<2> &point, real_t tol = bitsim::consts::TOLERANCE) const;
50
55 bool is_inside(const real_t x, const real_t y, real_t tol = bitsim::consts::TOLERANCE) const;
56
57 private:
61 real_t r_;
62
66 GeomPoint<2> center_;
67};
68
69inline Circle::Circle(real_t r) : r_(r), center_(0.0) {}
70
71inline Circle::Circle(real_t r, const GeomPoint<2> &center) : r_(r), center_(center) {}
72
73inline real_t Circle::area() const { return bitsim::consts::maths::PI * r_ * r_; }
74
75inline bool Circle::is_inside(const GeomPoint<2> &point, real_t tol) const
76{
77
78 if (std::pow((center_[0] - point[0]), 2) + std::pow((center_[1] - point[1]), 2) - r_ * r_ < tol)
79 {
80 return true;
81 }
82
83 return false;
84}
85
86inline bool Circle::is_inside(const real_t x, const real_t y, real_t tol) const
87{
88 return is_inside({x, y}, tol);
89}
90
91} // namespace geometry
92} // namespace bitsim
93#endif // BITSIM_GEOMETRY_SHAPES_CIRCLE_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
Circle(real_t r)
Construct a circle centerd at the origin.
Definition circle.h:69
bool is_inside(const GeomPoint< 2 > &point, real_t tol=bitsim::consts::TOLERANCE) const
Returns true if the given point lies inside the circle.
Definition circle.h:75
real_t radius() const noexcept
Returns the radius of the circle.
Definition circle.h:34
real_t area() const
Returns the area.
Definition circle.h:73
GeomPoint< 2 > center() const noexcept
Returns the center of the circle.
Definition circle.h:39
A class that describes a point with spacedim spatial dimension space.
Definition geom_point.h:22
const real_t PI
The PI constant.
Definition bitsim_consts.h:63
const real_t TOLERANCE
Tolerance used around the library.
Definition bitsim_consts.h:26
Definition generic_line.h:16
Definition dc_motor_backend_base.h:9
double real_t
real_t
Definition bitsim_types.h:20