DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ellipse2D.ih
1 
32 
33 #include <cstdlib>
35 
37 // IMPLEMENTATION of inline methods.
39 
41 // ----------------------- Standard services ------------------------------
42 
46 template <typename T>
47 inline
49 {
50 }
51 
52 template <typename T>
53 inline
54 DGtal::Ellipse2D<T>::Ellipse2D(const double x0, const double y0,
55  const double a0, const double a1, const double theta)
56  : myCenter(x0,y0), myAxis1(a0),myAxis2(a1),myTheta(theta)
57 {}
58 
59 
60 template <typename T>
61 inline
63  const double a0, const double a1, const double theta)
64  : myCenter(aPoint), myAxis1(a0),myAxis2(a1),myTheta(theta)
65 {}
66 
67 template <typename T>
68 inline
70  const double a0, const double a1, const double theta)
71  : myAxis1(a0),myAxis2(a1),myTheta(theta)
72 {
73  myCenter = aPoint;
74 }
75 
77 // ------------- Implementation of 'StarShaped' services ------------------
78 
85 template <typename T>
86 inline
87 double
89 {
90  RealPoint2D v2d( pp );
91  v2d -= myCenter;
92 
93  double angle;
94 
95  if ( v2d[0] == 0.0 )
96  {
97  if ( v2d[1] >0 )
98  angle = M_PI/2.0;
99  else
100  angle = 1.5*M_PI;
101  }
102  else if ( ( v2d[0] > 0.0 ) && ( v2d[1] >= 0.0 ) )
103  angle = atan(v2d[1]/v2d[0]);
104  else if ( ( v2d[0] > 0.0 ) && ( v2d[1] <= 0.0 ) )
105  angle = 2*M_PI + atan(v2d[1]/v2d[0]);
106  else if ( ( v2d[0] < 0.0 ) && ( v2d[1] >= 0.0 ) )
107  angle = atan(v2d[1]/v2d[0]) + M_PI;
108  else // ( ( v2d[0] < 0.0 ) && ( v2d[1] <= 0.0 ) )
109  angle = atan(v2d[1]/v2d[0]) + M_PI;
110 
111  return angle;
112 }
113 
120 template <typename T>
121 inline
123 DGtal::Ellipse2D<T>::x( double t ) const
124 {
125  double a2 = myAxis1*myAxis1;
126  double b2 = myAxis2*myAxis2;
127  double costth = cos( t - myTheta );
128  // double sintth = sin( t - myTheta );
129  double cost = cos( t );
130  double sint = sin( t );
131  double rho = myAxis2 / sqrt( 1.0 - ((a2-b2)/a2)*costth*costth);
132  //myAxis2*myAxis1 / sqrt( a2 - (a2-b2)*costth*costth);
133  RealPoint2D v( rho*cost,
134  rho*sint );
135  v += myCenter;
136  return v;
137 }
138 
139 
146 template <typename T>
147 inline
149 DGtal::Ellipse2D<T>::xp( const double t ) const
150 {
151  double a2 = myAxis1*myAxis1;
152  double b2 = myAxis2*myAxis2;
153  double costth = cos( t - myTheta );
154  double sintth = sin( t - myTheta );
155  double cost = cos( t );
156  double sint = sin( t );
157  double rho = myAxis2 / sqrt( 1.0 - ((a2-b2)/a2)*costth*costth);
158  double a = myAxis1;
159  double b = myAxis2;
160  double rhod= a*b*(b2-a2)*sintth*costth
161  / std::pow( a2*sintth*sintth + b2*costth*costth, 1.5 );
162  RealPoint2D v( rhod*cost - rho*sint, rhod*sint + rho*cost );
163 
164  return v;
165 }
166 
172 template <typename T>
173 inline
175 DGtal::Ellipse2D<T>::xpp( const double t ) const
176 {
177  double a2 = myAxis1*myAxis1;
178  double b2 = myAxis2*myAxis2;
179  double costth = cos( t - myTheta );
180  double sintth = sin( t - myTheta );
181  double cost = cos( t );
182  double sint = sin( t );
183  double rho = myAxis2 / sqrt( 1.0 - ((a2-b2)/a2)*costth*costth);
184 
185  double a = myAxis1;
186  double b = myAxis2;
187  double rhod = a*b*(b2-a2)*sintth*costth
188  / std::pow( a2*sintth*sintth + b2*costth*costth, 1.5 );
189  double rhodd = a*b*(b2-a2)
190  / std::pow( a2*sintth*sintth + b2*costth*costth, 2.5 )
191  * ( (costth*costth - sintth*sintth) * (a2*sintth*sintth + b2*costth*costth)
192  + 3.0*(b2-a2)*sintth*sintth*costth*costth );
193 
194  RealPoint2D v( rhodd*cost - 2.0*rhod*sint - rho*cost,
195  rhodd*sint + 2.0*rhod*cost - rho*sint );
196  return v;
197 }
198 
199 
201 // Interface - public :
202 
207 template <typename T>
208 inline
209 void
210 DGtal::Ellipse2D<T>::selfDisplay ( std::ostream & out ) const
211 {
212  out << "[Ellipse2D] center= "<<myCenter<<" big axis="<<myAxis1
213  <<" small axis="<<myAxis2<<" phase="<<myTheta;
214 }
215 
220 template <typename T>
221 inline
222 bool
224 {
225  return true;
226 }
227 
228 
229 
231 // Implementation of inline functions //
232 
233 template <typename T>
234 inline
235 std::ostream&
236 DGtal::operator<< ( std::ostream & out,
237  const Ellipse2D<T> & object )
238 {
239  object.selfDisplay( out );
240  return out;
241 }
242 
243 // //
245 
246