GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-f8115df121
gammavol.c
Go to the documentation of this file.
1 /****************************************************************************
2  * MODULE: R-Tree library
3  *
4  * AUTHOR(S): Antonin Guttman - original code
5  * Daniel Green (green@superliminal.com) - major clean-up
6  * and implementation of bounding spheres
7  * Markus Metz - file-based and memory-based R*-tree
8  *
9  * PURPOSE: Multidimensional index
10  *
11  * COPYRIGHT: (C) 2010 by the GRASS Development Team
12  *
13  * This program is free software under the GNU General Public
14  * License (>=v2). Read the file COPYING that comes with GRASS
15  * for details.
16  *****************************************************************************/
17 
18 #include <stdio.h>
19 #include <math.h>
20 
21 #ifndef ABS
22 #define ABS(a) ((a) > 0 ? (a) : -(a))
23 #endif
24 
25 #define EP .0000000001
26 
27 double sphere_volume(double dimension)
28 {
29  double log_gamma, log_volume;
30 
31  log_gamma = lgamma(dimension / 2.0 + 1);
32  log_volume = dimension / 2.0 * log(M_PI) - log_gamma;
33  return exp(log_volume);
34 }
35 
36 int main(void)
37 {
38  double dim = 0, delta = 1;
39 
40  while (ABS(delta) > EP)
41  if (sphere_volume(dim + delta) > sphere_volume(dim))
42  dim += delta;
43  else
44  delta /= -2;
45  fprintf(stdout, "max volume = %.10f at dimension %.10f\n",
46  sphere_volume(dim), dim);
47  return 0;
48 }
double sphere_volume(double dimension)
Definition: gammavol.c:27
int main(void)
Definition: gammavol.c:36
#define EP
Definition: gammavol.c:25
#define ABS(a)
Definition: gammavol.c:22
#define M_PI
Definition: gis.h:158