1 |
/*****************************************************************
|
2 |
|
3 |
m2d_int_seg_seg.c Type:Func
|
4 |
|
5 |
Intersection entre segment AB et le sement MN
|
6 |
|
7 |
Date de creation : Wed Feb 19 14:36:10 1997
|
8 |
|
9 |
Derniere version : Thu May 8 10:09:04 1997
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
Vincent FRANCOIS
|
26 |
|
27 |
*****************************************************************/
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
/**************************/
|
34 |
/* include */
|
35 |
#include <stdio.h>
|
36 |
#include <math.h>
|
37 |
#include <math.h>
|
38 |
#include "const.h"
|
39 |
#include "struct.h"
|
40 |
#include "memoire.h"
|
41 |
#include "prototype.h"
|
42 |
|
43 |
|
44 |
/**************************/
|
45 |
/* variables globales */
|
46 |
extern struct environnement env;
|
47 |
extern struct s_mesh *mesh;
|
48 |
|
49 |
/**************************/
|
50 |
/* programme principal */
|
51 |
#define VRAI 1
|
52 |
#define FAUX 0
|
53 |
|
54 |
|
55 |
|
56 |
int m2d_int_seg_seg(int a,int b,int m,int n)
|
57 |
{
|
58 |
struct s_noeud *noa,*nob,*nom,*non;
|
59 |
float ab[3],nm[3],am[3],an[3],det,sol1,sol2,tmp;
|
60 |
float eps,eps2;
|
61 |
float ua,va,ub,vb,un,vn,um,vm,du,dv;
|
62 |
int equation[4],ne1,ne2;
|
63 |
|
64 |
|
65 |
noa=ADRESSE(a,noeud,mesh->);
|
66 |
nob=ADRESSE(b,noeud,mesh->);
|
67 |
nom=ADRESSE(m,noeud,mesh->);
|
68 |
non=ADRESSE(n,noeud,mesh->);
|
69 |
/* decalage */
|
70 |
if (mesh->rev_u!=0.) du=0.5*mesh->rev_u-noa->u; else du=0.;
|
71 |
if (mesh->rev_v!=0.) dv=0.5*mesh->rev_v-noa->v; else dv=0.;
|
72 |
eval_decale(&ua,du,noa->u,U);
|
73 |
eval_decale(&va,dv,noa->v,V);
|
74 |
eval_decale(&ub,du,nob->u,U);
|
75 |
eval_decale(&vb,dv,nob->v,V);
|
76 |
eval_decale(&un,du,non->u,U);
|
77 |
eval_decale(&vn,dv,non->v,V);
|
78 |
eval_decale(&um,du,nom->u,U);
|
79 |
eval_decale(&vm,dv,nom->v,V);
|
80 |
ab[0]=ub-ua;
|
81 |
ab[1]=vb-va;
|
82 |
ab[2]=0.;
|
83 |
nm[0]=um-un;
|
84 |
nm[1]=vm-vn;
|
85 |
nm[2]=0.;
|
86 |
am[0]=um-ua;
|
87 |
am[1]=vm-va;
|
88 |
am[2]=0.;
|
89 |
equation[0]=1; /* etat de l'equation 0 */
|
90 |
equation[1]=1;
|
91 |
equation[2]=1;
|
92 |
equation[3]=3; /* cette variable comporte le bilan du nombre d'equation */
|
93 |
eps2=PSCA(ab,ab);
|
94 |
eps=(float)sqrt((double)eps2);
|
95 |
eps=eps*0.0001;
|
96 |
eps2=eps2*0.0001;
|
97 |
/* recherche du nombre d'equation -> inter franche ou para ou confondu */
|
98 |
if ( (EGAL(ab[0],0,eps)) && (EGAL(nm[0],0,eps)) )
|
99 |
if (EGAL(am[0],0,eps)) equation[0]=0; else return(FAUX);
|
100 |
if ( (EGAL(ab[1],0,eps)) && (EGAL(nm[1],0,eps)) )
|
101 |
if (EGAL(am[1],0,eps)) equation[1]=0; else return(FAUX);
|
102 |
if ( (EGAL(ab[2],0,eps)) && (EGAL(nm[2],0,eps)) )
|
103 |
if (EGAL(am[2],0,eps)) equation[2]=0; else return(FAUX);
|
104 |
equation[3]=equation[0]+equation[1]+equation[2];
|
105 |
if (equation[3]==3)
|
106 |
{
|
107 |
det=DETER(ab[0],nm[0],ab[1],nm[1]);
|
108 |
if ((float)fabs((double)det)>eps2)
|
109 |
{
|
110 |
det=1/det;
|
111 |
sol1=det*DETER(am[0],nm[0],am[1],nm[1]);
|
112 |
sol2=det*DETER(ab[0],am[0],ab[1],am[1]);
|
113 |
if ( (float)fabs((double)(sol1*ab[2]-sol2*nm[2]-am[2]))>eps2) return(FAUX);
|
114 |
return(m2d_ex_sol(sol1,sol2,1));
|
115 |
}
|
116 |
else
|
117 |
{
|
118 |
equation[0]=0;
|
119 |
equation[3]=2;
|
120 |
/* on verifie la compatibilite des deux equations dont le det est nul*/
|
121 |
if (ab[0]!=0) tmp=ab[1]*am[0]/ab[0]; else tmp=nm[1]*am[0]/nm[0];
|
122 |
if (!(EGAL(tmp,am[1],eps))) return(FAUX);
|
123 |
}
|
124 |
}
|
125 |
if (equation[3]==2)
|
126 |
{
|
127 |
/* on repere les equations qui existent */
|
128 |
if (equation[0]!=0)
|
129 |
{
|
130 |
ne1=0;
|
131 |
if (equation[1]!=0) ne2=1; else ne2=2;
|
132 |
}
|
133 |
else
|
134 |
{
|
135 |
ne1=1;
|
136 |
ne2=2;
|
137 |
}
|
138 |
|
139 |
det=DETER(ab[ne1],nm[ne1],ab[ne2],nm[ne2]);
|
140 |
if ((float)fabs((double)det)>eps2)
|
141 |
{
|
142 |
det=1/det;
|
143 |
sol1=det*DETER(am[ne1],nm[ne1],am[ne2],nm[ne2]);
|
144 |
sol2=det*DETER(ab[ne1],am[ne1],ab[ne2],am[ne2]);
|
145 |
return(m2d_ex_sol(sol1,sol2,1));
|
146 |
}
|
147 |
else
|
148 |
{
|
149 |
equation[ne1]=0;
|
150 |
equation[3]=1;
|
151 |
/* on verifie la compatibilite des deux equations dont le det est nul */
|
152 |
if (ab[ne1]!=0) tmp=ab[ne2]*am[ne1]/ab[ne1]; else tmp=nm[ne2]*am[ne1]/nm[ne1];
|
153 |
if (!(EGAL(tmp,am[ne2],eps))) return(FAUX);
|
154 |
}
|
155 |
|
156 |
}
|
157 |
if (equation[3]==1)
|
158 |
{
|
159 |
/* on repere l' equation qui existe */
|
160 |
if (equation[0]!=0) ne1=0; else
|
161 |
if (equation[1]!=0) ne1=1; else ne1=2;
|
162 |
an[0]=un-ua;
|
163 |
an[1]=vn-va;
|
164 |
an[2]=0.;
|
165 |
tmp=1/ab[ne1];
|
166 |
sol1=am[ne1]*tmp;
|
167 |
sol2=an[ne1]*tmp;
|
168 |
return(m2d_ex_sol(sol1,sol2,2));
|
169 |
}
|
170 |
return(0);
|
171 |
}
|