/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        A R R A N G E M E N T   H A R M O N I E U X   D E   P O I N T S   S U R   L A   S P H E R E  :                             */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*             *     * * * * * *   * * * * * *   * * * * * *   *         *   * * * * * *   *   * * * * * *   *         *             */
/*                        *             *        *             **        *        *        *   *         *   **        *             */
/*            * *         *             *        *             * *       *        *        *   *         *   * *       *             */
/*                        *             *        *             *  *      *        *        *   *         *   *  *      *             */
/*           *   *        *             *        *             *   *     *        *        *   *         *   *   *     *             */
/*                        *             *        * * *         *    *    *        *        *   *         *   *    *    *             */
/*          * * * *       *             *        *             *     *   *        *        *   *         *   *     *   *             */
/*                        *             *        *             *      *  *        *        *   *         *   *      *  *             */
/*         *       *      *             *        *             *       * *        *        *   *         *   *       * *             */
/*                        *             *        *             *        **        *        *   *         *   *        **             */
/*        *         *     *             *        * * * * * *   *         *        *        *   * * * * * *   *         *             */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        ATTENTION :                                                                                                                */
/*                                                                                                                                   */
/*                    Les programmes 'v $xtc/PtsSphere.01$c'                                                                         */
/*                  et 'v $xtc/PtsSphere.02$c' ne donnent                                                                            */
/*                  exactement les memes resultats que s'ils                                                                         */
/*                  sont compiles avec l'option '-ffloat-store'.                                                                     */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        Author of '$xtc/PtsSphere.01$c' :                                                                                          */
/*                                                                                                                                   */
/*                    Jean-Francois Colonna (LACTAMME, 20080306150811).                                                              */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

#include  "INCLUDES.01.I"

extern    double    drand48();
extern    double    srand48();

#define   NOMBRE_DE_POINTS                                                                                                              \
                    26

#define   NOMBRE_D_ITERATIONS                                                                                                           \
                    1000000000

#define   RAYON_DE_LA_SPHERE_UNITE                                                                                                      \
                    1.0
                                        /* Definition de la sphere unite.                                                            */
#define   PONDERATION_0                                                                                                                 \
                    0.010
#define   PONDERATION_N                                                                                                                 \
                    (1.0*(1/(double)NOMBRE_D_ITERATIONS))
                                        /* Definition de l'interpolation...                                                          */

#define   RANDOM(inf,sup)                                                                                                               \
                    ((((sup)-(inf))*drand48())+(inf))

#define   DISTANCE_1(dx,dy,dz)                                                                                                          \
                    sqrt(EXP2(dx)+EXP2(dy)+EXP2(dz))
#define   DISTANCE_2(dx,dy,dz)                                                                                                          \
                    sqrt(EXP2(dx)+EXP2(dy)+EXP2(dz))
                                        /* Le 20080310105944, fut introduit 'DISTANCE_2(...)' afin de reduire les temps de           */
                                        /* calcul. Ainsi pour 1000000 :                                                              */
                                        /*                                                                                           */
                                        /*                  DISTANCE_2(dx,dy,dz)=sqrt(EXP2(dx)+EXP2(dy)+EXP2(dz))      : 24 secondes */
                                        /*                                                                                           */
                                        /* alors que :                                                                               */
                                        /*                                                                                           */
                                        /*                  DISTANCE_2(dx,dy,dz)=    (EXP2(dx)+EXP2(dy)+EXP2(dz))      : 13 secondes */
                                        /*                                                                                           */
                                        /* ce qui n'est pas negligeable...                                                           */

typedef   struct
          {
          double    x,y,z;
          }         points;

void      normalisation(point)
points    *point;
          {
          double    module=DISTANCE_1(point->x,point->y,point->z);

          point->x = RAYON_DE_LA_SPHERE_UNITE*((point->x)/module);
          point->y = RAYON_DE_LA_SPHERE_UNITE*((point->y)/module);
          point->z = RAYON_DE_LA_SPHERE_UNITE*((point->z)/module);
          }

