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

File Contents

# User Rev Content
1 1 /*****************************************************************
2    
3     eval_dis_no_tri.cpp Type:Func
4    
5     Calcul de la distance entre un noeud et un triangle
6    
7     Date de creation : 30-7-1999 9 :28 :28
8     Derniere version : 30-7-1999 9 :28 :28
9    
10     Vincent FRANCOIS
11    
12     *****************************************************************/
13    
14    
15    
16    
17    
18     /**************************/
19     /* include */
20     #include <stdio.h>
21     #include <string.h>
22     #include <stdlib.h>
23     #include <math.h>
24     #include "const.h"
25     #include "memoire.h"
26     #include "struct.h"
27     #include "struct3d.h"
28     #include "prototype.h"
29    
30    
31     /**************************/
32     /* variables globales */
33     extern struct environnment env;
34     extern struct s_mesh *mesh;
35    
36    
37    
38     /**************************/
39     /* programme principal */
40    
41     float eval_dis_no_tri(float x,float y,float z,struct s_triangle *tri)
42     {
43     struct s_noeud *no1,*no2,*no3;
44     float n1n2[4],n1n3[4],n1n4[4],nn1[4],nn2[4],nn3[4],n1n[4];
45     float det,xsi,eta,psi;
46     float xproj,yproj,zproj,vec[4],dis,eps;
47    
48     eps=0.0001;
49     no1=ADRESSE(tri->n1,noeud,mesh->);
50     no2=ADRESSE(tri->n2,noeud,mesh->);
51     no3=ADRESSE(tri->n3,noeud,mesh->);
52    
53    
54     VEC(n1n2,no1,no2);
55     VEC(n1n3,no1,no3);
56     n1n4[0]=x-no1->x;
57     n1n4[1]=y-no1->y;
58     n1n4[2]=z-no1->z;
59     PVEC(n1n,n1n2,n1n3);
60    
61     det=n1n2[0]*n1n3[1]*n1n[2]+n1n2[1]*n1n3[2]*n1n[0]+n1n2[2]*n1n3[0]*n1n[1]
62     -n1n2[2]*n1n3[1]*n1n[0]-n1n2[0]*n1n3[2]*n1n[1]-n1n2[1]*n1n3[0]*n1n[2];
63     xsi=n1n4[0]*n1n3[1]*n1n[2]+n1n4[1]*n1n3[2]*n1n[0]+n1n4[2]*n1n3[0]*n1n[1]
64     -n1n4[2]*n1n3[1]*n1n[0]-n1n4[0]*n1n3[2]*n1n[1]-n1n4[1]*n1n3[0]*n1n[2];
65     eta=n1n2[0]*n1n4[1]*n1n[2]+n1n2[1]*n1n4[2]*n1n[0]+n1n2[2]*n1n4[0]*n1n[1]
66     -n1n2[2]*n1n4[1]*n1n[0]-n1n2[0]*n1n4[2]*n1n[1]-n1n2[1]*n1n4[0]*n1n[2];
67     psi=n1n2[0]*n1n3[1]*n1n4[2]+n1n2[1]*n1n3[2]*n1n4[0]+n1n2[2]*n1n3[0]*n1n4[1]
68     -n1n2[2]*n1n3[1]*n1n4[0]-n1n2[0]*n1n3[2]*n1n4[1]-n1n2[1]*n1n3[0]*n1n4[2];
69     xsi=xsi/det;
70     eta=eta/det;
71     psi=psi/det;
72    
73    
74     if((eta > -eps) && (xsi > -eps) && ((eta+xsi) < 1.0+eps))
75     {
76     xproj=(1-xsi-eta)*no1->x+xsi*no2->x+eta*no3->x;
77     yproj=(1-xsi-eta)*no1->y+xsi*no2->y+eta*no3->y;
78     zproj=(1-xsi-eta)*no1->z+xsi*no2->z+eta*no3->z;
79     vec[0]=x-xproj;
80     vec[1]=y-yproj;
81     vec[2]=z-zproj;
82     NORME(vec);
83     dis=vec[3];
84     }
85     else
86     {
87     nn1[0]=no1->x-x;
88     nn1[1]=no1->y-y;
89     nn1[2]=no1->z-z;
90     nn2[0]=no2->x-x;
91     nn2[1]=no2->y-y;
92     nn2[2]=no2->z-z;
93     nn3[0]=no3->x-x;
94     nn3[1]=no3->y-y;
95     nn3[2]=no3->z-z;
96     NORME(nn1);
97     NORME(nn2);
98     NORME(nn3);
99     dis=0.33333333333*(nn1[3]+nn2[3]+nn3[3]);
100     }
101     return(dis);
102     }