gammavol.c

Go to the documentation of this file.
00001 
00002 /****************************************************************************
00003 * MODULE:       R-Tree library 
00004 *              
00005 * AUTHOR(S):    Antonin Guttman - original code
00006 *               Daniel Green (green@superliminal.com) - major clean-up
00007 *                               and implementation of bounding spheres
00008 *               
00009 * PURPOSE:      Multidimensional index
00010 *
00011 * COPYRIGHT:    (C) 2001 by the GRASS Development Team
00012 *
00013 *               This program is free software under the GNU General Public
00014 *               License (>=v2). Read the file COPYING that comes with GRASS
00015 *               for details.
00016 *****************************************************************************/
00017 #include <stdio.h>
00018 #include <math.h>
00019 #include <grass/gis.h>
00020 
00021 #ifndef ABS
00022 #       define ABS(a) ((a) > 0 ? (a) : -(a))
00023 #endif
00024 
00025 #define EP .0000000001
00026 
00027 double sphere_volume(double dimension)
00028 {
00029     double log_gamma, log_volume;
00030 
00031     log_gamma = lgamma(dimension / 2.0 + 1);
00032     log_volume = dimension / 2.0 * log(M_PI) - log_gamma;
00033     return exp(log_volume);
00034 }
00035 
00036 int main()
00037 {
00038     double dim = 0, delta = 1;
00039 
00040     while (ABS(delta) > EP)
00041         if (sphere_volume(dim + delta) > sphere_volume(dim))
00042             dim += delta;
00043         else
00044             delta /= -2;
00045     fprintf(stdout, "max volume = %.10f at dimension %.10f\n",
00046             sphere_volume(dim), dim);
00047     return 0;
00048 }

Generated on Sat Oct 24 03:25:19 2009 for GRASS Programmer's Manual by  doxygen 1.6.1