main()
          {
          int       compatibilite_20080319100633=0;
          int       chercher_la_distance_minimale=VRAI;
          int       modifier_le_point_i_de_la_distance_minimale=VRAI;
          int       modifier_le_point_j_de_la_distance_minimale=VRAI;
          int       chercher_la_distance_maximale=VRAI;
          int       modifier_le_point_i_de_la_distance_maximale=VRAI;
          int       modifier_le_point_j_de_la_distance_maximale=VRAI;
                                        /* Indicateurs de controle divers...                                                         */

          int       n,p;
                                        /* Index divers...                                                                           */

          points    ListePoints[NOMBRE_DE_POINTS];

          if        (compatibilite_20080319100633 == 1)
                    {
                    }
          else
                    {
                    long int  graine=1;
                                        /* Il semblerait qu'utiliser une graine nulle soit une mauvaise idee comme cela se voit      */
                                        /* avec N=19...                                                                              */
                    srand48(graine);
                                        /* Introduit le 20080319100633 car, en effet, manquait...                                    */
                    }

          for       (p=0 ; p<NOMBRE_DE_POINTS ; p++)
                    {
                    ListePoints[p].x = RANDOM(-RAYON_DE_LA_SPHERE_UNITE,+RAYON_DE_LA_SPHERE_UNITE);
                    ListePoints[p].y = RANDOM(-RAYON_DE_LA_SPHERE_UNITE,+RAYON_DE_LA_SPHERE_UNITE);
                    ListePoints[p].z = RANDOM(-RAYON_DE_LA_SPHERE_UNITE,+RAYON_DE_LA_SPHERE_UNITE);
                                        /* Initialisation aleatoire du nuage de points a l'interieur du cube dans lequel la sphere   */
                                        /* unite est inscrite.                                                                       */

                    normalisation(&ListePoints[p]);
                                        /* Mise du nuage de points sur la surface de la sphere unite.                                */
                    }

          for       (n=1 ; n<=NOMBRE_D_ITERATIONS ; n++)
                    {
                    int       i,j;

                    int       distance_minimale_trouvee=FAUX;
                    double    distance_minimale=+1000;
                    int       min_i,min_j;
                    points    point_min_i,point_min_j;

                    int       distance_maximale_trouvee=FAUX;
                    double    distance_maximale=-1000;
                    int       max_i,max_j;
                    points    point_max_i,point_max_j;

                    double    ponderation=((double)((PONDERATION_0*(NOMBRE_D_ITERATIONS-n))+(PONDERATION_N*(n-1))))
                                          /((double)(NOMBRE_D_ITERATIONS-1)
                                           );

                    for       (i=0 ; i<NOMBRE_DE_POINTS ; i++)
                              {
                              for       (j=i+1 ; j<NOMBRE_DE_POINTS ; j++)
                                        {
                                        double    distance=DISTANCE_2(ListePoints[i].x-ListePoints[j].x
                                                                     ,ListePoints[i].y-ListePoints[j].y
                                                                     ,ListePoints[i].z-ListePoints[j].z
                                                                      );

                                        if        (chercher_la_distance_minimale == VRAI)
                                                  {
                                                  if        (distance < distance_minimale)
                                                            {
                                                            distance_minimale = distance;

                                                            min_i = i;
                                                            min_j = j;

                                                            distance_minimale_trouvee = VRAI;
                                        /* Recherche de la distance minimale.                                                        */
                                                            }
                                                  else
                                                            {
                                                            }
                                                  }
                                        else
                                                  {
                                                  }

                                        if        (chercher_la_distance_maximale == VRAI)
                                                  {
                                                  if        (distance > distance_maximale)
                                                            {
                                                            distance_maximale = distance;

                                                            max_i = i;
                                                            max_j = j;

                                                            distance_maximale_trouvee = VRAI;
                                        /* Recherche de la distance maximale.                                                        */
                                                            }
                                                  else
                                                            {
                                                            }
                                                  }
                                        else
                                                  {
                                                  }
                                        }
                              }

                    if        (distance_minimale_trouvee == VRAI)
                              {
                              point_min_i = ListePoints[min_i];
                              point_min_j = ListePoints[min_j];

                              if        (modifier_le_point_j_de_la_distance_minimale == VRAI)
                                        {
                                        ListePoints[min_j].x = point_min_j.x + ponderation*(point_min_j.x - point_min_i.x);
                                        ListePoints[min_j].y = point_min_j.y + ponderation*(point_min_j.y - point_min_i.y);
                                        ListePoints[min_j].z = point_min_j.z + ponderation*(point_min_j.z - point_min_i.z);
                                        normalisation(&ListePoints[min_j]);
                                        /* Augmentation de la distance minimale.                                                     */
                                        }
                              else
                                        {
                                        }

                              if        (modifier_le_point_i_de_la_distance_minimale == VRAI)
                                        {
                                        ListePoints[min_i].x = point_min_i.x - ponderation*(point_min_j.x - point_min_i.x);
                                        ListePoints[min_i].y = point_min_i.y - ponderation*(point_min_j.y - point_min_i.y);
                                        ListePoints[min_i].z = point_min_i.z - ponderation*(point_min_j.z - point_min_i.z);
                                        normalisation(&ListePoints[min_i]);
                                        /* Augmentation de la distance minimale.                                                     */
                                        }
                              else
                                        {
                                        }
                              }
                    else
                              {
                              }

                    if        (distance_maximale_trouvee == VRAI)
                              {
                              point_max_i = ListePoints[max_i];
                              point_max_j = ListePoints[max_j];

                                        /* La logique voudrait que ci-apres, on trouve dans cet ordre :                              */
                                        /*                                                                                           */
                                        /*                  -ponderation                                                             */
                                        /*                                                                                           */
                                        /* et :                                                                                      */
                                        /*                                                                                           */
                                        /*                  +ponderation                                                             */
                                        /*                                                                                           */
                                        /* relativement a 'distance_maximale' qu'on voudrait reduire, mais, malheureusement          */
                                        /* et paradoxalement, cela ne marche pas et les "conventions inverses" ameliorent les        */
                                        /* choses...                                                                                 */

                              if        (modifier_le_point_j_de_la_distance_maximale == VRAI)
                                        {
                                        ListePoints[max_j].x = point_max_j.x + ponderation*(point_max_j.x - point_max_i.x);
                                        ListePoints[max_j].y = point_max_j.y + ponderation*(point_max_j.y - point_max_i.y);
                                        ListePoints[max_j].z = point_max_j.z + ponderation*(point_max_j.z - point_max_i.z);
                                        normalisation(&ListePoints[max_j]);
                                        /* Augmentation (et non pas diminution !) de la distance maximale.                           */
                                        }
                              else
                                        {
                                        }

                              if        (modifier_le_point_i_de_la_distance_maximale == VRAI)
                                        {
                                        ListePoints[max_i].x = point_max_i.x - ponderation*(point_max_j.x - point_max_i.x);
                                        ListePoints[max_i].y = point_max_i.y - ponderation*(point_max_j.y - point_max_i.y);
                                        ListePoints[max_i].z = point_max_i.z - ponderation*(point_max_j.z - point_max_i.z);
                                        normalisation(&ListePoints[max_i]);
                                        /* Augmentation (et non pas diminution !) de la distance maximale.                           */
                                        }
                              else
                                        {
                                        }
                              }
                    else
                              {
                              }
                    }

          for       (p=0 ; p<NOMBRE_DE_POINTS ; p++)
                    {
                    printf("%+.16f %+.16f %+.16f\n",ListePoints[p].x,ListePoints[p].y,ListePoints[p].z);
                                        /* Edition des coordonees {X,Y,Z} resultantes...                                             */
                                        /*                                                                                           */
                                        /* Le 20080308164838, ce calcul pour 1000000000 iterations a donne les coordonnees           */
                                        /* suivantes :                                                                               */
                                        /*                                                                                           */
                                        /*                                                                                           */
                                        /*        :Debut_listG_xtc__PtsSphere_01_c__N26_1000000000:                                  */
                                        /*                                                                                           */
                                        /*                  +0.6305995759857794 +0.7612158737281595 -0.1513095117658836              */
                                        /*                  +0.6872243508285435 +0.5233576170172600 +0.5038050181749899              */
                                        /*                  +0.0663339047941786 +0.5644271420439312 +0.8228133533182824              */
                                        /*                  -0.4401094654292918 +0.8770237941320074 -0.1926990476516202              */
                                        /*                  -0.1454391861891323 -0.9504674648302709 +0.2746980914017435              */
                                        /*                  +0.3236762144259212 -0.0745037791392779 +0.9432300329765114              */
                                        /*                  -0.5266340307455665 +0.7023961354074492 +0.4788488974878800              */
                                        /*                  -0.6108779135070878 -0.5319401333885846 +0.5864024806221082              */
                                        /*                  -0.4894122869432521 -0.8119509560966254 -0.3181371689739376              */
                                        /*                  -0.4975035448912076 +0.4486796861732084 -0.7424127975972622              */
                                        /*                  -0.0552295897164148 -0.5782849329451138 -0.8139632846439829              */
                                        /*                  +0.9806296031475081 +0.1568290207158665 -0.1173466645970945              */
                                        /*                  +0.0945946705961166 +0.9637468827727044 +0.2494870622711876              */
                                        /*                  +0.8546037055073468 -0.1555181012905902 +0.4954458867566486              */
                                        /*                  +0.6342115268020814 +0.3279584450972228 -0.7001564093549274              */
                                        /*                  +0.6036644978481940 -0.3706060077699987 -0.7058614318989751              */
                                        /*                  -0.9132055053515924 +0.3621415047233783 -0.1868401336764406              */
                                        /*                  -0.3680457263863010 +0.0269256991543836 +0.9294177478474508              */
                                        /*                  +0.0466866986161308 +0.0894225712289771 -0.9948989676982910              */
                                        /*                  -0.6552981848549828 -0.2321302134298757 -0.7188183727053483              */
                                        /*                  +0.4080042645623137 -0.6818589074902772 +0.6071251521516227              */
                                        /*                  +0.8222505950105948 -0.5647236958045546 -0.0706477628914571              */
                                        /*                  +0.1061672212167088 +0.7789406404900755 -0.6180453055658893              */
                                        /*                  +0.2621252495809254 -0.9195870149641978 -0.2926603414222259              */
                                        /*                  -0.8818170993623027 +0.1003355224113081 +0.4607942992428452              */
                                        /*                  -0.9400712552955893 -0.3295209242444865 -0.0876469933998557              */
                                        /*                                                                                           */
                                        /*        :Fin_listG_xtc__PtsSphere_01_c__N26_1000000000:                                    */
                                        /*                                                                                           */
                                        /*                                                                                           */
                                        /* et les distances aux trois plus proches voisins suivantes :                               */
                                        /*                                                                                           */
                                        /*     d(00,12)=+0.69925529099624 d(00,14)=+0.69925529146779 d(00,01)=+0.69925529154322      */
                                        /*     d(01,00)=+0.69925529154322 d(01,13)=+0.69925529269271 d(01,02)=+0.69925529655024      */
                                        /*     d(02,17)=+0.69925529102451 d(02,12)=+0.69925529116713 d(02,06)=+0.69925529142275      */
                                        /*     d(03,16)=+0.69925529087008 d(03,09)=+0.69925529104870 d(03,06)=+0.69925529116044      */
                                        /*     d(04,20)=+0.69925529027298 d(04,07)=+0.69925529122796 d(04,23)=+0.69925529156737      */
                                        /*     d(05,17)=+0.69925529078330 d(05,13)=+0.69925529156775 d(05,20)=+0.69925529164131      */
                                        /*     d(06,03)=+0.69925529116044 d(06,24)=+0.69925529134293 d(06,02)=+0.69925529142275      */
                                        /*     d(07,04)=+0.69925529122796 d(07,24)=+0.69925529141972 d(07,17)=+0.69925529203252      */
                                        /*     d(08,10)=+0.69925529095393 d(08,25)=+0.69925529131028 d(08,04)=+0.69925529184902      */
                                        /*     d(09,16)=+0.69925529077393 d(09,18)=+0.69925529090520 d(09,03)=+0.69925529104870      */
                                        /*     d(10,08)=+0.69925529095393 d(10,18)=+0.69925529126365 d(10,19)=+0.69925529170830      */
                                        /*     d(11,14)=+0.69925529107233 d(11,13)=+0.69925529136100 d(11,00)=+0.69925529171881      */
                                        /*     d(12,00)=+0.69925529099624 d(12,02)=+0.69925529116713 d(12,03)=+0.69925529171736      */
                                        /*     d(13,11)=+0.69925529136100 d(13,21)=+0.69925529137237 d(13,05)=+0.69925529156775      */
                                        /*     d(14,11)=+0.69925529107233 d(14,18)=+0.69925529140351 d(14,22)=+0.69925529142649      */
                                        /*     d(15,14)=+0.69925529177105 d(15,21)=+0.69925529241799 d(15,10)=+0.69925529326305      */
                                        /*     d(16,09)=+0.69925529077393 d(16,03)=+0.69925529087008 d(16,24)=+0.69925529179808      */
                                        /*     d(17,05)=+0.69925529078330 d(17,02)=+0.69925529102451 d(17,24)=+0.69925529130807      */
                                        /*     d(18,09)=+0.69925529090520 d(18,10)=+0.69925529126365 d(18,14)=+0.69925529140351      */
                                        /*     d(19,25)=+0.69925529118881 d(19,10)=+0.69925529170830 d(19,09)=+0.69925529292587      */
                                        /*     d(20,04)=+0.69925529027298 d(20,05)=+0.69925529164131 d(20,13)=+0.69925529189454      */
                                        /*     d(21,13)=+0.69925529137237 d(21,23)=+0.69925529165219 d(21,15)=+0.69925529241799      */
                                        /*     d(22,03)=+0.69925529138002 d(22,14)=+0.69925529142649 d(22,09)=+0.69925529306097      */
                                        /*     d(23,04)=+0.69925529156737 d(23,21)=+0.69925529165219 d(23,10)=+0.69925529231295      */
                                        /*     d(24,17)=+0.69925529130807 d(24,06)=+0.69925529134293 d(24,07)=+0.69925529141972      */
                                        /*     d(25,19)=+0.69925529118881 d(25,08)=+0.69925529131028 d(25,24)=+0.69925529164293      */
                                        /*                                                                                           */
                    }
          }



Copyright © Jean-François Colonna, 2021-2023.
Copyright © CMAP (Centre de Mathématiques APpliquées) UMR CNRS 7641 / École polytechnique, Institut Polytechnique de Paris, 2021-2023.