GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
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 * SPDX-FileCopyrightText: 2010 GRASS Development Team
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *****************************************************************************/
14
15#include <stdio.h>
16#include <math.h>
17
18#ifndef ABS
19#define ABS(a) ((a) > 0 ? (a) : -(a))
20#endif
21
22#define EP .0000000001
23
24double sphere_volume(double dimension)
25{
26 double log_gamma, log_volume;
27
28 log_gamma = lgamma(dimension / 2.0 + 1);
29 log_volume = dimension / 2.0 * log(M_PI) - log_gamma;
30 return exp(log_volume);
31}
32
33int main(void)
34{
35 double dim = 0, delta = 1;
36
37 while (ABS(delta) > EP)
38 if (sphere_volume(dim + delta) > sphere_volume(dim))
39 dim += delta;
40 else
41 delta /= -2;
42 fprintf(stdout, "max volume = %.10f at dimension %.10f\n",
43 sphere_volume(dim), dim);
44 return 0;
45}
double sphere_volume(double dimension)
Definition gammavol.c:24
int main(void)
Definition gammavol.c:33
#define EP
Definition gammavol.c:22
#define ABS(a)
Definition gammavol.c:19
#define M_PI
Definition gis.h:154