GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
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
}
main
int main()
Definition:
gammavol.c:36
M_PI
#define M_PI
Definition:
gis.h:144
sphere_volume
double sphere_volume(double dimension)
Definition:
gammavol.c:27
EP
#define EP
Definition:
gammavol.c:25
ABS
#define ABS(a)
Definition:
gammavol.c:22
lib
vector
rtree
gammavol.c
Generated on Tue Feb 14 2023 05:55:59 for GRASS GIS 8 Programmer's Manual by
1.8.13