ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/acismesh/geo_app_point_body.cpp
Revision: 1
Committed: Mon Jun 11 22:53:07 2007 UTC (17 years, 11 months ago)
File size: 4268 byte(s)
Log Message:

File Contents

# Content
1 /*****************************************************************
2
3 geo_app_point_body.cpp Type:Inc
4
5 Appartenance d un point a un solide
6
7 Date de creation : 30-10-1997 18 :22 :38
8 Derniere version : 30-10-1997 18 :22 :38
9
10 Vincent FRANCOIS
11
12 *****************************************************************/
13
14
15
16
17
18 /**************************/
19 /* include */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <math.h>
24 #include "const.h"
25 #include "memoire.h"
26 #include "struct.h"
27 #include "prototype.h"
28
29
30 /**************************/
31 /* variables globales */
32 extern struct s_acis *acis;
33 extern struct environnement env;
34 extern struct s_mesh *mesh;
35 extern struct s_param *para;
36
37
38 /**************************/
39 /* programme principal */
40
41 int geo_app_point_body(float x,float y,float z)
42 {
43 struct s_triangle *tri;
44 struct s_noeud *no1,*no2,*no3;
45 float *inter,eps,xb,yb,zb,xi,yi,zi,ps1,ps2;
46 int nb_inter,ok,ok2,i,j,k,*iordre,nb_reel,nb_neg;
47 float vec[4],n1n3[4],n1n2[4],n[4],on1[4],pn1[4],pn2[4],pn3[4];
48 float h2moyen,h1,h2,h3,vmin,dist,pvec[4];
49
50 /* on fait passer une droite a trvers le domaine et on comptabilise les intersections avec la droite */
51
52 inter=(float *)calloc(mesh->nb_triangle,sizeof(float));
53 ERREUR_ALLOC(inter);
54 iordre=(int *)calloc(mesh->nb_triangle,sizeof(int));
55 ERREUR_ALLOC(iordre);
56 ok=0;
57 eps=0.0001;
58 i=(-1);
59 while (ok==0)
60 {
61 i++;
62 ok2=0;
63 while (ok2==0)
64 {
65 nb_inter=0;
66 tri=ADRESSE(i,triangle,mesh->);
67 /* construction de la droite */
68 no1=ADRESSE(tri->n1,noeud,mesh->);
69 no2=ADRESSE(tri->n2,noeud,mesh->);
70 no3=ADRESSE(tri->n3,noeud,mesh->);
71 xb=(no1->x+no2->x+no3->x)/3.;
72 yb=(no1->y+no2->y+no3->y)/3.;
73 zb=(no1->z+no2->z+no3->z)/3.;
74 vec[0]=xb-x;
75 vec[1]=yb-y;
76 vec[2]=zb-z;
77 NORME(vec);
78 VEC(n1n3,no1,no3);
79 VEC(n1n2,no1,no2);
80 PVEC(n,n1n2,n1n3);
81 NORME(n);
82 ps1=PSCA(n,vec);
83 if (ps1*ps1<(vec[0]+vec[1]+vec[2])*eps)i++;
84 else ok2=1;
85 }
86 /* intersection droite et tous les triangles */
87 j=0;
88 while (j<mesh->nb_triangle)
89 {
90 tri=ADRESSE(j,triangle,mesh->);
91 no1=ADRESSE(tri->n1,noeud,mesh->);
92 no2=ADRESSE(tri->n2,noeud,mesh->);
93 no3=ADRESSE(tri->n3,noeud,mesh->);
94 VEC(n1n3,no1,no3);
95 VEC(n1n2,no1,no2);
96 PVEC(n,n1n2,n1n3);
97 NORME(n);
98 ps1=PSCA(n,vec);
99 on1[0]=no1->x-x;
100 on1[1]=no1->y-y;
101 on1[2]=no1->z-z;
102 if (ps1*ps1<(vec[0]+vec[1]+vec[2])*eps)
103 {
104 ps2=PSCA(on1,n);
105 if (ps2*ps2<(on1[0]+on1[1]+on1[2])*eps)
106 j=mesh->nb_triangle*2;
107
108 }
109 else
110 {
111 dist=PSCA(on1,n)/ps1;
112 xi=dist*vec[0]+x;
113 yi=dist*vec[1]+y;
114 zi=dist*vec[2]+z;
115 h2moyen=n[3];
116 pn1[0]=no1->x-xi;
117 pn1[1]=no1->y-yi;
118 pn1[2]=no1->z-zi;
119 pn2[0]=no2->x-xi;
120 pn2[1]=no2->y-yi;
121 pn2[2]=no2->z-zi;
122 pn3[0]=no3->x-xi;
123 pn3[1]=no3->y-yi;
124 pn3[2]=no3->z-zi;
125 PVEC(pvec,pn1,pn2);
126 h1=PSCA(pvec,n);
127 PVEC(pvec,pn2,pn3);
128 h2=PSCA(pvec,n);
129 PVEC(pvec,pn3,pn1);
130 h3=PSCA(pvec,n);
131 MINI(vmin,h1*h2,h2*h3);
132 MINI(vmin,vmin,h1*h3);
133 if (((float)fabs((double)vmin)<=h2moyen*eps) || (vmin>(h2moyen*eps)))
134 {
135 inter[nb_inter]=dist;
136 nb_inter++;
137 }
138
139 }
140
141 j++;
142 }
143 if (j<2*mesh->nb_triangle)
144 {
145 for (k=0;k<nb_inter;k++) iordre[i]=i+1;
146 trirea(inter,&nb_inter,iordre);
147 ok=1;
148 nb_neg=0;
149 nb_reel=0;
150 for (k=0;k<nb_inter-1;k++)
151 {
152 if ((inter[k+1]-inter[k])>100.*eps)
153 {
154 nb_reel++;
155 if (inter[k]<(-eps)) nb_neg++;
156 if (k==nb_inter-2)
157 {
158 nb_reel++;
159 if (inter[k+1]<(-eps)) nb_neg++;
160 }
161 }
162 }
163
164 }
165 }
166 free(inter);
167 free(iordre);
168 if ((nb_neg%2)==1) return(1);
169 return(0);
170 }