1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: gensurf.c,v 2.29 2021/04/01 14:52:55 greg Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* gensurf.c - program to generate functional surfaces |
6 |
* |
7 |
* Parametric functions x(s,t), y(s,t) and z(s,t) |
8 |
* specify the surface, which is tesselated into an m by n |
9 |
* array of paired triangles. |
10 |
* The surface normal is defined by the right hand |
11 |
* rule applied to (s,t). |
12 |
* |
13 |
* 4/3/87 |
14 |
* |
15 |
* 4/16/02 Added conditional vertex output |
16 |
*/ |
17 |
|
18 |
#include "standard.h" |
19 |
|
20 |
#include "paths.h" |
21 |
#include "resolu.h" |
22 |
#include "rterror.h" |
23 |
#include "calcomp.h" |
24 |
|
25 |
char XNAME[] = "X`SYS"; /* x function name */ |
26 |
char YNAME[] = "Y`SYS"; /* y function name */ |
27 |
char ZNAME[] = "Z`SYS"; /* z function name */ |
28 |
|
29 |
char VNAME[] = "valid"; /* valid vertex name */ |
30 |
|
31 |
#define ABS(x) ((x)>=0 ? (x) : -(x)) |
32 |
|
33 |
#define ZEROVECT(v) (DOT(v,v) <= FTINY*FTINY) |
34 |
|
35 |
#define pvect(p) printf(vformat, (p)[0], (p)[1], (p)[2]) |
36 |
|
37 |
char vformat[] = "%18.12g %18.12g %18.12g\n"; |
38 |
char tsargs[] = "4 surf_dx surf_dy surf_dz surf.cal"; |
39 |
char texname[] = "Phong"; |
40 |
|
41 |
int smooth = 0; /* apply smoothing? */ |
42 |
int objout = 0; /* output .OBJ format? */ |
43 |
|
44 |
char *modname, *surfname; |
45 |
|
46 |
/* recorded data flags */ |
47 |
#define HASBORDER 01 |
48 |
#define TRIPLETS 02 |
49 |
/* a data structure */ |
50 |
struct { |
51 |
int flags; /* data type */ |
52 |
short m, n; /* number of s and t values */ |
53 |
RREAL *data; /* the data itself, s major sort */ |
54 |
} datarec; /* our recorded data */ |
55 |
|
56 |
/* XXX this is redundant with rt/noise3.c, should go to a library */ |
57 |
double l_hermite(), l_bezier(), l_bspline(), l_dataval(); |
58 |
|
59 |
typedef struct { |
60 |
int valid; /* point is valid (vertex number) */ |
61 |
int nvalid; /* normal is valid (normal number) */ |
62 |
FVECT p; /* vertex position */ |
63 |
FVECT n; /* average normal */ |
64 |
RREAL uv[2]; /* (u,v) position */ |
65 |
} POINT; |
66 |
|
67 |
int nverts = 0; /* vertex output count */ |
68 |
int nnorms = 0; /* normal output count */ |
69 |
|
70 |
void loaddata(char *file, int m, int n, int pointsize); |
71 |
double l_dataval(char *nam); |
72 |
void putobjrow(POINT *rp, int n); |
73 |
void putobjvert(POINT *p); |
74 |
void putsquare(POINT *p0, POINT *p1, POINT *p2, POINT *p3); |
75 |
void comprow(double s, POINT *row, int siz); |
76 |
void compnorms(POINT *r0, POINT *r1, POINT *r2, int siz); |
77 |
int norminterp(FVECT resmat[4], POINT *p0, POINT *p1, POINT *p2, POINT *p3); |
78 |
|
79 |
|
80 |
int |
81 |
main(int argc, char *argv[]) |
82 |
{ |
83 |
POINT *row0, *row1, *row2, *rp; |
84 |
int i, j, m, n; |
85 |
char stmp[256]; |
86 |
|
87 |
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
88 |
esupport &= ~(E_OUTCHAN|E_INCHAN); |
89 |
varset("PI", ':', PI); |
90 |
funset("hermite", 5, ':', l_hermite); |
91 |
funset("bezier", 5, ':', l_bezier); |
92 |
funset("bspline", 5, ':', l_bspline); |
93 |
|
94 |
if (argc < 8) |
95 |
goto userror; |
96 |
|
97 |
for (i = 8; i < argc; i++) |
98 |
if (!strcmp(argv[i], "-e")) |
99 |
scompile(argv[++i], NULL, 0); |
100 |
else if (!strcmp(argv[i], "-f")) { |
101 |
char *fpath = getpath(argv[++i], getrlibpath(), 0); |
102 |
if (fpath == NULL) { |
103 |
fprintf(stderr, "%s: cannot find file '%s'\n", |
104 |
argv[0], argv[i]); |
105 |
quit(1); |
106 |
} |
107 |
fcompile(fpath); |
108 |
} else if (!strcmp(argv[i], "-s")) |
109 |
smooth++; |
110 |
else if (!strcmp(argv[i], "-o")) |
111 |
objout++; |
112 |
else |
113 |
goto userror; |
114 |
|
115 |
modname = argv[1]; |
116 |
surfname = argv[2]; |
117 |
m = eval(argv[6]) + .5; |
118 |
n = eval(argv[7]) + .5; |
119 |
if (m <= 0 || n <= 0) |
120 |
goto userror; |
121 |
if (!strcmp(argv[5], "-") || access(argv[5], 4) == 0) { /* file? */ |
122 |
funset(ZNAME, 2, ':', l_dataval); |
123 |
if (!strcmp(argv[5],argv[3]) && !strcmp(argv[5],argv[4])) { |
124 |
loaddata(argv[5], m, n, 3); |
125 |
funset(XNAME, 2, ':', l_dataval); |
126 |
funset(YNAME, 2, ':', l_dataval); |
127 |
} else { |
128 |
loaddata(argv[5], m, n, 1); |
129 |
sprintf(stmp, "%s(s,t)=%s;", XNAME, argv[3]); |
130 |
scompile(stmp, NULL, 0); |
131 |
sprintf(stmp, "%s(s,t)=%s;", YNAME, argv[4]); |
132 |
scompile(stmp, NULL, 0); |
133 |
} |
134 |
} else { |
135 |
sprintf(stmp, "%s(s,t)=%s;", XNAME, argv[3]); |
136 |
scompile(stmp, NULL, 0); |
137 |
sprintf(stmp, "%s(s,t)=%s;", YNAME, argv[4]); |
138 |
scompile(stmp, NULL, 0); |
139 |
sprintf(stmp, "%s(s,t)=%s;", ZNAME, argv[5]); |
140 |
scompile(stmp, NULL, 0); |
141 |
} |
142 |
row0 = (POINT *)malloc((n+3)*sizeof(POINT)); |
143 |
row1 = (POINT *)malloc((n+3)*sizeof(POINT)); |
144 |
row2 = (POINT *)malloc((n+3)*sizeof(POINT)); |
145 |
if (row0 == NULL || row1 == NULL || row2 == NULL) { |
146 |
fprintf(stderr, "%s: out of memory\n", argv[0]); |
147 |
quit(1); |
148 |
} |
149 |
row0++; row1++; row2++; |
150 |
/* print header */ |
151 |
fputs("# ", stdout); |
152 |
printargs(argc, argv, stdout); |
153 |
eclock = 1; |
154 |
/* initialize */ |
155 |
comprow(-1.0/m, row0, n); |
156 |
comprow(0.0, row1, n); |
157 |
comprow(1.0/m, row2, n); |
158 |
compnorms(row0, row1, row2, n); |
159 |
if (objout) { |
160 |
printf("\nusemtl %s\n\n", modname); |
161 |
printf("o %s\n\n", surfname); |
162 |
putobjrow(row1, n); |
163 |
} |
164 |
/* for each row */ |
165 |
for (i = 0; i < m; i++) { |
166 |
/* compute next row */ |
167 |
rp = row0; |
168 |
row0 = row1; |
169 |
row1 = row2; |
170 |
row2 = rp; |
171 |
comprow((double)(i+2)/m, row2, n); |
172 |
compnorms(row0, row1, row2, n); |
173 |
if (objout) |
174 |
putobjrow(row1, n); |
175 |
|
176 |
for (j = 0; j < n; j++) { |
177 |
int orient = (j & 1); |
178 |
/* put polygons */ |
179 |
if (!(row0[j].valid && row1[j+1].valid)) |
180 |
orient = 1; |
181 |
else if (!(row1[j].valid && row0[j+1].valid)) |
182 |
orient = 0; |
183 |
if (orient) |
184 |
putsquare(&row0[j], &row1[j], |
185 |
&row0[j+1], &row1[j+1]); |
186 |
else |
187 |
putsquare(&row1[j], &row1[j+1], |
188 |
&row0[j], &row0[j+1]); |
189 |
} |
190 |
} |
191 |
|
192 |
return 0; |
193 |
|
194 |
userror: |
195 |
fprintf(stderr, "Usage: %s material name ", argv[0]); |
196 |
fprintf(stderr, "x(s,t) y(s,t) z(s,t) m n [-s][-o][-e expr][-f file]\n"); |
197 |
return 1; |
198 |
} |
199 |
|
200 |
|
201 |
void |
202 |
loaddata( /* load point data from file */ |
203 |
char *file, |
204 |
int m, |
205 |
int n, |
206 |
int pointsize |
207 |
) |
208 |
{ |
209 |
FILE *fp; |
210 |
char word[64]; |
211 |
int size; |
212 |
RREAL *dp; |
213 |
|
214 |
datarec.flags = HASBORDER; /* assume border values */ |
215 |
datarec.m = m+1; |
216 |
datarec.n = n+1; |
217 |
size = datarec.m*datarec.n*pointsize; |
218 |
if (pointsize == 3) |
219 |
datarec.flags |= TRIPLETS; |
220 |
dp = (RREAL *)malloc(size*sizeof(RREAL)); |
221 |
if ((datarec.data = dp) == NULL) { |
222 |
fputs("Out of memory\n", stderr); |
223 |
exit(1); |
224 |
} |
225 |
if (!strcmp(file, "-")) { |
226 |
file = "<stdin>"; |
227 |
fp = stdin; |
228 |
} else if ((fp = fopen(file, "r")) == NULL) { |
229 |
fputs(file, stderr); |
230 |
fputs(": cannot open\n", stderr); |
231 |
exit(1); |
232 |
} |
233 |
while (size > 0 && fgetword(word, sizeof(word), fp) != NULL) { |
234 |
if (!isflt(word)) { |
235 |
fprintf(stderr, "%s: garbled data value: %s\n", |
236 |
file, word); |
237 |
exit(1); |
238 |
} |
239 |
*dp++ = atof(word); |
240 |
size--; |
241 |
} |
242 |
if (size == (m+n+1)*pointsize) { /* no border after all */ |
243 |
dp = (RREAL *)realloc(datarec.data, |
244 |
m*n*pointsize*sizeof(RREAL)); |
245 |
if (dp != NULL) |
246 |
datarec.data = dp; |
247 |
datarec.flags &= ~HASBORDER; |
248 |
datarec.m = m; |
249 |
datarec.n = n; |
250 |
size = 0; |
251 |
} |
252 |
if (datarec.m < 2 || datarec.n < 2 || size != 0 || |
253 |
fgetword(word, sizeof(word), fp) != NULL) { |
254 |
fputs(file, stderr); |
255 |
fputs(": bad number of data points\n", stderr); |
256 |
exit(1); |
257 |
} |
258 |
fclose(fp); |
259 |
} |
260 |
|
261 |
|
262 |
double |
263 |
l_dataval( /* return recorded data value */ |
264 |
char *nam |
265 |
) |
266 |
{ |
267 |
double u, v; |
268 |
int i, j; |
269 |
RREAL *dp; |
270 |
double d00, d01, d10, d11; |
271 |
/* compute coordinates */ |
272 |
u = argument(1); v = argument(2); |
273 |
if (datarec.flags & HASBORDER) { |
274 |
i = u *= datarec.m-1; |
275 |
j = v *= datarec.n-1; |
276 |
} else { |
277 |
i = u = u*datarec.m - .5; |
278 |
j = v = v*datarec.n - .5; |
279 |
} |
280 |
if (i < 0) i = 0; |
281 |
else if (i > datarec.m-2) i = datarec.m-2; |
282 |
if (j < 0) j = 0; |
283 |
else if (j > datarec.n-2) j = datarec.n-2; |
284 |
/* compute value */ |
285 |
if (datarec.flags & TRIPLETS) { |
286 |
dp = datarec.data + 3*(j*datarec.m + i); |
287 |
if (nam == ZNAME) |
288 |
dp += 2; |
289 |
else if (nam == YNAME) |
290 |
dp++; |
291 |
d00 = dp[0]; d01 = dp[3]; |
292 |
dp += 3*datarec.m; |
293 |
d10 = dp[0]; d11 = dp[3]; |
294 |
} else { |
295 |
dp = datarec.data + j*datarec.m + i; |
296 |
d00 = dp[0]; d01 = dp[1]; |
297 |
dp += datarec.m; |
298 |
d10 = dp[0]; d11 = dp[1]; |
299 |
} |
300 |
/* bilinear interpolation */ |
301 |
return((j+1-v)*((i+1-u)*d00+(u-i)*d01)+(v-j)*((i+1-u)*d10+(u-i)*d11)); |
302 |
} |
303 |
|
304 |
|
305 |
void |
306 |
putobjrow( /* output vertex row to .OBJ */ |
307 |
POINT *rp, |
308 |
int n |
309 |
) |
310 |
{ |
311 |
static FVECT prevNorm; |
312 |
|
313 |
for ( ; n-- >= 0; rp++) { |
314 |
if (!rp->valid) |
315 |
continue; |
316 |
fputs("v ", stdout); |
317 |
pvect(rp->p); |
318 |
rp->valid = ++nverts; |
319 |
printf("\tvt %.9g %.9g\n", rp->uv[0], rp->uv[1]); |
320 |
if (!smooth || ZEROVECT(rp->n)) |
321 |
rp->nvalid = 0; |
322 |
else if (VABSEQ(rp->n, prevNorm)) |
323 |
rp->nvalid = nnorms; |
324 |
else { |
325 |
printf("\tvn %.9g %.9g %.9g\n", |
326 |
rp->n[0], rp->n[1], rp->n[2]); |
327 |
rp->nvalid = ++nnorms; |
328 |
VCOPY(prevNorm, rp->n); |
329 |
} |
330 |
} |
331 |
} |
332 |
|
333 |
|
334 |
void |
335 |
putobjvert( /* put out OBJ vertex index triplet */ |
336 |
POINT *p |
337 |
) |
338 |
{ |
339 |
int pti = p->valid ? p->valid-nverts-1 : 0; |
340 |
int ni = p->nvalid ? p->nvalid-nnorms-1 : 0; |
341 |
|
342 |
printf(" %d/%d/%d", pti, pti, ni); |
343 |
} |
344 |
|
345 |
|
346 |
void |
347 |
putsquare( /* put out a square */ |
348 |
POINT *p0, |
349 |
POINT *p1, |
350 |
POINT *p2, |
351 |
POINT *p3 |
352 |
) |
353 |
{ |
354 |
static int nout = 0; |
355 |
FVECT norm[4]; |
356 |
int axis; |
357 |
FVECT v1, v2, vc1, vc2; |
358 |
int ok1, ok2; |
359 |
/* compute exact normals */ |
360 |
ok1 = (p0->valid && p1->valid && p2->valid); |
361 |
if (ok1) { |
362 |
VSUB(v1, p1->p, p0->p); |
363 |
VSUB(v2, p2->p, p0->p); |
364 |
fcross(vc1, v1, v2); |
365 |
ok1 = (normalize(vc1) != 0.0); |
366 |
} |
367 |
ok2 = (p1->valid && p2->valid && p3->valid); |
368 |
if (ok2) { |
369 |
VSUB(v1, p2->p, p3->p); |
370 |
VSUB(v2, p1->p, p3->p); |
371 |
fcross(vc2, v1, v2); |
372 |
ok2 = (normalize(vc2) != 0.0); |
373 |
} |
374 |
if (!(ok1 | ok2)) |
375 |
return; |
376 |
if (objout) { /* output .OBJ faces */ |
377 |
if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) { |
378 |
putc('f', stdout); |
379 |
putobjvert(p0); putobjvert(p1); |
380 |
putobjvert(p3); putobjvert(p2); |
381 |
putc('\n', stdout); |
382 |
return; |
383 |
} |
384 |
if (ok1) { |
385 |
putc('f', stdout); |
386 |
putobjvert(p0); putobjvert(p1); putobjvert(p2); |
387 |
putc('\n', stdout); |
388 |
} |
389 |
if (ok2) { |
390 |
putc('f', stdout); |
391 |
putobjvert(p2); putobjvert(p1); putobjvert(p3); |
392 |
putc('\n', stdout); |
393 |
} |
394 |
return; |
395 |
} |
396 |
/* compute normal interpolation */ |
397 |
axis = norminterp(norm, p0, p1, p2, p3); |
398 |
|
399 |
/* put out quadrilateral? */ |
400 |
if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) { |
401 |
printf("\n%s ", modname); |
402 |
if (axis != -1) { |
403 |
printf("texfunc %s\n%s\n", texname, tsargs); |
404 |
printf("0\n13\t%d\n", axis); |
405 |
pvect(norm[0]); |
406 |
pvect(norm[1]); |
407 |
pvect(norm[2]); |
408 |
fvsum(v1, norm[3], vc1, -0.5); |
409 |
fvsum(v1, v1, vc2, -0.5); |
410 |
pvect(v1); |
411 |
printf("\n%s ", texname); |
412 |
} |
413 |
printf("polygon %s.%d\n", surfname, ++nout); |
414 |
printf("0\n0\n12\n"); |
415 |
pvect(p0->p); |
416 |
pvect(p1->p); |
417 |
pvect(p3->p); |
418 |
pvect(p2->p); |
419 |
return; |
420 |
} |
421 |
/* put out triangles? */ |
422 |
if (ok1) { |
423 |
printf("\n%s ", modname); |
424 |
if (axis != -1) { |
425 |
printf("texfunc %s\n%s\n", texname, tsargs); |
426 |
printf("0\n13\t%d\n", axis); |
427 |
pvect(norm[0]); |
428 |
pvect(norm[1]); |
429 |
pvect(norm[2]); |
430 |
fvsum(v1, norm[3], vc1, -1.0); |
431 |
pvect(v1); |
432 |
printf("\n%s ", texname); |
433 |
} |
434 |
printf("polygon %s.%d\n", surfname, ++nout); |
435 |
printf("0\n0\n9\n"); |
436 |
pvect(p0->p); |
437 |
pvect(p1->p); |
438 |
pvect(p2->p); |
439 |
} |
440 |
if (ok2) { |
441 |
printf("\n%s ", modname); |
442 |
if (axis != -1) { |
443 |
printf("texfunc %s\n%s\n", texname, tsargs); |
444 |
printf("0\n13\t%d\n", axis); |
445 |
pvect(norm[0]); |
446 |
pvect(norm[1]); |
447 |
pvect(norm[2]); |
448 |
fvsum(v2, norm[3], vc2, -1.0); |
449 |
pvect(v2); |
450 |
printf("\n%s ", texname); |
451 |
} |
452 |
printf("polygon %s.%d\n", surfname, ++nout); |
453 |
printf("0\n0\n9\n"); |
454 |
pvect(p2->p); |
455 |
pvect(p1->p); |
456 |
pvect(p3->p); |
457 |
} |
458 |
} |
459 |
|
460 |
|
461 |
void |
462 |
comprow( /* compute row of values */ |
463 |
double s, |
464 |
POINT *row, |
465 |
int siz |
466 |
) |
467 |
{ |
468 |
double st[2]; |
469 |
int end; |
470 |
int checkvalid; |
471 |
int i; |
472 |
|
473 |
if (smooth) { |
474 |
i = -1; /* compute one past each end */ |
475 |
end = siz+1; |
476 |
} else { |
477 |
if (s < -FTINY || s > 1.0+FTINY) |
478 |
return; |
479 |
i = 0; |
480 |
end = siz; |
481 |
} |
482 |
st[0] = s; |
483 |
checkvalid = (fundefined(VNAME) == 2); |
484 |
while (i <= end) { |
485 |
st[1] = (double)i/siz; |
486 |
if (checkvalid && funvalue(VNAME, 2, st) <= 0.0) { |
487 |
row[i].valid = 0; |
488 |
row[i].p[0] = row[i].p[1] = row[i].p[2] = 0.0; |
489 |
row[i].uv[0] = row[i].uv[1] = 0.0; |
490 |
} else { |
491 |
row[i].valid = 1; |
492 |
row[i].p[0] = funvalue(XNAME, 2, st); |
493 |
row[i].p[1] = funvalue(YNAME, 2, st); |
494 |
row[i].p[2] = funvalue(ZNAME, 2, st); |
495 |
row[i].uv[0] = st[0]; |
496 |
row[i].uv[1] = st[1]; |
497 |
} |
498 |
i++; |
499 |
} |
500 |
} |
501 |
|
502 |
|
503 |
void |
504 |
compnorms( /* compute row of averaged normals */ |
505 |
POINT *r0, |
506 |
POINT *r1, |
507 |
POINT *r2, |
508 |
int siz |
509 |
) |
510 |
{ |
511 |
FVECT v1, v2; |
512 |
|
513 |
if (!smooth) /* not needed if no smoothing */ |
514 |
return; |
515 |
/* compute row 1 normals */ |
516 |
while (siz-- >= 0) { |
517 |
if (!r1[0].valid) |
518 |
goto skip; |
519 |
if (!r0[0].valid) { |
520 |
if (!r2[0].valid) { |
521 |
r1[0].n[0] = r1[0].n[1] = r1[0].n[2] = 0.0; |
522 |
goto skip; |
523 |
} |
524 |
fvsum(v1, r2[0].p, r1[0].p, -1.0); |
525 |
} else if (!r2[0].valid) |
526 |
fvsum(v1, r1[0].p, r0[0].p, -1.0); |
527 |
else |
528 |
fvsum(v1, r2[0].p, r0[0].p, -1.0); |
529 |
if (!r1[-1].valid) { |
530 |
if (!r1[1].valid) { |
531 |
r1[0].n[0] = r1[0].n[1] = r1[0].n[2] = 0.0; |
532 |
goto skip; |
533 |
} |
534 |
fvsum(v2, r1[1].p, r1[0].p, -1.0); |
535 |
} else if (!r1[1].valid) |
536 |
fvsum(v2, r1[0].p, r1[-1].p, -1.0); |
537 |
else |
538 |
fvsum(v2, r1[1].p, r1[-1].p, -1.0); |
539 |
fcross(r1[0].n, v1, v2); |
540 |
normalize(r1[0].n); |
541 |
skip: |
542 |
r0++; r1++; r2++; |
543 |
} |
544 |
} |
545 |
|
546 |
|
547 |
int |
548 |
norminterp( /* compute normal interpolation */ |
549 |
FVECT resmat[4], |
550 |
POINT *p0, |
551 |
POINT *p1, |
552 |
POINT *p2, |
553 |
POINT *p3 |
554 |
) |
555 |
{ |
556 |
#define u ((ax+1)%3) |
557 |
#define v ((ax+2)%3) |
558 |
|
559 |
int ax; |
560 |
MAT4 eqnmat; |
561 |
FVECT v1; |
562 |
int i, j; |
563 |
|
564 |
if (!smooth) /* no interpolation if no smoothing */ |
565 |
return(-1); |
566 |
/* find dominant axis */ |
567 |
VCOPY(v1, p0->n); |
568 |
fvsum(v1, v1, p1->n, 1.0); |
569 |
fvsum(v1, v1, p2->n, 1.0); |
570 |
fvsum(v1, v1, p3->n, 1.0); |
571 |
ax = ABS(v1[0]) > ABS(v1[1]) ? 0 : 1; |
572 |
ax = ABS(v1[ax]) > ABS(v1[2]) ? ax : 2; |
573 |
/* assign equation matrix */ |
574 |
eqnmat[0][0] = p0->p[u]*p0->p[v]; |
575 |
eqnmat[0][1] = p0->p[u]; |
576 |
eqnmat[0][2] = p0->p[v]; |
577 |
eqnmat[0][3] = 1.0; |
578 |
eqnmat[1][0] = p1->p[u]*p1->p[v]; |
579 |
eqnmat[1][1] = p1->p[u]; |
580 |
eqnmat[1][2] = p1->p[v]; |
581 |
eqnmat[1][3] = 1.0; |
582 |
eqnmat[2][0] = p2->p[u]*p2->p[v]; |
583 |
eqnmat[2][1] = p2->p[u]; |
584 |
eqnmat[2][2] = p2->p[v]; |
585 |
eqnmat[2][3] = 1.0; |
586 |
eqnmat[3][0] = p3->p[u]*p3->p[v]; |
587 |
eqnmat[3][1] = p3->p[u]; |
588 |
eqnmat[3][2] = p3->p[v]; |
589 |
eqnmat[3][3] = 1.0; |
590 |
/* invert matrix (solve system) */ |
591 |
if (!invmat4(eqnmat, eqnmat)) |
592 |
return(-1); /* no solution */ |
593 |
/* compute result matrix */ |
594 |
for (j = 0; j < 4; j++) |
595 |
for (i = 0; i < 3; i++) |
596 |
resmat[j][i] = eqnmat[j][0]*p0->n[i] + |
597 |
eqnmat[j][1]*p1->n[i] + |
598 |
eqnmat[j][2]*p2->n[i] + |
599 |
eqnmat[j][3]*p3->n[i]; |
600 |
return(ax); |
601 |
|
602 |
#undef u |
603 |
#undef v |
604 |
} |
605 |
|
606 |
|
607 |
double |
608 |
l_hermite(char *nm) |
609 |
{ |
610 |
double t; |
611 |
|
612 |
t = argument(5); |
613 |
return( argument(1)*((2.0*t-3.0)*t*t+1.0) + |
614 |
argument(2)*(-2.0*t+3.0)*t*t + |
615 |
argument(3)*((t-2.0)*t+1.0)*t + |
616 |
argument(4)*(t-1.0)*t*t ); |
617 |
} |
618 |
|
619 |
|
620 |
double |
621 |
l_bezier(char *nm) |
622 |
{ |
623 |
double t; |
624 |
|
625 |
t = argument(5); |
626 |
return( argument(1) * (1.+t*(-3.+t*(3.-t))) + |
627 |
argument(2) * 3.*t*(1.+t*(-2.+t)) + |
628 |
argument(3) * 3.*t*t*(1.-t) + |
629 |
argument(4) * t*t*t ); |
630 |
} |
631 |
|
632 |
|
633 |
double |
634 |
l_bspline(char *nm) |
635 |
{ |
636 |
double t; |
637 |
|
638 |
t = argument(5); |
639 |
return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) + |
640 |
argument(2) * (2./3.+t*t*(-1.+1./2.*t)) + |
641 |
argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) + |
642 |
argument(4) * (1./6.*t*t*t) ); |
643 |
} |