circle_2d.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa Akiyama
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_GEOM_CIRCLE2D_H
00033 #define RCSC_GEOM_CIRCLE2D_H
00034 
00035 #include <iostream>
00036 
00037 #include <rcsc/geom/vector_2d.h>
00038 
00039 namespace rcsc {
00040 
00041 class Line2D;
00042 class Ray2D;
00043 
00048 class Circle2D {
00049 private:
00050 
00052     Vector2D M_center;
00053 
00055     double M_radius;
00056 
00057     static const double EPSILON;
00058 
00059 
00060 public:
00064     Circle2D()
00065         : M_center( 0.0, 0.0 )
00066         , M_radius( 0.0 )
00067       { }
00068 
00074     Circle2D( const Vector2D & c,
00075               const double & r )
00076         : M_center( c )
00077         , M_radius( r )
00078       {
00079           if ( r < 0.0 )
00080           {
00081               std::cerr << "Circle2D::Circle2D(). radius must be positive value."
00082                         << std::endl;
00083               M_radius = 0.0;
00084           }
00085       }
00086 
00093     const
00094     Circle2D & assign( const Vector2D & c,
00095                        const double & r )
00096       {
00097           M_center = c;
00098           M_radius = r;
00099           if ( r < 0.0 )
00100           {
00101               std::cerr << "Circle2D::assign(). radius must be positive value."
00102                         << std::endl;
00103               M_radius = 0.0;
00104           }
00105           return *this;
00106       }
00107 
00113     bool contains( const Vector2D & point ) const
00114       {
00115           return M_center.dist2( point ) < M_radius * M_radius;
00116       }
00117 
00122     const
00123     Vector2D & center() const
00124       {
00125           return M_center;
00126       }
00127 
00132     const
00133     double & radius() const
00134       {
00135           return M_radius;
00136       }
00137 
00145     int intersection( const Line2D & line,
00146                       Vector2D * sol1,
00147                       Vector2D * sol2 ) const;
00148 
00156     int intersection( const Ray2D & ray,
00157                       Vector2D * sol1,
00158                       Vector2D * sol2 ) const;
00159 
00167     int intersection( const Circle2D & circle,
00168                       Vector2D * sol1,
00169                       Vector2D * sol2 ) const;
00170 
00171     // static utility
00172 
00180     static
00181     Circle2D circumcircle( const Vector2D & a,
00182                            const Vector2D & b,
00183                            const Vector2D & c );
00184 };
00185 
00186 }
00187 
00188 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0