LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
circle_2d.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa Akiyama
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_GEOM_CIRCLE2D_H
33#define RCSC_GEOM_CIRCLE2D_H
34
35#include <iostream>
36
37#include <rcsc/geom/region_2d.h>
38#include <rcsc/geom/vector_2d.h>
39
40namespace rcsc {
41
42class Line2D;
43class Ray2D;
44class Segment2D;
45
51 : public Region2D {
52private:
53
55 Vector2D M_center;
56
58 double M_radius;
59
60 static const double EPSILON;
61
62
63public:
68 : M_center( 0.0, 0.0 ),
69 M_radius( 0.0 )
70 { }
71
77 Circle2D( const Vector2D & c,
78 const double r )
79 : M_center( c ),
80 M_radius( r )
81 {
82 if ( r < 0.0 )
83 {
84 std::cerr << "Circle2D::Circle2D(). radius must be positive value."
85 << std::endl;
86 M_radius = 0.0;
87 }
88 }
89
96 const Circle2D & assign( const Vector2D & c,
97 const double r )
98 {
99 M_center = c;
100 M_radius = r;
101 if ( r < 0.0 )
102 {
103 std::cerr << "Circle2D::assign(). radius must be positive value."
104 << std::endl;
105 M_radius = 0.0;
106 }
107 return *this;
108 }
109
114 virtual
115 double area() const
116 {
117 return AngleDeg::PI * M_radius * M_radius;
118 }
119
125 virtual
126 bool contains( const Vector2D & point ) const
127 {
128 return M_center.dist2( point ) < M_radius * M_radius;
129 }
130
135 const Vector2D & center() const
136 {
137 return M_center;
138 }
139
144 double radius() const
145 {
146 return M_radius;
147 }
148
156 int intersection( const Line2D & line,
157 Vector2D * sol1,
158 Vector2D * sol2 ) const;
159
167 int intersection( const Ray2D & ray,
168 Vector2D * sol1,
169 Vector2D * sol2 ) const;
170
178 int intersection( const Segment2D & segment,
179 Vector2D * sol1,
180 Vector2D * sol2 ) const;
181
189 int intersection( const Circle2D & circle,
190 Vector2D * sol1,
191 Vector2D * sol2 ) const;
192
193 // static utility
194
202 static
204 const Vector2D & p1,
205 const Vector2D & p2 );
206
215 static
216 bool contains( const Vector2D & point,
217 const Vector2D & p0,
218 const Vector2D & p1,
219 const Vector2D & p2 );
220};
221
222}
223
224#endif
static const double PI
pi valur
Definition: angle_deg.h:63
2d circle class
Definition: circle_2d.h:51
int intersection(const Segment2D &segment, Vector2D *sol1, Vector2D *sol2) const
calculate the intersection with segment line
virtual bool contains(const Vector2D &point) const
check if point is within this region
Definition: circle_2d.h:126
virtual double area() const
get the area value of this circle
Definition: circle_2d.h:115
Circle2D(const Vector2D &c, const double r)
construct with center point and radius value.
Definition: circle_2d.h:77
int intersection(const Line2D &line, Vector2D *sol1, Vector2D *sol2) const
caluclate the intersection with straight line
int intersection(const Ray2D &ray, Vector2D *sol1, Vector2D *sol2) const
calculate the intersection with ray line
const Vector2D & center() const
get the center point
Definition: circle_2d.h:135
double radius() const
get the radius value
Definition: circle_2d.h:144
int intersection(const Circle2D &circle, Vector2D *sol1, Vector2D *sol2) const
calculate the intersection with another circle
const Circle2D & assign(const Vector2D &c, const double r)
assign new value.
Definition: circle_2d.h:96
static bool contains(const Vector2D &point, const Vector2D &p0, const Vector2D &p1, const Vector2D &p2)
check if the circumcircle contains the input point
Circle2D()
create a zero area circle at (0,0)
Definition: circle_2d.h:67
static Circle2D circumcircle(const Vector2D &p0, const Vector2D &p1, const Vector2D &p2)
get the circle through three points (circumcircle of the triangle).
2d straight line class
Definition: line_2d.h:47
2D ray line class
Definition: ray_2d.h:44
abstract 2D region class
Definition: region_2d.h:43
2d segment line class
Definition: segment_2d.h:46
2D point vector class
Definition: vector_2d.h:46
double dist2(const Vector2D &p) const
get the squared distance from this to 'p'.
Definition: vector_2d.h:347
abstract 2D region class Header File.
2d vector class Header File.