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/>.
18 * @file Lemniscate2D.ih
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 Lemniscate2D.h
26 * This file is part of the DGtal library.
29///////////////////////////////////////////////////////////////////////////////
31///////////////////////////////////////////////////////////////////////////////
33#define LEMNISCATE2D_3_PI_2 (3. * M_PI / 2.)
35///////////////////////////////////////////////////////////////////////////////
36// IMPLEMENTATION of inline methods.
37///////////////////////////////////////////////////////////////////////////////
39///////////////////////////////////////////////////////////////////////////////
40// ----------------------- Standard services ----------------------------------
44DGtal::Lemniscate2D<T>::Lemniscate2D( const double x0, const double y0,
45 const double a ) : myCenter(x0,y0), myA(fabs(a))
50DGtal::Lemniscate2D<T>::Lemniscate2D( const RealPoint &aPoint,
51 const double a ) : myCenter(aPoint), myA(fabs(a))
56DGtal::Lemniscate2D<T>::Lemniscate2D(const Lemniscate2D& other ) :
57 myCenter(other.myCenter), myA(other.myA)
60///////////////////////////////////////////////////////////////////////////////
61// ------------- Implementation of 'StarShaped' services ----------------------
64 * @param pp any point in the plane.
66 * @return the angle parameter between 0 and 2*Pi corresponding to
67 * this point for the shape.
72DGtal::Lemniscate2D<T>::parameter( const RealPoint& pp ) const
74 const RealPoint p( pp-myCenter );
77 if ( fabs(p[0]) < fabs(p[1]) )
79 else if ( isAlmostEqual(p[0],0.) )
80 angle = p[1] < 0. ? M_PI : 0.;
81 else if ( isAlmostEqual(p[1],0.) )
82 angle = p[0] > 0. ? M_PI_2 : LEMNISCATE2D_3_PI_2;
84 angle = acos(p[1]/p[0]);
90 * @param t any angle between 0 and 2*Pi.
92 * @return the vector (x(t),y(t)) which is the position on the
97typename DGtal::Lemniscate2D<T>::RealPoint
98DGtal::Lemniscate2D<T>::x( const double t ) const
100 const double cost = cos(t);
101 const double sint = sin(t);
102 const double cos2t = pow(cost,2);
104 myA * sint / (1. + cos2t) + myCenter[0],
105 myA * sint * cost / (1. + cos2t) + myCenter[1]
111 * @param t any angle between 0 and 2*Pi.
113 * @return the vector (x'(t),y'(t)) which is the tangent to the
118typename DGtal::Lemniscate2D<T>::RealVector
119DGtal::Lemniscate2D<T>::xp( const double t ) const
121 const double cost = cos(t);
122 const double cos2t = pow(cost,2);
123 const double sin2t = pow(sin(t),2);
126 myA * (cost + 2*sin2t*cost+pow(cost,3)) / pow(1+cos2t,2),
127 myA * (pow(cost,4) + cos2t - sin2t + sin2t * cos2t)
133typename DGtal::Lemniscate2D<T>::RealVector
134DGtal::Lemniscate2D<T>::xpp( const double t ) const
136 const double cost = cos(t);
137 const double cos2t = pow(cost,2);
138 const double sint = sin(t);
139 const double sin3t = pow(sint,3);
142 myA * ( 4 * sin3t * cos2t +
143 6 * sin3t * pow(cost,4) +
146 9 * sint * pow(cost,4) +
147 5 * pow(cost,6) * sint -
151 myA * ( -4* sin3t * pow(cost,3) -
153 2 * sin3t * pow(cost,5) -
155 6 * sint * pow(cost,3) +
156 2 * sint * pow(cost,7) )
162///////////////////////////////////////////////////////////////////////////////
163// Interface - public :
166 * Writes/Displays the object on an output stream.
167 * @param out the output stream where the object is written.
172DGtal::Lemniscate2D<T>::selfDisplay ( std::ostream & out ) const
174 out << "[Lemniscate2D] center= " << myCenter
179 * Checks the validity/consistency of the object.
180 * @return 'true' if the object is valid, 'false' otherwise.
185DGtal::Lemniscate2D<T>::isValid() const
191///////////////////////////////////////////////////////////////////////////////
192// Implementation of inline functions //
197DGtal::operator<< ( std::ostream & out,
198 const Lemniscate2D<T> & object )
200 object.selfDisplay( out );
205///////////////////////////////////////////////////////////////////////////////