/*************************************************************************************************************************************/
/* */
/* P A R C O U R S D ' U N C U B E P A R C U B E S " C O N C E N T R I Q U E S " S U C C E S S I F S */
/* P U I S T R I P A R D I S T A N C E C R O I S S A N T E : */
/* */
/* */
/* Author of '$xtc/ParcoCube.12$c' : */
/* */
/* Jean-Francois COLONNA (LACTAMME, AAAAMMJJhhmmss). */
/* */
/*************************************************************************************************************************************/
#include <stdio.h>
#define INDEX0 \
0
#define INDEXn \
1000
static int Tpermutation[INDEXn-INDEX0+1];
static int TcoordonneeX[INDEXn-INDEX0+1];
static int TcoordonneeY[INDEXn-INDEX0+1];
static int TcoordonneeZ[INDEXn-INDEX0+1];
static double Tdistance[INDEXn-INDEX0+1];
#define compcl(index1,index2) \
(Tdistance[Tpermutation[index1]]-Tdistance[Tpermutation[index2]])
#define echang(index1,index2) \
{ \
int tempo=Tpermutation[index1]; \
Tpermutation[index1] = Tpermutation[index2]; \
Tpermutation[index2] = tempo; \
}
void tri(debut,fin)
/* Procedure de tri en "N au carre" afin de conserver l'ordre des points qui sont dans le */
/* bon ordre a priori... */
int debut;
int fin;
{
int index_de_fin;
for (index_de_fin=(fin-1) ; index_de_fin>=debut ; index_de_fin=index_de_fin-1)
{
int index_de_debut;
for (index_de_debut=debut ; index_de_debut<=index_de_fin ; index_de_debut=index_de_debut+1)
{
if (compcl(index_de_debut,index_de_debut+1)>0)
{
echang(index_de_debut,index_de_debut+1);
/* Cette echange conserve l'ordre des elements possedant la meme "clef"... */
}
else
{
}
}
}
}
extern double sqrt();
void Fcube(xc,yc,zc,DemiCote)
int xc,yc,zc;
int DemiCote;
/* Centre et demi-cote du cube courant. */
{
int numero=INDEX0;
/* Numero du point courant... */
int index;
/* Index de tri... */
int DemiCoteCourant;
for (DemiCoteCourant=0; DemiCoteCourant<=DemiCote; DemiCoteCourant++)
/* Pour parcourir la liste des cubes "concentriques". */
{
int x,xMin=xc-DemiCoteCourant,xMax=xc+DemiCoteCourant;
int y,yMin=yc-DemiCoteCourant,yMax=yc+DemiCoteCourant;
int z,zMin=zc-DemiCoteCourant,zMax=zc+DemiCoteCourant;
for (z=zMin; z<=zMax; z++)
{
for (y=yMin; y<=yMax; y++)
{
for (x=xMin; x<=xMax; x++)
{
if ( (z == zMin) || (z == zMax)
|| (y == yMin) || (y == yMax)
|| (x == xMin) || (x == xMax)
)
/* On ne marque que les points appartenant a l'une des 6 faces du cube 'DemiCoteCourant' */
/* courant... */
{
if (numero <= INDEXn)
{
double distance=sqrt((double)(((x-xc)*(x-xc))
+((y-yc)*(y-yc))
+((z-zc)*(z-zc))
)
);
TcoordonneeX[numero] = x;
TcoordonneeY[numero] = y;
TcoordonneeZ[numero] = z;
Tdistance[numero] = distance;
Tpermutation[numero] = numero;
numero++;
}
else
{
printf("debordement des listes\n");
}
}
else
{
}
}
}
}
}
numero--;
tri(INDEX0,numero);
/* Tri par distances croissantes. */
for (index=INDEX0 ; index<=numero ; index++)
{
printf("point=%04d coordonnees={%+d,%+d,%+d} distance=%f\n"
,Tpermutation[index]
,TcoordonneeX[Tpermutation[index]],TcoordonneeY[Tpermutation[index]],TcoordonneeZ[Tpermutation[index]]
,Tdistance[Tpermutation[index]]
);
/* Edition de la liste des points triee par distances croissantes. */
}
}
main()
{
int xc,yc,zc;
int DemiCote;
Fcube(0,0,0,0);
printf("\n");
Fcube(0,0,0,1);
printf("\n");
Fcube(0,0,0,2);
}