DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Flower2D.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::Flower2D<T>::Flower2D(const double x0, const double y0,
55  const double radius, const double varRadius,
56  const unsigned int k, const double phi)
57  : myCenter(x0,y0), myRadius(radius), myVarRadius(varRadius), myK(k),myPhi(phi)
58 {}
59 
60 
61 template <typename T>
62 inline
63 DGtal::Flower2D<T>::Flower2D(const RealPoint2D &aPoint, const double radius,
64  const double varRadius,
65  const unsigned int k, const double phi)
66  : myCenter(aPoint), myRadius(radius), myVarRadius(varRadius),
67  myK(k), myPhi(phi)
68 {}
69 
70 template <typename T>
71 inline
72 DGtal::Flower2D<T>::Flower2D(const Point &aPoint, const double radius,
73  const double varRadius,
74  const unsigned int k, const double phi)
75  : myRadius(radius),myVarRadius(varRadius),myK(k),myPhi(phi)
76 {
77  myCenter = aPoint;
78 }
79 
81 // ------------- Implementation of 'StarShaped' services ------------------
82 
89 template <typename T>
90 inline
91 double
93 {
94  RealPoint2D p( pp );
95  p -= myCenter;
96 
97  double angle = 0.0;
98  if ( ( p.at( 0 ) == 0.0 ) && ( p.at( 1 ) == 0.0 ) )
99  return angle;
100 
101 /*
102  if ( p.at( 0 ) >= p.at( 1 ) )
103  {
104  if ( p.at( 0 ) >= -p.at( 1 ) )
105  angle = atan( p.at( 1 ) / p.at( 0 ) );
106  else
107  angle = 1.5* M_PI + atan( - p.at( 0 ) / p.at( 1 ) );
108  }
109  else // ( p.at( 0 ) >= p.at( 1 ) )
110  {
111  if ( p.at( 0 ) >= -p.at( 1 ) )
112  angle = 0.5*M_PI - atan( p.at( 0 ) / p.at( 1 ) );
113  else
114  angle = M_PI + atan( p.at( 1 ) / p.at( 0 ) );
115  }
116  angle = ( angle < 0.0 ) ? angle + 2*M_PI : angle;
117 */
118  angle = atan2( p.at( 1 ), p.at( 0 ) ) + M_PI;
119  return angle;
120 }
121 
128 template <typename T>
129 inline
131 DGtal::Flower2D<T>::x( double t ) const
132 {
133  double r= myRadius+ myVarRadius*cos(myK*t + myPhi);
134  RealPoint2D c( r*cos(t), r*sin(t) );
135  c += myCenter;
136  return c;
137 }
138 
139 
146 template <typename T>
147 inline
149 DGtal::Flower2D<T>::xp( const double t ) const
150 {
151  double r= myRadius+ myVarRadius*cos(myK*t + myPhi);
152  double rp = - myVarRadius * sin( myK * t + myPhi ) * myK;
153  RealVector2D c( rp*cos(t) - r*sin(t),rp*sin(t) + r*cos(t) );
154  return c;
155 }
156 
162 template <typename T>
163 inline
165 DGtal::Flower2D<T>::xpp( const double t ) const
166 {
167  double r= myRadius+ myVarRadius*cos(myK*t + myPhi);
168  double rp = - myVarRadius * sin( myK * t + myPhi ) * myK;
169  double rpp = - myVarRadius * cos( myK * t + myPhi ) * myK * myK;
170  RealVector2D c(rpp * cos( t ) - 2 * rp * sin( t ) - r * cos( t ),
171  rpp * sin( t ) + 2 * rp * cos( t ) - r * sin( t ) );
172  return c;
173 }
174 
175 
177 // Interface - public :
178 
183 template <typename T>
184 inline
185 void
186 DGtal::Flower2D<T>::selfDisplay ( std::ostream & out ) const
187 {
188  out << "[Flower2D] center= "<<myCenter<<" radius="<<myRadius<<" varRadius="<<myVarRadius
189  <<" myK="<<myK<<" phase-shift="<<myPhi;
190 }
191 
196 template <typename T>
197 inline
198 bool
200 {
201  return true;
202 }
203 
204 
205 
207 // Implementation of inline functions //
208 
209 template <typename T>
210 inline
211 std::ostream&
212 DGtal::operator<< ( std::ostream & out,
213  const Flower2D<T> & object )
214 {
215  object.selfDisplay( out );
216  return out;
217 }
218 
219 // //
221 
222