DGtal  1.5.beta
Ellipse2D.h
1 
17 #pragma once
18 
33 #if defined(Ellipse2D_RECURSES)
34 #error Recursive header files inclusion detected in Ellipse2D.h
35 #else // defined(Ellipse2D_RECURSES)
37 #define Ellipse2D_RECURSES
38 
39 #if !defined Ellipse2D_h
41 #define Ellipse2D_h
42 
44 // Inclusions
45 #include <iostream>
46 #include "DGtal/base/Common.h"
47 #include "DGtal/shapes/parametric/StarShaped2D.h"
48 #include <cmath>
50 
51 namespace DGtal
52 {
53 
55  // template class Ellipse2D
63  template <typename TSpace>
64  class Ellipse2D final: public StarShaped2D<TSpace>
65  {
66  // ----------------------- Standard services ------------------------------
67  public:
68 
69  typedef TSpace Space;
70  typedef typename Space::RealPoint RealPoint;
71  typedef typename Space::RealVector RealVector;
72 
77  Ellipse2D() = delete;
78 
87  Ellipse2D( const double x0, const double y0,
88  const double a0, const double a1, const double theta );
89 
98  const double a0, const double a1, const double theta );
99 
104  Ellipse2D( const Ellipse2D& other );
105 
112  Ellipse2D& operator=( const Ellipse2D& other ) = delete;
113 
117  ~Ellipse2D() = default;
118 
119  // ------------- Implementation of 'StarShaped' services ------------------
120  public:
121 
127  {
128  return myCenter - myAxis1;
129  }
130 
136  {
137  return myCenter + myAxis1;
138  }
139 
144  {
145  return myCenter;
146  }
147 
152  inline
153  void moveTo( const RealPoint& newCenter )
154  {
155  myCenter = newCenter;
156  }
157 
164  double parameter( const RealPoint & p ) const;
165 
166 
173  RealPoint x( const double t ) const;
174 
181  RealVector xp( const double t ) const;
182 
188  RealVector xpp( const double t ) const;
189 
190 
191  // ------------------------- data ----------------------------
192  private:
193 
198 
202  double myAxis1;
203 
204 
208  double myAxis2;
209 
213  double myTheta;
214 
215  // ----------------------- Interface --------------------------------------
216  public:
217 
222  void selfDisplay ( std::ostream & out ) const;
223 
228  bool isValid() const;
229 
230  // ------------------------- Hidden services ------------------------------
231  private:
232 
236  template <typename T>
237  inline
238  bool isAlmostEqual( T x, T y ) const
239  {
240  return std::abs(x - y) <= std::numeric_limits<T>::epsilon();
241  }
242 
243  }; // end of class Ellipse2D
244 
245 
252  template <typename T>
253  std::ostream&
254  operator<< ( std::ostream & out, const Ellipse2D<T> & object );
255 
256 } // namespace DGtal
257 
258 
260 // Includes inline functions.
261 #include "DGtal/shapes/parametric/Ellipse2D.ih"
262 
263 // //
265 
266 #endif // !defined Ellipse2D_h
267 
268 #undef Ellipse2D_RECURSES
269 #endif // else defined(Ellipse2D_RECURSES)
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition: Ellipse2D.h:65
RealVector xpp(const double t) const
RealPoint getLowerBound() const
Definition: Ellipse2D.h:126
void selfDisplay(std::ostream &out) const
RealPoint getUpperBound() const
Definition: Ellipse2D.h:135
Ellipse2D()=delete
Ellipse2D & operator=(const Ellipse2D &other)=delete
bool isValid() const
RealPoint myCenter
Definition: Ellipse2D.h:197
Ellipse2D(const double x0, const double y0, const double a0, const double a1, const double theta)
Space::RealVector RealVector
Definition: Ellipse2D.h:71
RealPoint x(const double t) const
Ellipse2D(const RealPoint &aPoint, const double a0, const double a1, const double theta)
RealVector xp(const double t) const
void moveTo(const RealPoint &newCenter)
Definition: Ellipse2D.h:153
Space::RealPoint RealPoint
Definition: Ellipse2D.h:70
RealPoint center() const
Definition: Ellipse2D.h:143
bool isAlmostEqual(T x, T y) const
Definition: Ellipse2D.h:238
Ellipse2D(const Ellipse2D &other)
~Ellipse2D()=default
double parameter(const RealPoint &p) const
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
const Point aPoint(3, 4)
PointVector< 3, double > RealPoint