62 inline double det(
const double *p1,
const double *p2,
const double *p3)
64 return p1[0]*p2[1]*p3[2] + p2[0]*p3[1]*p1[2] + p3[0]*p1[1]*p2[2] -p1[0]*p3[1]*p2[2] - p2[0]*p1[1]*p3[2] - p3[0]*p2[1]*p1[2];
67 double computeMeshVolume(
const double *vertices,
unsigned int tcount,
const unsigned int *indices)
71 const double *p0 = vertices;
72 for (
unsigned int i=0; i<tcount; i++,indices+=3)
75 const double *p1 = &vertices[ indices[0]*3 ];
76 const double *p2 = &vertices[ indices[1]*3 ];
77 const double *p3 = &vertices[ indices[2]*3 ];
79 volume+=
det(p1,p2,p3);
91 cross[0] = a[1]*b[2] - a[2]*b[1];
92 cross[1] = a[2]*b[0] - a[0]*b[2];
93 cross[2] = a[0]*b[1] - a[1]*b[0];
96 inline double DotProduct(
const double *a,
const double *b)
98 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
101 inline double tetVolume(
const double *p0,
const double *p1,
const double *p2,
const double *p3)
107 a[0] = p1[0] - p0[0];
108 a[1] = p1[1] - p0[1];
109 a[2] = p1[2] - p0[2];
111 b[0] = p2[0] - p0[0];
112 b[1] = p2[1] - p0[1];
113 b[2] = p2[2] - p0[2];
115 c[0] = p3[0] - p0[0];
116 c[1] = p3[1] - p0[1];
117 c[2] = p3[2] - p0[2];
131 inline double det(
const double *p0,
const double *p1,
const double *p2,
const double *p3)
133 return p1[0]*p2[1]*p3[2] + p2[0]*p3[1]*p1[2] + p3[0]*p1[1]*p2[2] -p1[0]*p3[1]*p2[2] - p2[0]*p1[1]*p3[2] - p3[0]*p2[1]*p1[2];
140 const double *p0 = vertices;
141 for (
unsigned int i=0; i<tcount; i++,indices+=3)
144 const double *p1 = &vertices[ indices[0]*3 ];
145 const double *p2 = &vertices[ indices[1]*3 ];
146 const double *p3 = &vertices[ indices[2]*3 ];
151 return volume * (1.0f / 6.0f );
157 inline float det(
const float *p1,
const float *p2,
const float *p3)
159 return p1[0]*p2[1]*p3[2] + p2[0]*p3[1]*p1[2] + p3[0]*p1[1]*p2[2] -p1[0]*p3[1]*p2[2] - p2[0]*p1[1]*p3[2] - p3[0]*p2[1]*p1[2];
166 const float *p0 = vertices;
167 for (
unsigned int i=0; i<tcount; i++,indices+=3)
170 const float *p1 = &vertices[ indices[0]*3 ];
171 const float *p2 = &vertices[ indices[1]*3 ];
172 const float *p3 = &vertices[ indices[2]*3 ];
174 volume+=
det(p1,p2,p3);
186 cross[0] = a[1]*b[2] - a[2]*b[1];
187 cross[1] = a[2]*b[0] - a[0]*b[2];
188 cross[2] = a[0]*b[1] - a[1]*b[0];
193 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
196 inline float tetVolume(
const float *p0,
const float *p1,
const float *p2,
const float *p3)
202 a[0] = p1[0] - p0[0];
203 a[1] = p1[1] - p0[1];
204 a[2] = p1[2] - p0[2];
206 b[0] = p2[0] - p0[0];
207 b[1] = p2[1] - p0[1];
208 b[2] = p2[2] - p0[2];
210 c[0] = p3[0] - p0[0];
211 c[1] = p3[1] - p0[1];
212 c[2] = p3[2] - p0[2];
226 inline float det(
const float *p0,
const float *p1,
const float *p2,
const float *p3)
228 return p1[0]*p2[1]*p3[2] + p2[0]*p3[1]*p1[2] + p3[0]*p1[1]*p2[2] -p1[0]*p3[1]*p2[2] - p2[0]*p1[1]*p3[2] - p3[0]*p2[1]*p1[2];
235 const float *p0 = vertices;
236 for (
unsigned int i=0; i<tcount; i++,indices+=3)
239 const float *p1 = &vertices[ indices[0]*3 ];
240 const float *p2 = &vertices[ indices[1]*3 ];
241 const float *p3 = &vertices[ indices[2]*3 ];
246 return volume * (1.0f / 6.0f );