/*************************************************************************************************************************************/
/* */
/* C O N S T R U C T I O N D E P O L Y E D R E S : */
/* */
/* */
/* Author of '$xtc/Polyedres.01$vv$I' : */
/* */
/* Jean-Francois COLONNA (LACTAMME, 20261006081131). */
/* */
/*************************************************************************************************************************************/
#include "INCLUDES.01.I"
extern double atof();
#define INFINI 1e100
#define EPSILON1 1e-10
#define EPSILON2 1e-12
double epsilon1=EPSILON1;
double epsilon2=EPSILON2;
typedef struct
{
double x, y, z;
} POINT;
static POINT p[NSOMMETS];
/*************************************************************************************************************************************/
/* */
/* P R O D U I T S C A L A I R E E T D I S T A N C E A U C A R R E : */
/* */
/*************************************************************************************************************************************/
static double dist2(POINT a,POINT b)
{
double x = a.x-b.x;
double y = a.y-b.y;
double z = a.z-b.z;
return (x*x)+(y*y)+(z*z);
}
/*************************************************************************************************************************************/
/* */
/* G E N E R A T I O N D E S S O M M E T S : */
/* */
/*************************************************************************************************************************************/
POINT centre_de_gravite={0,0,0};
double rayon_sphere_circonscrite=-INFINI;
#define EXTREMA_SOMMETS(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) \
{ \
int m=0; \
\
for (m=0; m<NSOMMETS; m++) \
{ \
centre_de_gravite.x = centre_de_gravite.x+p[m].x; \
centre_de_gravite.y = centre_de_gravite.y+p[m].y; \
centre_de_gravite.z = centre_de_gravite.z+p[m].z; \
} \
\
centre_de_gravite.x = centre_de_gravite.x/(double)m; \
centre_de_gravite.y = centre_de_gravite.y/(double)m; \
centre_de_gravite.z = centre_de_gravite.z/(double)m; \
\
m=0; \
\
for (m=0; m<NSOMMETS; m++) \
{ \
double rayon=sqrt(dist2(centre_de_gravite,p[m])); \
rayon_sphere_circonscrite = MAX2(rayon,rayon_sphere_circonscrite); \
\
Xmin = MIN2(p[m].x,Xmin); \
Ymin = MIN2(p[m].y,Ymin); \
Zmin = MIN2(p[m].z,Zmin); \
\
Xmax = MAX2(p[m].x,Xmax); \
Ymax = MAX2(p[m].y,Ymax); \
Zmax = MAX2(p[m].z,Zmax); \
} \
}
/*************************************************************************************************************************************/
/* */
/* R E C H E R C H E D E S A R E T E S : */
/* */
/*************************************************************************************************************************************/
static void bonds(char polyedre[])
{
double longueur_des_aretes_au_carre=+INFINI;
int i,j;
for (i=0; i<NSOMMETS; i++)
{
for (j=i+1; j<NSOMMETS; j++)
{
double d=dist2(p[i],p[j]);
if ((d<longueur_des_aretes_au_carre) && (d>epsilon2))
{
longueur_des_aretes_au_carre=d;
/* Distance minimale entre 2 des sommets. */
}
else
{
}
}
}
printf("Longueur des aretes au carre = %.15g\n\n",longueur_des_aretes_au_carre);
int nb=0;
for (i=0; i<NSOMMETS; i++)
{
for (j=i+1; j<NSOMMETS; j++)
{
if (fabs(dist2(p[i],p[j])-longueur_des_aretes_au_carre)<epsilon1)
{
printf("Arete%s={%02d,%02d} ",polyedre,i,j);
printf("X1=%+.12f Y1=%+.12f Z1=%+.12f",p[i].x,p[i].y,p[i].z);
printf(" ");
printf("X2=%+.12f Y2=%+.12f Z2=%+.12f",p[j].x,p[j].y,p[j].z);
printf("\n");
nb++;
}
else
{
}
}
}
printf("\nNombre d'aretes = %d\n",nb);
if (nb != NARETES)
{
printf("ERREUR : le nombre de cotes (%d) est mauvais et devrait valoir %d\n",nb,NARETES);
}
else
{
}
}
/*************************************************************************************************************************************/
/* */
/* P R O G R A M M E P R I N C I P A L : */
/* */
/*************************************************************************************************************************************/
#define GET_ARGUMENT(index,futur_argument,argument) \
{ \
double futur_argument=atof(argv[index]); \
\
if (futur_argument != 0) \
{ \
argument=futur_argument; \
} \
else \
{ \
} \
}
#define EDITIONS_FINALES(polyedre,Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) \
printf("\nCoordonnees des sommets :\n\n"); \
\
int i; \
\
for (i=0; i<NSOMMETS; i++) \
{ \
printf("Sommet=%2d X=%+.12f Y=%+.12f Z=%+.12f\n",i,p[i].x,p[i].y,p[i].z); \
} \
\
printf("\n"); \
printf("Extrema%s :",polyedre); \
printf(" Xmin_%s=%+.12f Ymin_%s=%+.12f Zmin_%s=%+.12f" \
,polyedre \
,Xmin \
,polyedre \
,Ymin \
,polyedre \
,Zmin \
); \
printf(" Xmax_%s=%+.12f Ymax_%s=%+.12f Zmax_%s=%+.12f" \
,polyedre \
,Xmax \
,polyedre \
,Ymax \
,polyedre \
,Zmax \
); \
printf("\n"); \
printf("\n"); \
\
printf("\nRayonSphereCirconscrite=%f\n",rayon_sphere_circonscrite); \
printf("CentreDeGravite={%f,%f,%f}\n\n",centre_de_gravite.x,centre_de_gravite.y,centre_de_gravite.z); \
\
printf("\nLiaisons :\n\n");