gammavol.c

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

Generated on Sun Apr 6 17:32:44 2008 for GRASS by  doxygen 1.5.5