DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ball2D.ih
1 
30 
31 #include <cstdlib>
33 
35 // IMPLEMENTATION of inline methods.
37 
39 // ----------------------- Standard services ------------------------------
40 
44 template <typename T>
45 inline
47 {
48 }
49 
50 template <typename T>
51 inline
52 DGtal::Ball2D<T>::Ball2D(const double x0, const double y0, const double radius):
53  myRadius(radius), myCenter(x0,y0)
54 {}
55 
56 
57 template <typename T>
58 inline
59 DGtal::Ball2D<T>::Ball2D(const RealPoint2D &aPoint, const double radius):
60  myRadius(radius), myCenter(aPoint)
61 {}
62 
63 template <typename T>
64 inline
65 DGtal::Ball2D<T>::Ball2D(const Point &aPoint, const double radius):
66  myRadius(radius)
67 {
68  myCenter = aPoint;
69 }
70 
72 // ------------- Implementation of 'StarShaped' services ------------------
73 
80 template <typename T>
81 inline
82 double
84 {
85  RealPoint2D p( pp );
86  p -= myCenter;
87 
88  double angle = 0.0;
89  if ( ( p.at( 0 ) == 0.0 ) && ( p.at( 1 ) == 0.0 ) )
90  return angle;
91  if ( p.at( 0 ) >= p.at( 1 ) )
92  {
93  if ( p.at( 0 ) >= -p.at( 1 ) )
94  angle = atan( p.at( 1 ) / p.at( 0 ) );
95  else
96  angle = 1.5* M_PI + atan( - p.at( 0 ) / p.at( 1 ) );
97  }
98  else // ( p.at( 0 ) >= p.at( 1 ) )
99  {
100  if ( p.at( 0 ) >= -p.at( 1 ) )
101  angle = 0.5*M_PI - atan( p.at( 0 ) / p.at( 1 ) );
102  else
103  angle = M_PI + atan( p.at( 1 ) / p.at( 0 ) );
104  }
105  angle = ( angle < 0.0 ) ? angle + 2*M_PI : angle;
106  return angle;
107 }
108 
115 template <typename T>
116 inline
118 DGtal::Ball2D<T>::x( double t ) const
119 {
120  RealPoint2D c( myRadius*cos(t), myRadius*sin(t) );
121  c += myCenter;
122  return c;
123 }
124 
125 
132 template <typename T>
133 inline
135 DGtal::Ball2D<T>::xp( const double t ) const
136 {
137  RealVector2D c( -myRadius*sin(t), myRadius*cos(t) );
138  return c;
139 }
140 
146 template <typename T>
147 inline
149 DGtal::Ball2D<T>::xpp( const double t ) const
150 {
151  RealVector2D c( -myRadius*cos(t), -myRadius*sin(t) );
152  return c;
153 }
154 
155 
157 // Interface - public :
158 
163 template <typename T>
164 inline
165 void
166 DGtal::Ball2D<T>::selfDisplay ( std::ostream & out ) const
167 {
168  out << "[Ball2D] center= "<<myCenter<<" radius="<<myRadius;
169 }
170 
175 template <typename T>
176 inline
177 bool
179 {
180  return true;
181 }
182 
183 
184 
186 // Implementation of inline functions //
187 
188 template <typename T>
189 inline
190 std::ostream&
191 DGtal::operator<< ( std::ostream & out,
192  const Ball2D<T> & object )
193 {
194  object.selfDisplay( out );
195  return out;
196 }
197 
198 // //
200 
201