/*************************************************************************************************************************************/
/* */
/* 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 */
/* O P T I M I S E E : */
/* */
/* */
/* Author of '$xtc/SpiLogCar.12$c' : */
/* */
/* Jean-Francois COLONNA (LACTAMME, AAAAMMJJhhmmss). */
/* */
/*************************************************************************************************************************************/
#include <stdio.h>
/* Introduit le 20140820183519... */
#define OK 0
#define COTEs2 3
/* Ce qui fait une spirale (2x3+1)^2 pour ce test... */
#define NUMERO0 0
#define DISTANCE0 0
#define DISTANCE2 ((COTEs2*COTEs2) + (COTEs2*COTEs2))
#define Xmin 0
#define Ymin 0
int initialisation=0;
/* Indicateur d'initialisation. */
int compteur;
/* Numero du point courant. */
int distance2;
/* Definition du carre de la distance. */
int Xcourant,Ycourant;
/* Definition des coordonnees courantes. */
int Xanterieur,Yanterieur;
/* Definition du couple {x,y} anterieur... */
int CodeSortie;
/* Code de sortie... */
#define TEST(code,condition,X,Y) \
if (condition) \
{ \
CodeSortie=0; \
Xsatisfaisant=X; \
Ysatisfaisant=Y; \
\
if (compteur==numero) \
{ \
if (validation[X+COTEs2][Y+COTEs2] == 0) \
{ \
validation[X+COTEs2][Y+COTEs2]++; \
} \
else \
{ \
printf("\n collision"); \
} \
\
iterer++; \
CodeSortie=code; \
} \
else \
{ \
} \
compteur++; \
} \
else \
{ \
}
int validation[2*COTEs2+1][2*COTEs2+1];
/* Pour valider le travail... */
spirale(numero)
int numero;
{
int iterer=0;
int Xsatisfaisant,Ysatisfaisant;
/* Definition des coordonnees courantes d'un point satisfaisant. */
if (initialisation==0)
{
compteur=NUMERO0;
distance2=DISTANCE0;
Xcourant=Xmin;
Ycourant=Xmin;
CodeSortie=0;
initialisation++;
}
else
{
}
if (numero>=(((COTEs2*2)+1)*((COTEs2*2)+1)))
{
printf("\n ATTENTION, le numero demande est trop grand, le processus va boucler...");
}
else
{
}
while (iterer==0)
{
if ((((Xcourant*Xcourant)+(Ycourant*Ycourant)) == distance2) && (Xcourant<=COTEs2) && (Ycourant<=COTEs2))
{
TEST(1
,(((CodeSortie==0) || (CodeSortie==4)) && (iterer==0))
,Xcourant
,Ycourant
);
TEST(2
,(((CodeSortie==0) || (CodeSortie<=1)) && ((iterer==0) && (Xcourant != Xmin)))
,Xmin-Xcourant
,Ycourant
);
TEST(3
,(((CodeSortie==0) || (CodeSortie<=2)) && ((iterer==0) && ((Xcourant != Xmin) && (Ycourant != Ymin))))
,Xmin-Xcourant
,Ymin-Ycourant
);
TEST(4
,(((CodeSortie==0) || (CodeSortie<=3)) && ((iterer==0) && (Ycourant != Ymin)))
,Xcourant
,Ymin-Ycourant
);
}
else
{
}
if ((iterer==0) || ((iterer!=0) && (CodeSortie==4)))
{
CodeSortie=0;
Xcourant++;
if (Xcourant > COTEs2)
{
Xcourant=Xmin;
Ycourant++;
if (Ycourant > COTEs2)
{
Ycourant=Ymin;
distance2++;
}
else
{
}
}
else
{
}
}
else
{
}
}
Xanterieur=Xsatisfaisant;
Yanterieur=Ysatisfaisant;
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)",Xanterieur,Yanterieur);
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");
}