DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AccFlower2D.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::AccFlower2D<T>::AccFlower2D(const double x0, const double y0,
55  const double radius, const double smallRadius,
56  const unsigned int k, const double phi)
57  : myCenter(x0,y0), myRadius(radius), myVarRadius(smallRadius),
58  myK(k), myPhi(phi)
59 {
60  myKp = 2 * myK/ ( M_PI * M_PI );
61 }
62 
63 
64 template <typename T>
65 inline
66 DGtal::AccFlower2D<T>::AccFlower2D(const RealPoint2D &aPoint, const double radius,
67  const double smallRadius,
68  const unsigned int k, const double phi)
69  : myCenter(aPoint), myRadius(radius), myVarRadius(smallRadius),
70  myK(k), myPhi(phi)
71 {
72  myKp = 2 * myK/ ( M_PI * M_PI );
73 }
74 
75 template <typename T>
76 inline
77 DGtal::AccFlower2D<T>::AccFlower2D(const Point &aPoint, const double radius,
78  const double smallRadius,
79  const unsigned int k, const double phi)
80  : myRadius(radius), myVarRadius(smallRadius), myK(k), myPhi(phi)
81 {
82  myCenter = aPoint;
83  myKp = 2 * myK/ ( M_PI * M_PI );
84 }
85 
87 // ------------- Implementation of 'StarShaped' services ------------------
88 
95 template <typename T>
96 inline
97 double
99 {
100  RealPoint2D p( pp );
101  p -= myCenter;
102 
103  double angle = 0.0;
104  if ( ( p.at( 0 ) == 0.0 ) && ( p.at( 1 ) == 0.0 ) )
105  return angle;
106 
107  if ( p.at( 0 ) >= p.at( 1 ) )
108  {
109  if ( p.at( 0 ) >= -p.at( 1 ) )
110  angle = atan( p.at( 1 ) / p.at( 0 ) );
111  else
112  angle = 1.5* M_PI + atan( - p.at( 0 ) / p.at( 1 ) );
113  }
114  else // ( p.at( 0 ) >= p.at( 1 ) )
115  {
116  if ( p.at( 0 ) >= -p.at( 1 ) )
117  angle = 0.5*M_PI - atan( p.at( 0 ) / p.at( 1 ) );
118  else
119  angle = M_PI + atan( p.at( 1 ) / p.at( 0 ) );
120  }
121  angle = ( angle < 0.0 ) ? angle + 2*M_PI : angle;
122  return angle;
123 }
124 
131 template <typename T>
132 inline
134 DGtal::AccFlower2D<T>::x(const double t ) const
135 {
136  double tt =t;
137  while ( tt >= M_PI ) tt -= 2 * M_PI;
138  while ( tt < -M_PI ) tt += 2 * M_PI;
139 
140  double ktn = myKp * tt * tt * tt;
141  double r = myRadius + myVarRadius * cos( ktn );
142  RealPoint2D c( r * cos( tt ), r * sin( tt ) );
143  c += myCenter;
144  return c;
145 }
146 
147 
154 template <typename T>
155 inline
157 DGtal::AccFlower2D<T>::xp( const double tt ) const
158 {
159  double t= tt;
160  while ( t >= M_PI ) t -= 2 * M_PI;
161  while ( t < -M_PI ) t += 2 * M_PI;
162 
163  double ktn = myKp * t * t * t;
164  double ktnp = 3 * myKp * t * t ;
165 
166  double r = myRadius + myVarRadius * cos( ktn );
167  double rp = - myVarRadius * sin( ktn ) * ktnp;
168  RealPoint2D c( rp * cos( t ) - r * sin( t ),
169  rp * sin( t ) + r * cos( t ) );
170  return c;
171 }
172 
178 template <typename T>
179 inline
181 DGtal::AccFlower2D<T>::xpp( const double tt ) const
182 {
183  double t=tt;
184  while ( t >= M_PI ) t -= 2 * M_PI;
185  while ( t < -M_PI ) t += 2 * M_PI;
186 
187  double ktn = myKp * t * t * t;
188  double ktnp = 3 * myKp * t * t;
189  double ktnpp = 6 * myKp * t;
190 
191  double r = myRadius + myVarRadius * cos( ktn );
192  double rp = - myVarRadius * sin( ktn ) * ktnp;
193  double rpp = - myVarRadius * cos( ktn ) * ktnp * ktnp -
194  myVarRadius * sin( ktn ) * ktnpp;
195 
196  RealPoint2D c( rpp * cos( t ) - 2 * rp * sin( t ) - r * cos( t ),
197  rpp * sin( t ) + 2 * rp * cos( t ) - r * sin( t ) );
198  return c;
199 }
200 
201 
203 // Interface - public :
204 
209 template <typename T>
210 inline
211 void
212 DGtal::AccFlower2D<T>::selfDisplay ( std::ostream & out ) const
213 {
214  out << "[AccFlower2D] center= "<<myCenter<<" radius="<<myRadius<<" smallradius="<<myVarRadius
215  <<" myK="<<myK<<" phase-shift="<<myPhi;
216 }
217 
222 template <typename T>
223 inline
224 bool
226 {
227  return true;
228 }
229 
230 
231 
233 // Implementation of inline functions //
234 
235 template <typename T>
236 inline
237 std::ostream&
238 DGtal::operator<< ( std::ostream & out,
239  const AccFlower2D<T> & object )
240 {
241  object.selfDisplay( out );
242  return out;
243 }
244 
245 // //
247 
248