GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71806
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gammavol.c
Go to the documentation of this file.
1 
2 /****************************************************************************
3 * MODULE: R-Tree library
4 *
5 * AUTHOR(S): Antonin Guttman - original code
6 * Daniel Green (green@superliminal.com) - major clean-up
7 * and implementation of bounding spheres
8 * Markus Metz - file-based and memory-based R*-tree
9 *
10 * PURPOSE: Multidimensional index
11 *
12 * COPYRIGHT: (C) 2010 by the GRASS Development Team
13 *
14 * This program is free software under the GNU General Public
15 * License (>=v2). Read the file COPYING that comes with GRASS
16 * for details.
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()
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 }
int main(int argc, char *argv[])
Definition: main.c:27
#define M_PI
Definition: gis.h:115
double sphere_volume(double dimension)
Definition: gammavol.c:27
#define EP
Definition: gammavol.c:25
#define ABS(a)
Definition: gammavol.c:22