/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        C O N S T R U C T I O N   D ' U N E   S P I R A L E   L O G A R I T H M I Q U E                                            */
/*        S U R   U N   R E S E A U   C A R R E  :                                                                                   */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        Author of '$xtc/SpiLogCar.01$c' :                                                                                          */
/*                                                                                                                                   */
/*                    Jean-Francois Colonna (LACTAMME, AAAAMMJJhhmmss).                                                              */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

#define   OK        0

#define   COTEs2    3

#define   DISTANCE0 0
#define   DISTANCE2 ((COTEs2*COTEs2) + (COTEs2*COTEs2))

#define   Xmin      0
#define   Ymin      0

#define   TEST(code,condition,X,Y)                                                                                                      \
                    if        (condition)                                                                                               \
                              {                                                                                                         \
                              printf("  %d=(%+03d,%+03d)",code,X,Y);                                                                    \
                              compteur++;                                                                                               \
                              if        (validation[X+COTEs2][Y+COTEs2] == 0)                                                           \
                                        {                                                                                               \
                                        validation[X+COTEs2][Y+COTEs2]++;                                                               \
                                        }                                                                                               \
                              else                                                                                                      \
                                        {                                                                                               \
                                        printf("\n collision");                                                                         \
                                        }                                                                                               \
                              }                                                                                                         \
                    else                                                                                                                \
                              {                                                                                                         \
                              }

main()
          {
          int       distance2;
                                        /* Definition du carre de la distance.                                                       */
          int       x,y;
                                        /* Definition des coordonnees.                                                               */
          int       compteur=0;
                                        /* Compteur des points generes.                                                              */
          int       validation[2*COTEs2+1][2*COTEs2+1];
                                        /* Pour valider le travail...                                                                */

          for       (y=-COTEs2 ; y<=COTEs2 ; y++)
                    {
                    for       (x=-COTEs2 ; x<=COTEs2 ; x++)
                              {
                              validation[x+COTEs2][y+COTEs2] = 0;
                              }
                    }

          for       (distance2=DISTANCE0 ; distance2<=DISTANCE2 ; distance2++)
                    {
                    int       changer=0;
                    for       (y=Ymin ; y<=COTEs2 ; y++)
                              {
                              for       (x=Xmin ; x<=COTEs2 ; x++)
                                        {
                                        if        ((((x*x)+(y*y)) == distance2) && (x<=COTEs2) && (y<=COTEs2))
                                                  {
                                                  if        (changer==0)
                                                            {
                                                            printf("\n carre de la distance=%04d ",distance2);
                                                            changer++;
                                                            }
                                                  else
                                                            {
                                                            }

                                                  TEST(1,(OK==OK),x,y);
                                                  TEST(2,(x != Xmin),Xmin-x,y);
                                                  TEST(3,((x != Xmin) && (y != Ymin)),Xmin-x,Ymin-y);
                                                  TEST(4,(y != Ymin),x,Ymin-y);
                                                  }
                                        else
                                                  {
                                                  }
                                        }
                              }
                    }

          printf("\n nombre de points=%d\n",compteur);

          if        (compteur != ((2*COTEs2)+1)*((2*COTEs2)+1))
                    {
                    printf("\n le nombre de points n'est pas un carre");
                    compteur++;
                    }
          else
                    {
                    }

          for       (y=-COTEs2 ; y<=COTEs2 ; y++)
                    {
                    for       (x=-COTEs2 ; x<=COTEs2 ; x++)
                              {
                              if        (validation[x+COTEs2][y+COTEs2] != 1)
                                        {
                                        printf("\n absence ou collision");
                                        }
                              else
                                        {
                                        }                                                                                               \
                              }
                    }
          }



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.