8 static void affect(
double *xi,
double *yi,
double *zi,
int i,
double *xp,
9 double *yp,
double *zp,
int j)
16 double InterpolateIso(
double *X,
double *Y,
double *Z,
double *Val,
double V,
17 int I1,
int I2,
double *XI,
double *YI,
double *ZI)
19 if(Val[I1] == Val[I2]) {
26 double coef = (V - Val[I1]) / (Val[I2] - Val[I1]);
27 *XI = coef * (X[I2] - X[I1]) + X[I1];
28 *YI = coef * (Y[I2] - Y[I1]) + Y[I1];
29 *ZI = coef * (Z[I2] - Z[I1]) + Z[I1];
36 int IsoLine(
double *X,
double *Y,
double *Z,
double *Val,
double V,
double *Xp,
37 double *Yp,
double *Zp)
39 if(Val[0] == Val[1])
return 0;
41 if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)) {
50 int IsoTriangle(
double *X,
double *Y,
double *Z,
double *Val,
double V,
51 double *Xp,
double *Yp,
double *Zp)
53 if(Val[0] == Val[1] && Val[0] == Val[2])
return 0;
56 if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)) {
60 if((Val[0] >= V && Val[2] <= V) || (Val[2] >= V && Val[0] <= V)) {
64 if((Val[1] >= V && Val[2] <= V) || (Val[2] >= V && Val[1] <= V)) {
75 int IsoSimplex(
double *X,
double *Y,
double *Z,
double *Val,
double V,
76 double *Xp,
double *Yp,
double *Zp,
double n[3])
78 if(Val[0] == Val[1] && Val[0] == Val[2] && Val[0] == Val[3])
return 0;
81 if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)) {
85 if((Val[0] >= V && Val[2] <= V) || (Val[2] >= V && Val[0] <= V)) {
89 if((Val[0] >= V && Val[3] <= V) || (Val[3] >= V && Val[0] <= V)) {
93 if((Val[1] >= V && Val[2] <= V) || (Val[2] >= V && Val[1] <= V)) {
97 if((Val[1] >= V && Val[3] <= V) || (Val[3] >= V && Val[1] <= V)) {
101 if((Val[2] >= V && Val[3] <= V) || (Val[3] >= V && Val[2] <= V)) {
111 double xi[6], yi[6], zi[6];
112 affect(xi, yi, zi, 0, Xp, Yp, Zp, 0);
114 for(
int j = 1; j < nb; j++) {
115 for(
int i = 0; i < ni; i++) {
116 if(fabs(Xp[j] - xi[i]) < 1.e-12 && fabs(Yp[j] - yi[i]) < 1.e-12 &&
117 fabs(Zp[j] - zi[i]) < 1.e-12) {
121 affect(xi, yi, zi, i + 1, Xp, Yp, Zp, j);
126 for(
int i = 0; i < ni; i++)
affect(Xp, Yp, Zp, i, xi, yi, zi, i);
130 if(nb < 3 || nb > 4)
return 0;
136 double x = Xp[3], y = Yp[3],
z = Zp[3];
148 double v1[3] = {Xp[2] - Xp[0], Yp[2] - Yp[0], Zp[2] - Zp[0]};
149 double v2[3] = {Xp[1] - Xp[0], Yp[1] - Yp[0], Zp[1] - Zp[0]};
157 double Xpi[6], Ypi[6], Zpi[6];
158 for(
int i = 0; i < nb; i++) {
163 for(
int i = 0; i < nb; i++) {
164 Xp[i] = Xpi[nb - i - 1];
165 Yp[i] = Ypi[nb - i - 1];
166 Zp[i] = Zpi[nb - i - 1];
180 int CutLine(
double *X,
double *Y,
double *Z,
double *Val,
double V1,
double V2,
181 double *Xp2,
double *Yp2,
double *Zp2,
double *Vp2)
184 if(Val[0] < Val[1]) {
193 if(Val[io[0]] > V2 || Val[io[1]] < V1)
return 0;
195 if(V1 <= Val[io[0]] && Val[io[1]] <= V2) {
196 for(
int i = 0; i < 2; i++) {
205 if(V1 <= Val[io[0]]) {
213 InterpolateIso(X, Y, Z, Val, V1, io[0], io[1], &Xp2[0], &Yp2[0], &Zp2[0]);
216 if(V2 >= Val[io[1]]) {
224 InterpolateIso(X, Y, Z, Val, V2, io[0], io[1], &Xp2[1], &Yp2[1], &Zp2[1]);
233 int CutTriangle(
double *X,
double *Y,
double *Z,
double *Val,
double V1,
234 double V2,
double *Xp2,
double *Yp2,
double *Zp2,
double *Vp2)
238 int io[3] = {0, 1, 2};
239 for(
int i = 0; i < 2; i++) {
240 for(
int j = i + 1; j < 3; j++) {
241 if(Val[io[i]] > Val[io[j]]) {
249 if(Val[io[0]] > V2 || Val[io[2]] < V1)
return 0;
251 if(V1 <= Val[io[0]] && Val[io[2]] <= V2) {
252 for(
int i = 0; i < 3; i++) {
262 double Xp[10], Yp[10], Zp[10], Vp[10];
264 if(V1 <= Val[io[0]]) {
272 else if(Val[io[0]] < V1 && V1 <= Val[io[1]]) {
274 InterpolateIso(X, Y, Z, Val, V1, io[0], io[2], &Xp[Np], &Yp[Np], &Zp[Np]);
277 InterpolateIso(X, Y, Z, Val, V1, io[0], io[1], &Xp[Np], &Yp[Np], &Zp[Np]);
283 InterpolateIso(X, Y, Z, Val, V1, io[0], io[2], &Xp[Np], &Yp[Np], &Zp[Np]);
286 InterpolateIso(X, Y, Z, Val, V1, io[1], io[2], &Xp[Np], &Yp[Np], &Zp[Np]);
291 if(V2 == Val[io[0]]) {
return 0; }
292 else if((Val[io[0]] < V2) && (V2 < Val[io[1]])) {
294 InterpolateIso(X, Y, Z, Val, V2, io[0], io[1], &Xp[Np], &Yp[Np], &Zp[Np]);
297 InterpolateIso(X, Y, Z, Val, V2, io[0], io[2], &Xp[Np], &Yp[Np], &Zp[Np]);
300 else if(V2 < Val[io[2]]) {
309 InterpolateIso(X, Y, Z, Val, V2, io[1], io[2], &Xp[Np], &Yp[Np], &Zp[Np]);
312 InterpolateIso(X, Y, Z, Val, V2, io[0], io[2], &Xp[Np], &Yp[Np], &Zp[Np]);
337 for(
int i = 1; i < Np; i++) {
338 if((Xp[i] != Xp2[Np2 - 1]) || (Yp[i] != Yp2[Np2 - 1]) ||
339 (Zp[i] != Zp2[Np2 - 1])) {
348 if(Xp2[0] == Xp2[Np2 - 1] && Yp2[0] == Yp2[Np2 - 1] &&
349 Zp2[0] == Zp2[Np2 - 1]) {
354 double in1[3] = {X[1] - X[0], Y[1] - Y[0], Z[1] - Z[0]};
355 double in2[3] = {X[2] - X[0], Y[2] - Y[0], Z[2] - Z[0]};
358 double out1[3] = {Xp2[1] - Xp2[0], Yp2[1] - Yp2[0], Zp2[1] - Zp2[0]};
359 double out2[3] = {Xp2[2] - Xp2[0], Yp2[2] - Yp2[0], Zp2[2] - Zp2[0]};
363 if(
prosca(inn, outn) < 0.0) {
364 for(
int i = 0; i < Np2; i++) {
365 Vp[i] = Vp2[Np2 - i - 1];
366 Xp[i] = Xp2[Np2 - i - 1];
367 Yp[i] = Yp2[Np2 - i - 1];
368 Zp[i] = Zp2[Np2 - i - 1];
370 for(
int i = 0; i < Np2; i++) {