83 #define BIGNUMBER 100000000.0 85 static inline void Set(
double *n,
double x,
double y,
double z)
92 static inline void Copy(
double *dest,
const double *source)
122 for (
unsigned i=0; i<vcount; i++)
124 const double *caller_p = &points[i*3];
126 if (caller_p[0]<xmin[0])
128 if (caller_p[0]>xmax[0])
130 if (caller_p[1]<ymin[1])
132 if (caller_p[1]>ymax[1])
134 if (caller_p[2]<zmin[2])
136 if (caller_p[2]>zmax[2])
141 double dx = xmax[0] - xmin[0];
142 double dy = xmax[1] - xmin[1];
143 double dz = xmax[2] - xmin[2];
144 double xspan = dx*dx + dy*dy + dz*dz;
147 dx = ymax[0] - ymin[0];
148 dy = ymax[1] - ymin[1];
149 dz = ymax[2] - ymin[2];
150 double yspan = dx*dx + dy*dy + dz*dz;
152 dx = zmax[0] - zmin[0];
153 dy = zmax[1] - zmin[1];
154 dz = zmax[2] - zmin[2];
155 double zspan = dx*dx + dy*dy + dz*dz;
160 double maxspan = xspan;
178 center[0] = (dia1[0]+dia2[0])*0.5f;
179 center[1] = (dia1[1]+dia2[1])*0.5f;
180 center[2] = (dia1[2]+dia2[2])*0.5f;
184 dx = dia2[0]-center[0];
185 dy = dia2[1]-center[1];
186 dz = dia2[2]-center[2];
188 mRadius2 = dx*dx + dy*dy + dz*dz;
189 mRadius = double(sqrt(mRadius2));
194 for (
unsigned i=0; i<vcount; i++)
196 const double *caller_p = &points[i*3];
198 dx = caller_p[0]-center[0];
199 dy = caller_p[1]-center[1];
200 dz = caller_p[2]-center[2];
202 double old_to_p_sq = dx*dx + dy*dy + dz*dz;
204 if (old_to_p_sq > mRadius2)
206 double old_to_p = double(sqrt(old_to_p_sq));
208 mRadius = (mRadius + old_to_p) * 0.5f;
209 mRadius2 = mRadius*mRadius;
210 double old_to_new = old_to_p - mRadius;
214 double recip = 1.0f /old_to_p;
216 double cx = (mRadius*center[0] + old_to_new*caller_p[0]) * recip;
217 double cy = (mRadius*center[1] + old_to_new*caller_p[1]) * recip;
218 double cz = (mRadius*center[2] + old_to_new*caller_p[2]) * recip;
220 Set(center,cx,cy,cz);
228 static inline void Set(
float *n,
float x,
float y,
float z)
235 static inline void Copy(
float *dest,
const float *source)
266 for (
unsigned i=0; i<vcount; i++)
268 const float *caller_p = &points[i*3];
270 if (caller_p[0]<xmin[0])
272 if (caller_p[0]>xmax[0])
274 if (caller_p[1]<ymin[1])
276 if (caller_p[1]>ymax[1])
278 if (caller_p[2]<zmin[2])
280 if (caller_p[2]>zmax[2])
285 float dx = xmax[0] - xmin[0];
286 float dy = xmax[1] - xmin[1];
287 float dz = xmax[2] - xmin[2];
288 float xspan = dx*dx + dy*dy + dz*dz;
291 dx = ymax[0] - ymin[0];
292 dy = ymax[1] - ymin[1];
293 dz = ymax[2] - ymin[2];
294 float yspan = dx*dx + dy*dy + dz*dz;
296 dx = zmax[0] - zmin[0];
297 dy = zmax[1] - zmin[1];
298 dz = zmax[2] - zmin[2];
299 float zspan = dx*dx + dy*dy + dz*dz;
304 float maxspan = xspan;
322 center[0] = (dia1[0]+dia2[0])*0.5f;
323 center[1] = (dia1[1]+dia2[1])*0.5f;
324 center[2] = (dia1[2]+dia2[2])*0.5f;
328 dx = dia2[0]-center[0];
329 dy = dia2[1]-center[1];
330 dz = dia2[2]-center[2];
332 mRadius2 = dx*dx + dy*dy + dz*dz;
333 mRadius = float(sqrt(mRadius2));
338 for (
unsigned i=0; i<vcount; i++)
340 const float *caller_p = &points[i*3];
342 dx = caller_p[0]-center[0];
343 dy = caller_p[1]-center[1];
344 dz = caller_p[2]-center[2];
346 float old_to_p_sq = dx*dx + dy*dy + dz*dz;
348 if (old_to_p_sq > mRadius2)
350 float old_to_p = float(sqrt(old_to_p_sq));
352 mRadius = (mRadius + old_to_p) * 0.5f;
353 mRadius2 = mRadius*mRadius;
354 float old_to_new = old_to_p - mRadius;
358 float recip = 1.0f /old_to_p;
360 float cx = (mRadius*center[0] + old_to_new*caller_p[0]) * recip;
361 float cy = (mRadius*center[1] + old_to_new*caller_p[1]) * recip;
362 float cz = (mRadius*center[2] + old_to_new*caller_p[2]) * recip;
364 Set(center,cx,cy,cz);
375 return (4.0f*3.141592654f*r*r*r)/3.0f;
static void Copy(double *dest, const double *source)
double computeSphereVolume(double r)
double computeBoundingSphere(unsigned int vcount, const double *points, double *center)
static void Set(double *n, double x, double y, double z)