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
21 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
22 * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
26 * Implementation of inline methods defined in Flower2D.h
28 * This file is part of the DGtal library.
32 //////////////////////////////////////////////////////////////////////////////
34 //////////////////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////////
37 // IMPLEMENTATION of inline methods.
38 ///////////////////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////////////////
41 // ----------------------- Standard services ------------------------------
48 DGtal::Flower2D<T>::~Flower2D()
54 DGtal::Flower2D<T>::Flower2D(const double x0, const double y0,
55 const double radius, const double varRadius,
56 const unsigned int k, const double phi)
57 : myCenter(x0,y0), myRadius(radius), myVarRadius(varRadius), myK(k),myPhi(phi)
63 DGtal::Flower2D<T>::Flower2D(const RealPoint2D &aPoint, const double radius,
64 const double varRadius,
65 const unsigned int k, const double phi)
66 : myCenter(aPoint), myRadius(radius), myVarRadius(varRadius),
72 DGtal::Flower2D<T>::Flower2D(const Point &aPoint, const double radius,
73 const double varRadius,
74 const unsigned int k, const double phi)
75 : myRadius(radius),myVarRadius(varRadius),myK(k),myPhi(phi)
80 /////////////////////////////////////////////////////////////////////////////
81 // ------------- Implementation of 'StarShaped' services ------------------
84 * @param p any point in the plane.
86 * @return the angle parameter between 0 and 2*Pi corresponding to
87 * this point for the shape.
92 DGtal::Flower2D<T>::parameter( const RealPoint2D & pp ) const
97 double angle = atan2( p[1], p[0] );
98 angle = ( angle < 0.0 ) ? angle + 2*M_PI : angle;
104 * @param t any angle between 0 and 2*Pi.
106 * @return the vector (x(t),y(t)) which is the position on the
109 template <typename T>
111 typename DGtal::Flower2D<T>::RealPoint2D
112 DGtal::Flower2D<T>::x( double t ) const
114 double r= myRadius+ myVarRadius*cos(myK*t + myPhi);
115 RealPoint2D c( r*cos(t), r*sin(t) );
122 * @param t any angle between 0 and 2*Pi.
124 * @return the vector (x'(t),y'(t)) which is the tangent to the
127 template <typename T>
129 typename DGtal::Flower2D<T>::RealVector2D
130 DGtal::Flower2D<T>::xp( const double t ) const
132 double r= myRadius+ myVarRadius*cos(myK*t + myPhi);
133 double rp = - myVarRadius * sin( myK * t + myPhi ) * myK;
134 RealVector2D c( rp*cos(t) - r*sin(t),rp*sin(t) + r*cos(t) );
139 * @param t any angle between 0 and 2*Pi.
141 * @return the vector (x''(t),y''(t)).
143 template <typename T>
145 typename DGtal::Flower2D<T>::RealVector2D
146 DGtal::Flower2D<T>::xpp( const double t ) const
148 double r= myRadius+ myVarRadius*cos(myK*t + myPhi);
149 double rp = - myVarRadius * sin( myK * t + myPhi ) * myK;
150 double rpp = - myVarRadius * cos( myK * t + myPhi ) * myK * myK;
151 RealVector2D c(rpp * cos( t ) - 2 * rp * sin( t ) - r * cos( t ),
152 rpp * sin( t ) + 2 * rp * cos( t ) - r * sin( t ) );
157 ///////////////////////////////////////////////////////////////////////////////
158 // Interface - public :
161 * Writes/Displays the object on an output stream.
162 * @param out the output stream where the object is written.
164 template <typename T>
167 DGtal::Flower2D<T>::selfDisplay ( std::ostream & out ) const
169 out << "[Flower2D] center= "<<myCenter<<" radius="<<myRadius<<" varRadius="<<myVarRadius
170 <<" myK="<<myK<<" phase-shift="<<myPhi;
174 * Checks the validity/consistency of the object.
175 * @return 'true' if the object is valid, 'false' otherwise.
177 template <typename T>
180 DGtal::Flower2D<T>::isValid() const
187 ///////////////////////////////////////////////////////////////////////////////
188 // Implementation of inline functions //
190 template <typename T>
193 DGtal::operator<< ( std::ostream & out,
194 const Flower2D<T> & object )
196 object.selfDisplay( out );
201 ///////////////////////////////////////////////////////////////////////////////