DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ball3D.ih
1 
17 #pragma once
18 
32 
33 #include <cstdlib>
34 
36 
38 // IMPLEMENTATION of inline methods.
40 
42 // ----------------------- Standard services ------------------------------
43 typedef pair<double,double> AngularCoordinates;
47 template <typename T>
48 inline
50 {
51 }
52 
53 template <typename T>
54 inline
55 DGtal::Ball3D<T>::Ball3D(const double x0, const double y0, const double z0, const double radius):
56  myRadius(radius), myCenter(x0,y0,z0)
57 {}
58 
59 
60 template <typename T>
61 inline
62 DGtal::Ball3D<T>::Ball3D(const RealPoint &aPoint, const double radius):
63  myRadius(radius), myCenter(aPoint)
64 {}
65 
66 
68 // ------------- Implementation of 'StarShaped' services ------------------
69 
76 template <typename T>
77 inline
78 AngularCoordinates
80 {
81  RealPoint l( pp );
82  l -= myCenter;
83  AngularCoordinates angle ;
84 
85 
86 
87  if((fabs(l[0])<0.0001)&&(fabs(l[1])<0.0001))
88  {
89  angle.first=0;
90  if(l[2]>=0)
91  angle.second=0;
92  if(l[2]<0)
93  angle.second=M_PI;
94  }
95  else
96  {
97  if(l[1]>0)
98  angle.first=atan2(l[1],l[0]);
99  else
100  angle.first=atan2(l[1],l[0])+M_PI*2.0;
101  angle.second=acos(sqrt(l[2]*l[2])/sqrt(l[0]*l[0]+l[1]*l[1]+l[2]*l[2]));
102  }
103  return angle;
104 }
105 
112 template <typename T>
113 inline
116 {
117  RealPoint c( myRadius*cos(t.first)*sin(t.second), myRadius*sin(t.first)*sin(t.second) , myRadius*cos(t.second));
118  c += myCenter;
119  return c;
120 }
121 
122 
123 
129 template <typename T>
130 inline
133 {
134  RealPoint p= x(t);
135  double xx=2*(p[0]-myCenter[0]);
136  double yy =2*(p[1]-myCenter[1]);
137  double zz=2*(p[2]-myCenter[2]);
138  return RealPoint(xx,yy,zz);
139 }
140 
146 template <typename T>
147 inline
150 {
151  return RealPoint(-myRadius*sin(t.first)*sin(t.second),myRadius*cos(t.first)*sin(t.second),0);
152 }
153 
154 
155 
161 template <typename T>
162 inline
165 {
166  return RealPoint(myRadius*cos(t.first)*cos(t.second),myRadius*sin(t.first)*cos(t.second),-myRadius*sin(t.second));
167 }
168 
169 
175 template <typename T>
176 inline
179 {
180  return RealPoint(-myRadius*cos(t.first)*sin(t.second),-myRadius*sin(t.first)*sin(t.second),0);
181 }
182 
183 
184 
190 template <typename T>
191 inline
194 {
195  return RealPoint(-myRadius*cos(t.first)*sin(t.second),-myRadius*sin(t.first)*sin(t.second),-myRadius*cos(t.second));
196 }
197 
203 template <typename T>
204 inline
207 {
208  return RealPoint(-myRadius*sin(t.first)*cos(t.second),myRadius*cos(t.first)*cos(t.second),0);
209 }
210 
211 
212 
213 
215 // Interface - public :
216 
221 template <typename T>
222 inline
223 void
224 DGtal::Ball3D<T>::selfDisplay ( std::ostream & out ) const
225 {
226  out << "[Ball3D] center= "<<myCenter<<" radius="<<myRadius;
227 }
228 
233 template <typename T>
234 inline
235 bool
237 {
238  return true;
239 }
240 
241 
242 
243 
244 
246 // Implementation of inline functions //
247 
248 template <typename T>
249 inline
250 std::ostream&
251 DGtal::operator<< ( std::ostream & out,
252  const Ball3D<T> & object )
253 {
254  object.selfDisplay( out );
255  return out;
256 }
257 
258 // //