DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarShaped2D.ih
1 
30 
31 #include <cstdlib>
33 
35 // IMPLEMENTATION of inline methods.
37 
39 // ----------------------- Standard services ------------------------------
40 
41 
43 // ------------------------- star-shaped services -------------------------
44 
45 
52 template<typename TSpace>
53 inline
54 bool
56 {
57 
60 
61  return this->isInside(prel);
62 }
63 
64 
71 template<typename TSpace>
72 inline
73 bool
75 {
76  double t = parameter( p );
77  RealPoint x_rel = x( t );
78  x_rel -= center();
79  double d_x = x_rel[0]*x_rel[0] + x_rel[1]*x_rel[1];
80  RealPoint p_rel( p );
81  p_rel -= center();
82  double d_p = p_rel[0]*p_rel[0] + p_rel[1]*p_rel[1];
83 
84  return d_p <= d_x;
85 }
86 
93 template<typename TSpace>
94 inline
97 {
98  double t = parameter( p );
99  RealPoint x_rel = x( t );
100  x_rel -= center();
101  double d_x = x_rel[0]*x_rel[0] + x_rel[1]*x_rel[1];
102  RealPoint p_rel( p );
103  p_rel -= center();
104  double d_p = p_rel[0]*p_rel[0] + p_rel[1]*p_rel[1];
105 
106  if (d_p - d_x > 0.0)
107  return OUTSIDE;
108  else
109  if (d_p - d_x < 0.0)
110  return INSIDE;
111  else
112  return ON;
113 }
114 
115 
122 template<typename TSpace>
123 inline
126 {
127  RealPoint tgt( xp( t ) );
128  double norm = tgt.norm();
129  tgt /= norm;
130  return tgt;
131 }
132 
133 
140 template<typename TSpace>
141 inline
144 {
145  RealPoint tgt( tangent( t ) );
146  return RealPoint( -tgt[1], tgt[0]);
147 }
148 
149 
157 template<typename TSpace>
158 inline
159 double
161 {
162  RealPoint tgt( xp( t ) );
163  RealPoint dt( xpp( t ) );
164  double norm = tgt.norm();
165  double curv = ( dt[0] * tgt[1] - dt[1] * tgt[0] ) / ( norm * norm * norm );
166  return - curv;
167 }
168 
169 
176 template<typename TSpace>
177 inline
178 double
179 DGtal::StarShaped2D<TSpace>::arclength( double t1, double t2, unsigned int nb ) const
180 {
181  while ( t2 < t1 ) t2 += 2.0*M_PI;
182 
183  RealPoint x0( x( t1 ) );
184  double l = 0.0;
185  // JOL 2008/08/28
186  for ( unsigned int i = 1; i <= nb; ++i )
187  {
188  double t = ( ( t2 - t1 ) * i ) / nb;
189  RealPoint x1( x( t1 + t ) );
190  l += sqrt( ( x1[0] - x0[0] )*( x1[0] - x0[0] )
191  + ( x1[1] - x0[1] )*( x1[1] - x0[1] ) );
192  x0 = x1;
193  }
194  return l;
195 }
196 
197 
198 
202 template <typename T>
203 inline
205 {
206 }
207 
209 // Interface - public :
210 
215 template <typename T>
216 inline
217 void
218 DGtal::StarShaped2D<T>::selfDisplay ( std::ostream & out ) const
219 {
220  out << "[StarShaped2D]";
221 }
222 
227 template <typename T>
228 inline
229 bool
231 {
232  return true;
233 }
234 
235 
236 
238 // Implementation of inline functions //
239 
240 template <typename T>
241 inline
242 std::ostream&
243 DGtal::operator<< ( std::ostream & out,
244  const StarShaped2D<T> & object )
245 {
246  object.selfDisplay( out );
247  return out;
248 }
249 
250 // //
252 
253