1 #include "../include/Matematica.h" 11 Dir21[d] = P2[d] - P1[d];
12 Dir31[d] = P3[d] - P1[d];
13 Dir23[d] = P2[d] - P3[d];
28 if( fabs(
Norm[d]) > 0.){
29 InvNorm[d] = 1./
Norm[d];
38 Bound[d*2 ] = MIN(P1[d],MIN(P2[d],P3[d]));
40 Bound[d*2+1] = MAX(P1[d],MAX(P2[d],P3[d]));
44 mxy[0] = (P1[1] - P2[1])*
Inv(P1[0] - P2[0]);
45 qxy[0] = P1[1] -
mxy[0]*P1[0];
46 mxz[0] = (P1[2] - P2[2])*
Inv(P1[0] - P2[0]);
47 qxz[0] = P1[2] - mxz[0]*P1[0];
48 mxy[1] = (P1[1] - P3[1])*
Inv(P1[0] - P3[0]);
49 qxy[1] = P1[1] -
mxy[1]*P1[0];
50 mxz[1] = (P1[2] - P3[2])*
Inv(P1[0] - P3[0]);
51 qxz[1] = P1[2] - mxz[1]*P1[0];
52 mxy[2] = (P3[1] - P2[1])*
Inv(P3[0] - P2[0]);
53 qxy[2] = P1[1] -
mxy[2]*P1[0];
54 mxz[2] = (P3[2] - P2[2])*
Inv(P3[0] - P2[0]);
55 qxz[2] = P1[2] - mxz[2]*P1[0];
69 Sign += (
P1[d] - Pos->
x[d])*
Norm[d];
71 if(Sign > 0) Sign = -1.;
74 Pos1[d] = Pos->
x[d] - Sign*Dist*
Norm.
x[d];
80 for(
int d=0;d<v->
NDim;d++){
81 Len += v->
x[d]*
Norm[d];
93 v1[d] = - v->
x[d] + 2.*n1[d];
99 if(Dist >
Rad)
return 0;
106 if(i == 1)
return P1;
107 if(i == 2)
return P2;
108 if(i == 3)
return P3;
109 if(i == 4)
return P4;
113 return x != 0. ? 1./x : 100000000000.;
131 for(
int d=0;d<3;d++){
134 D1[d] = (C[NUno]-B[NUno])*(P[NDue]-B[NDue]) - (C[NDue]-B[NDue])*(P[NUno]-B[NUno]);
135 D2[d] = (C[NUno]-B[NUno])*(A[NDue]-B[NDue]) - (C[NDue]-B[NDue])*(A[NUno]-B[NUno]);
138 if( Scal >= 0)
return 1;
140 if( D1%D2 >= 0)
return 1;
147 for(
int d=0;d<3;d++){
148 DirP1[d] = P[d] - P1[d];
153 double sq2 = 0.,sq3 = 0.;
154 double pd32 = 0., pdP3 = 0., pdP2 = 0.;
155 for(
int d=0;d<3;d++){
156 sq2 += SQR(
Dir21[d]);
157 sq3 += SQR(Dir31[d]);
158 pd32 +=
Dir21[d]*Dir31[d];
159 pdP3 += Dir31[d]*DirP1[d];
160 pdP2 +=
Dir21[d]*DirP1[d];
162 double Inv = 1./(sq2*sq3 - SQR(pd32));
163 double v = (sq3*pdP2 - pd32*pdP3)*Inv;
164 double u = (sq2*pdP3 - pd32*pdP2)*Inv;
165 if(u >= 0. && v >= 0. && (u+v) < 1.)
return 1;
Vettore Norm
Normal and inverse to the normal.
void Copy(Vettore *o)
Copy the vector.
Vettore P1
Points defining the plane.
double dPar
d of ax+by+cz+d=0
Vettore GetVertex(int i)
Get vertex.
double Normalize()
Normlizes a Vettore.
Geometrical operations on vectors.
Vettore ProjOnNorm(Vettore *v)
Project on normal (vector)
int IsOnSurf1(Vettore *P)
If the point is inside the triangle first method.
double * x
Where the data are stored.
int IsInf[3]
If the inverse to the normal is infinite.
Piano(Vettore *P1, Vettore *P2, Vettore *P3)
Allocates.
int SameSide(Vettore *P, Vettore *A, Vettore *B, Vettore *C)
Is the orientation of the difference vectors on the same side?
double Distance(Vettore *P)
Distance.
double Bound[6]
Boundaries.
Vettore Dir21
Direction vectors.
Vettore Reflect(Vettore *V)
Reflect a vector by the normal.
int IsOnSurf2(Vettore *P)
If the point is inside the triangle second method.
double Rad
Radius of the contact.
double Inv(double x)
Calculate the inverse.
int NDim
Dimension allocated.
int Impact(Vettore *P, Vettore *V)
Reflect velocity.
int IsOnSurf(Vettore *P)
If the point is inside the triangle.
Vettore ProjOnSurf(Vettore *Pos)
Project on surface (point)