1 |
|
5 |
#include <stdio.h>
|
2 |
|
|
#include <math.h>
|
3 |
|
|
#include "r3d_struct.h"
|
4 |
|
|
#include "m3d_const.h"
|
5 |
|
|
#include "m3d_hotes.h"
|
6 |
|
|
#include "prototype2.h"
|
7 |
|
|
extern int debug ;
|
8 |
|
|
int r3d_switch(float *coord,FACE *face,TETRAEDRE *tetra,int *numele)
|
9 |
|
|
{
|
10 |
|
|
int n1, n2, n3, n4, i;
|
11 |
|
|
float vab[3], vac[3], vn[3], norme, pvec[3],vap[3], dist, dab, dac, dref ;
|
12 |
|
|
NOEUD *noe ;
|
13 |
|
|
|
14 |
|
|
if (face->hist == 0 ) return(VRAI) ;
|
15 |
|
|
|
16 |
|
|
n1 = face->n1->num ;
|
17 |
|
|
n2 = face->n2->num ;
|
18 |
|
|
n3 = face->n3->num ;
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
if ( (numele[4*(tetra->num)]!=n1) && (numele[4*(tetra->num)]!=n2) && (numele[4*(tetra->num)]!=n3))
|
22 |
|
|
n4 = numele[4*(tetra->num)] ;
|
23 |
|
|
else if ( (numele[4*(tetra->num) + 1]!=n1) && (numele[4*(tetra->num)+ 1]!=n2) && (numele[4*(tetra->num) + 1]!=n3))
|
24 |
|
|
n4 = numele[4*(tetra->num) + 1] ;
|
25 |
|
|
else if ( (numele[4*(tetra->num) + 2]!=n1) && (numele[4*(tetra->num) + 2]!=n2) && (numele[4*(tetra->num) + 2]!=n3))
|
26 |
|
|
n4 = numele[4*(tetra->num) + 2] ;
|
27 |
|
|
else n4 = numele[4*(tetra->num) + 3] ;
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
/* calcul de la normale */
|
31 |
|
|
vab[0] = coord[x(n2)] - coord[x(n1)] ;
|
32 |
|
|
vab[1] = coord[y(n2)] - coord[y(n1)] ;
|
33 |
|
|
vab[2] = coord[z(n2)] - coord[z(n1)] ;
|
34 |
|
|
dab = NORME(vab) ;
|
35 |
|
|
vac[0] = coord[x(n3)] - coord[x(n1)] ;
|
36 |
|
|
vac[1] = coord[y(n3)] - coord[y(n1)] ;
|
37 |
|
|
vac[2] = coord[z(n3)] - coord[z(n1)] ;
|
38 |
|
|
dac = NORME(vac) ;
|
39 |
|
|
|
40 |
|
|
dref = max(dab,dac) ;
|
41 |
|
|
|
42 |
|
|
/* calcul du critere 2 D */
|
43 |
|
|
pvec[0] = PVECX(vab,vac) ;
|
44 |
|
|
pvec[1] = PVECY(vab,vac) ;
|
45 |
|
|
pvec[2] = PVECZ(vab,vac) ;
|
46 |
|
|
|
47 |
|
|
vn[0] = PVECX(vab,vac) ;
|
48 |
|
|
vn[1] = PVECY(vab,vac) ;
|
49 |
|
|
vn[2] = PVECZ(vab,vac) ;
|
50 |
|
|
|
51 |
|
|
norme = NORME(vn) ;
|
52 |
|
|
if (norme<EPSILON)
|
53 |
|
|
{
|
54 |
|
|
if (debug) printf("%s\n"," erreur normale nulle M3D_SWITCH ") ;
|
55 |
|
|
return(FAUX) ;
|
56 |
|
|
}
|
57 |
|
|
for (i=0;i<3;i++) vn[i] = vn[i]/norme ;
|
58 |
|
|
|
59 |
|
|
/* position de n4 par rapport au plan */
|
60 |
|
|
|
61 |
|
|
/* calcul du vecteur PA */
|
62 |
|
|
vap[0] = coord[x(n4)] - coord[x(n1)] ;
|
63 |
|
|
vap[1] = coord[y(n4)] - coord[y(n1)] ;
|
64 |
|
|
vap[2] = coord[z(n4)] - coord[z(n1)] ;
|
65 |
|
|
dist = PROSCA(vap,vn) ;
|
66 |
|
|
|
67 |
|
|
if (dist>dref*EPSILON) /* pas la peine d'inverser la face */
|
68 |
|
|
{
|
69 |
|
|
return(VRAI) ;
|
70 |
|
|
}
|
71 |
|
|
else
|
72 |
|
|
{
|
73 |
|
|
noe = face->n3 ;
|
74 |
|
|
face->n3 = face->n2 ;
|
75 |
|
|
face->n2 = noe ;
|
76 |
|
|
}
|
77 |
|
|
return(VRAI) ;
|
78 |
|
|
}
|
79 |
|
|
|