2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Implementation of inline methods defined in Ball2D.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 #define BALL2D_2_PI (2. * M_PI)
36 ///////////////////////////////////////////////////////////////////////////////
37 // IMPLEMENTATION of inline methods.
38 ///////////////////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////////
41 // ----------------------- Standard services ------------------------------
45 DGtal::Ball2D<T>::Ball2D(const double x0, const double y0, const double radius):
46 myRadius(radius), myCenter(x0,y0)
52 DGtal::Ball2D<T>::Ball2D(const RealPoint &aPoint, const double radius):
53 myRadius(radius), myCenter(aPoint)
58 DGtal::Ball2D<T>::Ball2D(const Ball2D &other):
59 myCenter(other.myCenter), myRadius(other.myRadius)
62 /////////////////////////////////////////////////////////////////////////////
63 // ------------- Implementation of 'StarShaped' services ------------------
66 * @param p any point in the plane.
68 * @return the angle parameter between 0 and 2*Pi corresponding to
69 * this point for the shape.
74 DGtal::Ball2D<T>::parameter( const RealPoint & p ) const
76 const double angle = atan2(p[1]-myCenter[1], p[0]-myCenter[0]);
77 return angle < 0. ? angle + BALL2D_2_PI : angle;
81 * @param t any angle between 0 and 2*Pi.
83 * @return the vector (x(t),y(t)) which is the position on the
88 typename DGtal::Ball2D<T>::RealPoint
89 DGtal::Ball2D<T>::x( const double t ) const
91 return RealPoint( myRadius*cos(t)+myCenter[0], myRadius*sin(t)+myCenter[1] );
96 * @param t any angle between 0 and 2*Pi.
98 * @return the vector (x'(t),y'(t)) which is the tangent to the
101 template <typename T>
103 typename DGtal::Ball2D<T>::RealVector
104 DGtal::Ball2D<T>::xp( const double t ) const
106 return RealVector( -myRadius*sin(t), myRadius*cos(t) );
110 * @param t any angle between 0 and 2*Pi.
112 * @return the vector (x''(t),y''(t)).
114 template <typename T>
116 typename DGtal::Ball2D<T>::RealVector
117 DGtal::Ball2D<T>::xpp( const double t ) const
119 return RealVector( -myRadius*cos(t), -myRadius*sin(t) );
123 ///////////////////////////////////////////////////////////////////////////////
124 // Interface - public :
127 * Writes/Displays the object on an output stream.
128 * @param out the output stream where the object is written.
130 template <typename T>
133 DGtal::Ball2D<T>::selfDisplay ( std::ostream & out ) const
135 out << "[Ball2D] center= " << myCenter
136 << " radius=" << myRadius;
140 * Checks the validity/consistency of the object.
141 * @return 'true' if the object is valid, 'false' otherwise.
143 template <typename T>
146 DGtal::Ball2D<T>::isValid() const
153 ///////////////////////////////////////////////////////////////////////////////
154 // Implementation of inline functions //
156 template <typename T>
159 DGtal::operator<< ( std::ostream & out,
160 const Ball2D<T> & object )
162 object.selfDisplay( out );
167 ///////////////////////////////////////////////////////////////////////////////