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#define FLOWER2D_2_PI (2. * M_PI)
38///////////////////////////////////////////////////////////////////////////////
39// IMPLEMENTATION of inline methods.
40///////////////////////////////////////////////////////////////////////////////
42///////////////////////////////////////////////////////////////////////////////
43// ----------------------- Standard services ------------------------------
47DGtal::Flower2D<T>::Flower2D(const double x0, const double y0,
48 const double radius, const double varRadius,
49 const unsigned int k, const double phi)
50 : myCenter(x0,y0), myRadius(radius), myVarRadius(varRadius), myK(k),myPhi(phi)
56DGtal::Flower2D<T>::Flower2D(const RealPoint &aPoint, const double radius,
57 const double varRadius,
58 const unsigned int k, const double phi)
59 : myCenter(aPoint), myRadius(radius), myVarRadius(varRadius),
65DGtal::Flower2D<T>::Flower2D(const Flower2D& other)
66 : myCenter(other.myCenter), myRadius(other.myRadius),
67 myVarRadius(other.myVarRadius), myK(other.myK), myPhi(other.myPhi)
70/////////////////////////////////////////////////////////////////////////////
71// ------------- Implementation of 'StarShaped' services ------------------
74 * @param p any point in the plane.
76 * @return the angle parameter between 0 and 2*Pi corresponding to
77 * this point for the shape.
82DGtal::Flower2D<T>::parameter( const RealPoint & p ) const
84 const double angle = atan2( p[1]-myCenter[1], p[0]-myCenter[0] );
85 return angle < 0.0 ? angle + FLOWER2D_2_PI : angle;
89 * @param t any angle between 0 and 2*Pi.
91 * @return the vector (x(t),y(t)) which is the position on the
96typename DGtal::Flower2D<T>::RealPoint
97DGtal::Flower2D<T>::x( const double t ) const
99 const double r = myRadius + myVarRadius * cos(myK*t + myPhi);
101 r*cos(t) + myCenter[0],
102 r*sin(t) + myCenter[1]
108 * @param t any angle between 0 and 2*Pi.
110 * @return the vector (x'(t),y'(t)) which is the tangent to the
115typename DGtal::Flower2D<T>::RealVector
116DGtal::Flower2D<T>::xp( const double t ) const
118 const double r = myRadius + myVarRadius * cos(myK*t + myPhi);
119 const double rp = -myVarRadius * sin(myK*t + myPhi) * myK;
121 rp*cos(t) - r*sin(t),
127 * @param t any angle between 0 and 2*Pi.
129 * @return the vector (x''(t),y''(t)).
133typename DGtal::Flower2D<T>::RealVector
134DGtal::Flower2D<T>::xpp( const double t ) const
136 const double r = myRadius + myVarRadius * cos(myK*t + myPhi);
137 const double rp = -myVarRadius * sin(myK*t + myPhi) * myK;
138 const double rpp = -myVarRadius * cos(myK*t + myPhi) * myK * myK;
140 rpp*cos(t) - 2*rp*sin(t) - r*cos(t),
141 rpp*sin(t) + 2*rp*cos(t) - r*sin(t)
146///////////////////////////////////////////////////////////////////////////////
147// Interface - public :
150 * Writes/Displays the object on an output stream.
151 * @param out the output stream where the object is written.
156DGtal::Flower2D<T>::selfDisplay ( std::ostream & out ) const
158 out << "[Flower2D] center= " << myCenter
159 << " radius=" << myRadius
160 << " varRadius=" << myVarRadius
162 << " phase-shift=" << myPhi;
166 * Checks the validity/consistency of the object.
167 * @return 'true' if the object is valid, 'false' otherwise.
172DGtal::Flower2D<T>::isValid() const
179///////////////////////////////////////////////////////////////////////////////
180// Implementation of inline functions //
185DGtal::operator<< ( std::ostream & out,
186 const Flower2D<T> & object )
188 object.selfDisplay( out );
193///////////////////////////////////////////////////////////////////////////////