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 Ellipse2D.h
28 * This file is part of the DGtal library.
32//////////////////////////////////////////////////////////////////////////////
34//////////////////////////////////////////////////////////////////////////////
36///////////////////////////////////////////////////////////////////////////////
37// IMPLEMENTATION of inline methods.
38///////////////////////////////////////////////////////////////////////////////
40#define ELLIPSE2D_3_PI_2 (1.5*M_PI)
41#define ELLIPSE2D_2_PI (2.*M_PI)
43///////////////////////////////////////////////////////////////////////////////
44// ----------------------- Standard services ------------------------------
48DGtal::Ellipse2D<T>::Ellipse2D(const double x0, const double y0,
49 const double a0, const double a1, const double theta)
50 : myCenter(x0,y0), myAxis1(a0), myAxis2(a1), myTheta(theta)
55DGtal::Ellipse2D<T>::Ellipse2D(const RealPoint &aPoint,
56 const double a0, const double a1, const double theta)
57 : myCenter(aPoint), myAxis1(a0), myAxis2(a1), myTheta(theta)
62DGtal::Ellipse2D<T>::Ellipse2D(const Ellipse2D& other)
63 : myCenter(other.myCenter), myAxis1(other.myAxis1),
64 myAxis2(other.myAxis2), myTheta(other.myTheta)
67/////////////////////////////////////////////////////////////////////////////
68// ------------- Implementation of 'StarShaped' services ------------------
71 * @param pp any point in the plane.
73 * @return the angle parameter between 0 and 2*Pi corresponding to
74 * this point for the shape.
79DGtal::Ellipse2D<T>::parameter( const RealPoint & pp ) const
81 RealPoint v2d( pp - myCenter );
85 if ( isAlmostEqual(v2d[0],0.) )
86 angle = v2d[1] > 0. ? M_PI_2 : ELLIPSE2D_3_PI_2;
87 else if ( v2d[0] > 0. )
88 angle = atan(v2d[1]/v2d[0]) + (v2d[1] < 0. ? ELLIPSE2D_2_PI : 0.);
90 angle = atan(v2d[1]/v2d[0]) + M_PI;
96 * @param t any angle between 0 and 2*Pi.
98 * @return the vector (x(t),y(t)) which is the position on the
103typename DGtal::Ellipse2D<T>::RealPoint
104DGtal::Ellipse2D<T>::x( const double t ) const
106 const double a2 = myAxis1*myAxis1;
107 const double b2 = myAxis2*myAxis2;
108 const double costth = cos(t - myTheta);
109 const double rho = myAxis2 / sqrt(1. - (a2-b2) / a2 * costth * costth);
112 rho * cos(t) + myCenter[0],
113 rho * sin(t) + myCenter[1] );
118 * @param t any angle between 0 and 2*Pi.
120 * @return the vector (x'(t),y'(t)) which is the tangent to the
125typename DGtal::Ellipse2D<T>::RealVector
126DGtal::Ellipse2D<T>::xp( const double t ) const
128 const double a2 = myAxis1 * myAxis1;
129 const double b2 = myAxis2 * myAxis2;
130 const double costth = cos(t - myTheta);
131 const double sintth = sin(t - myTheta);
132 const double cost = cos(t);
133 const double sint = sin(t);
134 const double rho = myAxis2 / sqrt(1. - (a2-b2) / a2 * costth * costth);
135 const double rhod = myAxis1 * myAxis2 * (b2-a2) * sintth * costth
136 / std::pow(a2 * sintth * sintth + b2 * costth * costth, 1.5);
139 rhod*cost - rho*sint,
145 * @param t any angle between 0 and 2*Pi.
147 * @return the vector (x''(t),y''(t)).
151typename DGtal::Ellipse2D<T>::RealVector
152DGtal::Ellipse2D<T>::xpp( const double t ) const
154 const double a2 = myAxis1 * myAxis1;
155 const double b2 = myAxis2 * myAxis2;
156 const double costth = cos(t - myTheta);
157 const double sintth = sin(t - myTheta);
158 const double cost = cos(t);
159 const double sint = sin(t);
160 const double rho = myAxis2 / sqrt( 1. - (a2-b2)/a2*costth*costth);
162 const double rhod = myAxis1 * myAxis2 * (b2-a2) * sintth * costth
163 / std::pow( a2*sintth*sintth + b2*costth*costth, 1.5 );
164 const double rhodd = myAxis1 * myAxis2 * (b2-a2)
165 / std::pow( a2*sintth*sintth + b2*costth*costth, 2.5 )
166 * ( (costth*costth - sintth*sintth) * (a2*sintth*sintth + b2*costth*costth)
167 + 3.*(b2-a2)*sintth*sintth*costth*costth );
170 rhodd*cost - 2.*rhod*sint - rho*cost,
171 rhodd*sint + 2.*rhod*cost - rho*sint
176///////////////////////////////////////////////////////////////////////////////
177// Interface - public :
180 * Writes/Displays the object on an output stream.
181 * @param out the output stream where the object is written.
186DGtal::Ellipse2D<T>::selfDisplay ( std::ostream & out ) const
188 out << "[Ellipse2D] center= " << myCenter
189 << " big axis=" << myAxis1
190 << " small axis=" << myAxis2
191 << " phase=" << myTheta;
195 * Checks the validity/consistency of the object.
196 * @return 'true' if the object is valid, 'false' otherwise.
201DGtal::Ellipse2D<T>::isValid() const
208///////////////////////////////////////////////////////////////////////////////
209// Implementation of inline functions //
214DGtal::operator<< ( std::ostream & out,
215 const Ellipse2D<T> & object )
217 object.selfDisplay( out );
222///////////////////////////////////////////////////////////////////////////////