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 Chouaib Fellah, Adrien Krähenbühl (\c krahenbuhl@unistra.fr )
20 * Laboratoire des sciences de l'ingénieur, de l'informatique et de l'imagerie - ICube (UMR 7357), France
24 * Implementation of inline methods defined in Astroid2D.h
26 * This file is part of the DGtal library.
29 ///////////////////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////////////////
33 #define ASTROID_3_PI_2 (3. * M_PI_2)
34 #define ASTROID_2_PI (2. * M_PI)
36 ///////////////////////////////////////////////////////////////////////////////
37 // IMPLEMENTATION of inline methods.
38 ///////////////////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////////
41 // ----------------------- Standard services ----------------------------------
45 DGtal::Astroid2D<T>::Astroid2D( const double x0, const double y0,
46 const double a, const double b ) : myCenter(x0,y0), myA(fabs(a)), myB(fabs(b))
51 DGtal::Astroid2D<T>::Astroid2D( const RealPoint &aPoint,
52 const double a, const double b ) : myCenter(aPoint), myA(fabs(a)), myB(fabs(b))
57 DGtal::Astroid2D<T>::Astroid2D( const Astroid2D& other ) :
58 myCenter(other.myCenter), myA(other.myA), myB(other.myB)
61 ///////////////////////////////////////////////////////////////////////////////
62 // ------------- Implementation of 'StarShaped' services ----------------------
65 * @param pp any point in the plane.
67 * @return the angle parameter between 0 and 2*Pi corresponding to
68 * this point for the shape.
73 DGtal::Astroid2D<T>::parameter( const RealPoint & pp ) const
75 const RealPoint p( pp - myCenter );
78 if ( isAlmostEqual(p[0],0.) )
79 angle = p[1] > 0. ? M_PI_2 : ASTROID_3_PI_2;
80 else if ( isAlmostEqual(p[1],0.) )
81 angle = p[0] > 0. ? 0. : M_PI;
82 else if ( ! isAlmostEqual(myB,0.) )
85 angle = atan(-pow(-(myA*p[1])/(myB*p[0]) , 1/3.))
86 + (p[0] > 0. ? ASTROID_2_PI : M_PI);
88 angle = atan(pow(( myA*p[1])/(myB*p[0]) , 1/3.));
95 * @param t any angle between 0 and 2*Pi.
97 * @return the vector (x(t),y(t)) which is the position on the
100 template <typename T>
102 typename DGtal::Astroid2D<T>::RealPoint
103 DGtal::Astroid2D<T>::x( const double t ) const
105 return RealPoint( myA*pow(cos(t),3), myB*pow(sin(t),3) ) + myCenter;
110 * @param t any angle between 0 and 2*Pi.
112 * @return the vector (x'(t),y'(t)) which is the tangent to the
115 template <typename T>
117 typename DGtal::Astroid2D<T>::RealVector
118 DGtal::Astroid2D<T>::xp( const double t ) const
121 return RealVector( myA * 3*(-sin(t))*pow(cos(t),2),
122 myB * 3*cos(t)*pow(sin(t),2) );
125 template <typename T>
127 typename DGtal::Astroid2D<T>::RealVector
128 DGtal::Astroid2D<T>::xpp( const double t ) const
130 return RealVector( -myA * 3*pow(cos(t),3) + 6*pow(sin(t),2)*cos(t),
131 myB * (6*pow(cos(t),2)*sin(t) - 3*pow(sin(t),3)) );
135 ///////////////////////////////////////////////////////////////////////////////
136 // Interface - public :
139 * Writes/Displays the object on an output stream.
140 * @param out the output stream where the object is written.
142 template <typename T>
145 DGtal::Astroid2D<T>::selfDisplay ( std::ostream & out ) const
147 out << "[Astroid2D] center= " << myCenter
153 * Checks the validity/consistency of the object.
154 * @return 'true' if the object is valid, 'false' otherwise.
156 template <typename T>
159 DGtal::Astroid2D<T>::isValid() const
165 ///////////////////////////////////////////////////////////////////////////////
166 // Implementation of inline functions //
168 template <typename T>
171 DGtal::operator<< ( std::ostream & out,
172 const Astroid2D<T> & object )
174 object.selfDisplay( out );
179 ///////////////////////////////////////////////////////////////////////////////