/*************************************************************************************************************************************/
/* */
/* 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 V I A U N E F O N C T I O N G E N E R A T R I C E */
/* N O N O P T I M I S E E : */
/* */
/* */
/* Author of '$xtc/SpiLogCar.11$c' : */
/* */
/* Jean-Francois COLONNA (LACTAMME, AAAAMMJJhhmmss). */
/* */
/*************************************************************************************************************************************/
#define OK 0
#define COTEs2 3
#define NUMERO0 0
#define DISTANCE0 0
#define DISTANCE2 ((COTEs2*COTEs2) + (COTEs2*COTEs2))
#define Xmin 0
#define Ymin 0
int compteur;
/* Numero du point courant. */
int distance2;
/* Definition du carre de la distance. */
int xa,ya;
/* Definition du couple {x,y} anterieur... */
int sortie;
/* Code de sortie... */
#define TEST(code,condition,X,Y) \
if (condition) \
{ \
if (compteur==numero) \
{ \
xc=X; \
yc=Y; \
\
if (validation[X+COTEs2][Y+COTEs2] == 0) \
{ \
validation[X+COTEs2][Y+COTEs2]++; \
} \
else \
{ \
printf("\n collision"); \
} \
\
iterer++; \
sortie=code; \
} \
else \
{ \
compteur++; \
} \
} \
else \
{ \
}
int validation[2*COTEs2+1][2*COTEs2+1];
/* Pour valider le travail... */
spirale(numero)
int numero;
{
int iterer=0;
int x,y;
/* Definition des coordonnees courantes. */
int xc,yc;
/* Definition des coordonnees courantes d'un point satisfaisant. */
compteur=NUMERO0;
distance2=DISTANCE0;
x=Xmin;
y=Xmin;
/* Positionnement sur la spirale. */
while (iterer==0)
{
if ((((x*x)+(y*y)) == distance2) && (x<=COTEs2) && (y<=COTEs2))
{
TEST(1,(iterer==0),x,y);
TEST(2,((iterer==0) && (x != Xmin)),Xmin-x,y);
TEST(3,((iterer==0) && ((x != Xmin) && (y != Ymin))),Xmin-x,Ymin-y);
TEST(4,((iterer==0) && (y != Ymin)),x,Ymin-y);
}
else
{
}
if (iterer==0)
{
x++;
if (x > COTEs2)
{
x=Xmin;
y++;
if (y > COTEs2)
{
y=Ymin;
distance2++;
}
else
{
}
}
else
{
}
}
else
{
}
}
xa=xc;
ya=yc;
return(OK);
}
main()
{
int n;
int numero;
int x,y;
/* Definition des coordonnees courantes. */
for (y=-COTEs2 ; y<=COTEs2 ; y++)
{
for (x=-COTEs2 ; x<=COTEs2 ; x++)
{
validation[x+COTEs2][y+COTEs2] = 0;
}
}
for (numero=NUMERO0 ; numero<(((COTEs2*2)+1)*((COTEs2*2)+1)) ; n++)
{
spirale(numero);
printf("\n(%+03d,%+03d)",xa,ya);
numero++;
}
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
{
} \
}
}
printf("\n");
}