1 |
/*****************************************************************
|
2 |
|
3 |
geo_int_elli_plane.c Type:Func
|
4 |
|
5 |
Intersection ellipse plane
|
6 |
|
7 |
Date de creation : Tue Jul 8 09:37:23 1997
|
8 |
|
9 |
Derniere version : Wed Jul 9 16:24:46 1997
|
10 |
|
11 |
|
12 |
|
13 |
Vincent FRANCOIS
|
14 |
|
15 |
*****************************************************************/
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
/**************************/
|
22 |
/* include */
|
23 |
#include <stdio.h>
|
24 |
#include <string.h>
|
25 |
#include <math.h>
|
26 |
#include "const.h"
|
27 |
#include "memoire.h"
|
28 |
#include "struct.h"
|
29 |
#include "prototype.h"
|
30 |
|
31 |
|
32 |
|
33 |
/**************************/
|
34 |
/* variables globales */
|
35 |
|
36 |
|
37 |
|
38 |
/**************************/
|
39 |
/* programme principal */
|
40 |
|
41 |
int geo_int_elli_plane(struct s_edge *edge,struct s_ellipse *ellipse,float x1,float y1,float z1,float x2,float y2,float z2,float x3,float y3,float z3,float *x,float *y ,float *z)
|
42 |
{
|
43 |
struct s_par_ellipse *param;
|
44 |
float A,B,C,resu,res[3],rad,ox[3],oy[3],oz[4],cteta,steta,teta,alpha,t1,t2,coord[3],tt,ttt,delta;
|
45 |
int sol1,sol2,n1,n2;
|
46 |
int nb_sol;
|
47 |
|
48 |
param=ellipse->param;
|
49 |
/* definition du plan */
|
50 |
ox[0]=x2-x1;ox[1]=y2-y1;ox[2]=z2-z1;
|
51 |
oy[0]=x3-x1;oy[1]=y3-y1;oy[2]=z3-z1;
|
52 |
PVEC(oz,ox,oy);
|
53 |
oz[3]=(-oz[0]*x1-oz[1]*y1-oz[2]*z1);
|
54 |
|
55 |
/* resolution */
|
56 |
A=param->a*(oz[0]*param->u[0]+oz[1]*param->u[1]+oz[2]*param->u[2]);
|
57 |
B=param->b*(oz[0]*param->v[0]+oz[1]*param->v[1]+oz[2]*param->v[2]);
|
58 |
C=(-oz[0]*param->centre[0]-oz[1]*param->centre[1]-oz[2]*param->centre[2]-oz[3]);
|
59 |
rad=A*A+B*B;
|
60 |
if (EGAL(rad,0.0,0.0001)) return(0);
|
61 |
rad=(float)sqrt((double)rad);
|
62 |
resu=C/rad;
|
63 |
if (fabs((double)resu)>1.0001) return(0);
|
64 |
if (resu>1.) resu=1.;
|
65 |
if (resu<(-1)) resu=(-1);
|
66 |
cteta=A/rad;
|
67 |
steta=B/rad;
|
68 |
if (cteta>1.) cteta=1.;
|
69 |
if (cteta<(-1)) cteta=(-1);
|
70 |
teta=(float)acos((double)cteta);
|
71 |
if (steta<0.) teta=(-teta);
|
72 |
alpha=(float)acos((double)resu);
|
73 |
t1=teta+alpha;
|
74 |
t2=teta-alpha;
|
75 |
while (t1<edge->t1) t1=t1+2*PI;
|
76 |
while (t2<edge->t1) t2=t2+2*PI;
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
/* validation de la resolution */
|
82 |
nb_sol=0;
|
83 |
t1=t1-edge->t1;
|
84 |
t2=t2-edge->t1;
|
85 |
|
86 |
if (t1>edge->t2) sol1=0; else sol1=1;
|
87 |
if (t2>edge->t2) sol2=0; else sol2=1;
|
88 |
if ((sol1==0) && (sol2==0)) return(0);
|
89 |
delta=ox[0]*oy[1]-ox[1]*oy[0];
|
90 |
if (EGAL(delta,0.0,0.0001))
|
91 |
{
|
92 |
delta=ox[0]*oy[2]-ox[2]*oy[0];
|
93 |
if (EGAL(delta,0.0,0.0001))
|
94 |
{
|
95 |
delta=ox[1]*oy[2]-ox[2]*oy[1];
|
96 |
n1=1;n2=2;
|
97 |
}
|
98 |
else
|
99 |
{
|
100 |
n1=0;n2=2;
|
101 |
}
|
102 |
}
|
103 |
else
|
104 |
{
|
105 |
n1=0;n2=1;
|
106 |
}
|
107 |
if (sol1==1)
|
108 |
{
|
109 |
eval_ellipse(param,t1+edge->t1,FONCTION,coord);
|
110 |
res[0]=coord[0]-x1;res[1]=coord[1]-y1;res[2]=coord[2]-z1;
|
111 |
tt=(res[n1]*oy[n2]-res[n2]*oy[n1])/delta;
|
112 |
ttt=(ox[n1]*res[n2]-ox[n2]*res[n1])/delta;
|
113 |
if ((tt<-0.0001)||(tt>0.9999)) sol1=0;
|
114 |
if ((ttt<-0.0001)||(ttt>=0.9999)) sol1=0;
|
115 |
}
|
116 |
if (sol1==1)
|
117 |
{
|
118 |
x[nb_sol]=coord[0];
|
119 |
y[nb_sol]=coord[1];
|
120 |
z[nb_sol]=coord[2];
|
121 |
nb_sol++;
|
122 |
}
|
123 |
if (sol2==1)
|
124 |
{
|
125 |
eval_ellipse(param,t2+edge->t1,FONCTION,coord);
|
126 |
res[0]=coord[0]-x1;res[1]=coord[1]-y1;res[2]=coord[2]-z1;
|
127 |
tt=(res[n1]*oy[n2]-res[n2]*oy[n1])/delta;
|
128 |
ttt=(ox[n1]*res[n2]-ox[n2]*res[n1])/delta;
|
129 |
if ((tt<-0.0001)||(tt>=0.9999)) sol2=0;
|
130 |
if ((ttt<-0.0001)||(ttt>=0.9999)) sol2=0;
|
131 |
}
|
132 |
if (sol2==1)
|
133 |
{
|
134 |
x[nb_sol]=coord[0];
|
135 |
y[nb_sol]=coord[1];
|
136 |
z[nb_sol]=coord[2];
|
137 |
nb_sol++;
|
138 |
}
|
139 |
return(nb_sol);
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
}
|