1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: gensurf.c,v 2.22 2013/12/09 22:08:13 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 */ |
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(argc, argv) |
82 |
int argc; |
83 |
char *argv[]; |
84 |
{ |
85 |
POINT *row0, *row1, *row2, *rp; |
86 |
int i, j, m, n; |
87 |
char stmp[256]; |
88 |
|
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 |
fcompile(argv[++i]); |
102 |
else if (!strcmp(argv[i], "-s")) |
103 |
smooth++; |
104 |
else if (!strcmp(argv[i], "-o")) |
105 |
objout++; |
106 |
else |
107 |
goto userror; |
108 |
|
109 |
modname = argv[1]; |
110 |
surfname = argv[2]; |
111 |
m = atoi(argv[6]); |
112 |
n = atoi(argv[7]); |
113 |
if (m <= 0 || n <= 0) |
114 |
goto userror; |
115 |
if (!strcmp(argv[5], "-") || access(argv[5], 4) == 0) { /* file? */ |
116 |
funset(ZNAME, 2, ':', l_dataval); |
117 |
if (!strcmp(argv[5],argv[3]) && !strcmp(argv[5],argv[4])) { |
118 |
loaddata(argv[5], m, n, 3); |
119 |
funset(XNAME, 2, ':', l_dataval); |
120 |
funset(YNAME, 2, ':', l_dataval); |
121 |
} else { |
122 |
loaddata(argv[5], m, n, 1); |
123 |
sprintf(stmp, "%s(s,t)=%s;", XNAME, argv[3]); |
124 |
scompile(stmp, NULL, 0); |
125 |
sprintf(stmp, "%s(s,t)=%s;", YNAME, argv[4]); |
126 |
scompile(stmp, NULL, 0); |
127 |
} |
128 |
} else { |
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 |
sprintf(stmp, "%s(s,t)=%s;", ZNAME, argv[5]); |
134 |
scompile(stmp, NULL, 0); |
135 |
} |
136 |
row0 = (POINT *)malloc((n+3)*sizeof(POINT)); |
137 |
row1 = (POINT *)malloc((n+3)*sizeof(POINT)); |
138 |
row2 = (POINT *)malloc((n+3)*sizeof(POINT)); |
139 |
if (row0 == NULL || row1 == NULL || row2 == NULL) { |
140 |
fprintf(stderr, "%s: out of memory\n", argv[0]); |
141 |
quit(1); |
142 |
} |
143 |
row0++; row1++; row2++; |
144 |
/* print header */ |
145 |
fputs("# ", stdout); |
146 |
printargs(argc, argv, stdout); |
147 |
eclock = 0; |
148 |
/* initialize */ |
149 |
comprow(-1.0/m, row0, n); |
150 |
comprow(0.0, row1, n); |
151 |
comprow(1.0/m, row2, n); |
152 |
compnorms(row0, row1, row2, n); |
153 |
if (objout) { |
154 |
printf("\nusemtl %s\n\n", modname); |
155 |
putobjrow(row1, n); |
156 |
} |
157 |
/* for each row */ |
158 |
for (i = 0; i < m; i++) { |
159 |
/* compute next row */ |
160 |
rp = row0; |
161 |
row0 = row1; |
162 |
row1 = row2; |
163 |
row2 = rp; |
164 |
comprow((double)(i+2)/m, row2, n); |
165 |
compnorms(row0, row1, row2, n); |
166 |
if (objout) |
167 |
putobjrow(row1, n); |
168 |
|
169 |
for (j = 0; j < n; j++) { |
170 |
int orient = (j & 1); |
171 |
/* put polygons */ |
172 |
if (!(row0[j].valid && row1[j+1].valid)) |
173 |
orient = 1; |
174 |
else if (!(row1[j].valid && row0[j+1].valid)) |
175 |
orient = 0; |
176 |
if (orient) |
177 |
putsquare(&row0[j], &row1[j], |
178 |
&row0[j+1], &row1[j+1]); |
179 |
else |
180 |
putsquare(&row1[j], &row1[j+1], |
181 |
&row0[j], &row0[j+1]); |
182 |
} |
183 |
} |
184 |
|
185 |
return 0; |
186 |
|
187 |
userror: |
188 |
fprintf(stderr, "Usage: %s material name ", argv[0]); |
189 |
fprintf(stderr, "x(s,t) y(s,t) z(s,t) m n [-s][-o][-e expr][-f file]\n"); |
190 |
return 1; |
191 |
} |
192 |
|
193 |
|
194 |
void |
195 |
loaddata( /* load point data from file */ |
196 |
char *file, |
197 |
int m, |
198 |
int n, |
199 |
int pointsize |
200 |
) |
201 |
{ |
202 |
FILE *fp; |
203 |
char word[64]; |
204 |
int size; |
205 |
RREAL *dp; |
206 |
|
207 |
datarec.flags = HASBORDER; /* assume border values */ |
208 |
datarec.m = m+1; |
209 |
datarec.n = n+1; |
210 |
size = datarec.m*datarec.n*pointsize; |
211 |
if (pointsize == 3) |
212 |
datarec.flags |= TRIPLETS; |
213 |
dp = (RREAL *)malloc(size*sizeof(RREAL)); |
214 |
if ((datarec.data = dp) == NULL) { |
215 |
fputs("Out of memory\n", stderr); |
216 |
exit(1); |
217 |
} |
218 |
if (!strcmp(file, "-")) { |
219 |
file = "<stdin>"; |
220 |
fp = stdin; |
221 |
} else if ((fp = fopen(file, "r")) == NULL) { |
222 |
fputs(file, stderr); |
223 |
fputs(": cannot open\n", stderr); |
224 |
exit(1); |
225 |
} |
226 |
while (size > 0 && fgetword(word, sizeof(word), fp) != NULL) { |
227 |
if (!isflt(word)) { |
228 |
fprintf(stderr, "%s: garbled data value: %s\n", |
229 |
file, word); |
230 |
exit(1); |
231 |
} |
232 |
*dp++ = atof(word); |
233 |
size--; |
234 |
} |
235 |
if (size == (m+n+1)*pointsize) { /* no border after all */ |
236 |
dp = (RREAL *)realloc(datarec.data, |
237 |
m*n*pointsize*sizeof(RREAL)); |
238 |
if (dp != NULL) |
239 |
datarec.data = dp; |
240 |
datarec.flags &= ~HASBORDER; |
241 |
datarec.m = m; |
242 |
datarec.n = n; |
243 |
size = 0; |
244 |
} |
245 |
if (datarec.m < 2 || datarec.n < 2 || size != 0 || |
246 |
fgetword(word, sizeof(word), fp) != NULL) { |
247 |
fputs(file, stderr); |
248 |
fputs(": bad number of data points\n", stderr); |
249 |
exit(1); |
250 |
} |
251 |
fclose(fp); |
252 |
} |
253 |
|
254 |
|
255 |
double |
256 |
l_dataval( /* return recorded data value */ |
257 |
char *nam |
258 |
) |
259 |
{ |
260 |
double u, v; |
261 |
int i, j; |
262 |
RREAL *dp; |
263 |
double d00, d01, d10, d11; |
264 |
/* compute coordinates */ |
265 |
u = argument(1); v = argument(2); |
266 |
if (datarec.flags & HASBORDER) { |
267 |
i = u *= datarec.m-1; |
268 |
j = v *= datarec.n-1; |
269 |
} else { |
270 |
i = u = u*datarec.m - .5; |
271 |
j = v = v*datarec.n - .5; |
272 |
} |
273 |
if (i < 0) i = 0; |
274 |
else if (i > datarec.m-2) i = datarec.m-2; |
275 |
if (j < 0) j = 0; |
276 |
else if (j > datarec.n-2) j = datarec.n-2; |
277 |
/* compute value */ |
278 |
if (datarec.flags & TRIPLETS) { |
279 |
dp = datarec.data + 3*(j*datarec.m + i); |
280 |
if (nam == ZNAME) |
281 |
dp += 2; |
282 |
else if (nam == YNAME) |
283 |
dp++; |
284 |
d00 = dp[0]; d01 = dp[3]; |
285 |
dp += 3*datarec.m; |
286 |
d10 = dp[0]; d11 = dp[3]; |
287 |
} else { |
288 |
dp = datarec.data + j*datarec.m + i; |
289 |
d00 = dp[0]; d01 = dp[1]; |
290 |
dp += datarec.m; |
291 |
d10 = dp[0]; d11 = dp[1]; |
292 |
} |
293 |
/* bilinear interpolation */ |
294 |
return((j+1-v)*((i+1-u)*d00+(u-i)*d01)+(v-j)*((i+1-u)*d10+(u-i)*d11)); |
295 |
} |
296 |
|
297 |
|
298 |
void |
299 |
putobjrow( /* output vertex row to .OBJ */ |
300 |
POINT *rp, |
301 |
int n |
302 |
) |
303 |
{ |
304 |
for ( ; n-- >= 0; rp++) { |
305 |
if (!rp->valid) |
306 |
continue; |
307 |
fputs("v ", stdout); |
308 |
pvect(rp->p); |
309 |
if (smooth && !ZEROVECT(rp->n)) { |
310 |
printf("\tvn %.9g %.9g %.9g\n", |
311 |
rp->n[0], rp->n[1], rp->n[2]); |
312 |
rp->nvalid = ++nnorms; |
313 |
} else |
314 |
rp->nvalid = 0; |
315 |
printf("\tvt %.9g %.9g\n", rp->uv[0], rp->uv[1]); |
316 |
rp->valid = ++nverts; |
317 |
} |
318 |
} |
319 |
|
320 |
|
321 |
void |
322 |
putobjvert( /* put out OBJ vertex index triplet */ |
323 |
POINT *p |
324 |
) |
325 |
{ |
326 |
int pti = p->valid ? p->valid-nverts-1 : 0; |
327 |
int ni = p->nvalid ? p->nvalid-nnorms-1 : 0; |
328 |
|
329 |
printf(" %d/%d/%d", pti, pti, ni); |
330 |
} |
331 |
|
332 |
|
333 |
void |
334 |
putsquare( /* put out a square */ |
335 |
POINT *p0, |
336 |
POINT *p1, |
337 |
POINT *p2, |
338 |
POINT *p3 |
339 |
) |
340 |
{ |
341 |
static int nout = 0; |
342 |
FVECT norm[4]; |
343 |
int axis; |
344 |
FVECT v1, v2, vc1, vc2; |
345 |
int ok1, ok2; |
346 |
/* compute exact normals */ |
347 |
ok1 = (p0->valid && p1->valid && p2->valid); |
348 |
if (ok1) { |
349 |
VSUB(v1, p1->p, p0->p); |
350 |
VSUB(v2, p2->p, p0->p); |
351 |
fcross(vc1, v1, v2); |
352 |
ok1 = (normalize(vc1) != 0.0); |
353 |
} |
354 |
ok2 = (p1->valid && p2->valid && p3->valid); |
355 |
if (ok2) { |
356 |
VSUB(v1, p2->p, p3->p); |
357 |
VSUB(v2, p1->p, p3->p); |
358 |
fcross(vc2, v1, v2); |
359 |
ok2 = (normalize(vc2) != 0.0); |
360 |
} |
361 |
if (!(ok1 | ok2)) |
362 |
return; |
363 |
if (objout) { /* output .OBJ faces */ |
364 |
if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) { |
365 |
putc('f', stdout); |
366 |
putobjvert(p0); putobjvert(p1); |
367 |
putobjvert(p3); putobjvert(p2); |
368 |
putc('\n', stdout); |
369 |
return; |
370 |
} |
371 |
if (ok1) { |
372 |
putc('f', stdout); |
373 |
putobjvert(p0); putobjvert(p1); putobjvert(p2); |
374 |
putc('\n', stdout); |
375 |
} |
376 |
if (ok2) { |
377 |
putc('f', stdout); |
378 |
putobjvert(p2); putobjvert(p1); putobjvert(p3); |
379 |
putc('\n', stdout); |
380 |
} |
381 |
return; |
382 |
} |
383 |
/* compute normal interpolation */ |
384 |
axis = norminterp(norm, p0, p1, p2, p3); |
385 |
|
386 |
/* put out quadrilateral? */ |
387 |
if (ok1 & ok2 && fdot(vc1,vc2) >= 1.0-FTINY*FTINY) { |
388 |
printf("\n%s ", modname); |
389 |
if (axis != -1) { |
390 |
printf("texfunc %s\n%s\n", texname, tsargs); |
391 |
printf("0\n13\t%d\n", axis); |
392 |
pvect(norm[0]); |
393 |
pvect(norm[1]); |
394 |
pvect(norm[2]); |
395 |
fvsum(v1, norm[3], vc1, -0.5); |
396 |
fvsum(v1, v1, vc2, -0.5); |
397 |
pvect(v1); |
398 |
printf("\n%s ", texname); |
399 |
} |
400 |
printf("polygon %s.%d\n", surfname, ++nout); |
401 |
printf("0\n0\n12\n"); |
402 |
pvect(p0->p); |
403 |
pvect(p1->p); |
404 |
pvect(p3->p); |
405 |
pvect(p2->p); |
406 |
return; |
407 |
} |
408 |
/* put out triangles? */ |
409 |
if (ok1) { |
410 |
printf("\n%s ", modname); |
411 |
if (axis != -1) { |
412 |
printf("texfunc %s\n%s\n", texname, tsargs); |
413 |
printf("0\n13\t%d\n", axis); |
414 |
pvect(norm[0]); |
415 |
pvect(norm[1]); |
416 |
pvect(norm[2]); |
417 |
fvsum(v1, norm[3], vc1, -1.0); |
418 |
pvect(v1); |
419 |
printf("\n%s ", texname); |
420 |
} |
421 |
printf("polygon %s.%d\n", surfname, ++nout); |
422 |
printf("0\n0\n9\n"); |
423 |
pvect(p0->p); |
424 |
pvect(p1->p); |
425 |
pvect(p2->p); |
426 |
} |
427 |
if (ok2) { |
428 |
printf("\n%s ", modname); |
429 |
if (axis != -1) { |
430 |
printf("texfunc %s\n%s\n", texname, tsargs); |
431 |
printf("0\n13\t%d\n", axis); |
432 |
pvect(norm[0]); |
433 |
pvect(norm[1]); |
434 |
pvect(norm[2]); |
435 |
fvsum(v2, norm[3], vc2, -1.0); |
436 |
pvect(v2); |
437 |
printf("\n%s ", texname); |
438 |
} |
439 |
printf("polygon %s.%d\n", surfname, ++nout); |
440 |
printf("0\n0\n9\n"); |
441 |
pvect(p2->p); |
442 |
pvect(p1->p); |
443 |
pvect(p3->p); |
444 |
} |
445 |
} |
446 |
|
447 |
|
448 |
void |
449 |
comprow( /* compute row of values */ |
450 |
double s, |
451 |
POINT *row, |
452 |
int siz |
453 |
) |
454 |
{ |
455 |
double st[2]; |
456 |
int end; |
457 |
int checkvalid; |
458 |
int i; |
459 |
|
460 |
if (smooth) { |
461 |
i = -1; /* compute one past each end */ |
462 |
end = siz+1; |
463 |
} else { |
464 |
if (s < -FTINY || s > 1.0+FTINY) |
465 |
return; |
466 |
i = 0; |
467 |
end = siz; |
468 |
} |
469 |
st[0] = s; |
470 |
checkvalid = (fundefined(VNAME) == 2); |
471 |
while (i <= end) { |
472 |
st[1] = (double)i/siz; |
473 |
if (checkvalid && funvalue(VNAME, 2, st) <= 0.0) { |
474 |
row[i].valid = 0; |
475 |
row[i].p[0] = row[i].p[1] = row[i].p[2] = 0.0; |
476 |
row[i].uv[0] = row[i].uv[1] = 0.0; |
477 |
} else { |
478 |
row[i].valid = 1; |
479 |
row[i].p[0] = funvalue(XNAME, 2, st); |
480 |
row[i].p[1] = funvalue(YNAME, 2, st); |
481 |
row[i].p[2] = funvalue(ZNAME, 2, st); |
482 |
row[i].uv[0] = st[0]; |
483 |
row[i].uv[1] = st[1]; |
484 |
} |
485 |
i++; |
486 |
} |
487 |
} |
488 |
|
489 |
|
490 |
void |
491 |
compnorms( /* compute row of averaged normals */ |
492 |
POINT *r0, |
493 |
POINT *r1, |
494 |
POINT *r2, |
495 |
int siz |
496 |
) |
497 |
{ |
498 |
FVECT v1, v2; |
499 |
|
500 |
if (!smooth) /* not needed if no smoothing */ |
501 |
return; |
502 |
/* compute row 1 normals */ |
503 |
while (siz-- >= 0) { |
504 |
if (!r1[0].valid) |
505 |
continue; |
506 |
if (!r0[0].valid) { |
507 |
if (!r2[0].valid) { |
508 |
r1[0].n[0] = r1[0].n[1] = r1[0].n[2] = 0.0; |
509 |
continue; |
510 |
} |
511 |
fvsum(v1, r2[0].p, r1[0].p, -1.0); |
512 |
} else if (!r2[0].valid) |
513 |
fvsum(v1, r1[0].p, r0[0].p, -1.0); |
514 |
else |
515 |
fvsum(v1, r2[0].p, r0[0].p, -1.0); |
516 |
if (!r1[-1].valid) { |
517 |
if (!r1[1].valid) { |
518 |
r1[0].n[0] = r1[0].n[1] = r1[0].n[2] = 0.0; |
519 |
continue; |
520 |
} |
521 |
fvsum(v2, r1[1].p, r1[0].p, -1.0); |
522 |
} else if (!r1[1].valid) |
523 |
fvsum(v2, r1[0].p, r1[-1].p, -1.0); |
524 |
else |
525 |
fvsum(v2, r1[1].p, r1[-1].p, -1.0); |
526 |
fcross(r1[0].n, v1, v2); |
527 |
normalize(r1[0].n); |
528 |
r0++; r1++; r2++; |
529 |
} |
530 |
} |
531 |
|
532 |
|
533 |
int |
534 |
norminterp( /* compute normal interpolation */ |
535 |
FVECT resmat[4], |
536 |
POINT *p0, |
537 |
POINT *p1, |
538 |
POINT *p2, |
539 |
POINT *p3 |
540 |
) |
541 |
{ |
542 |
#define u ((ax+1)%3) |
543 |
#define v ((ax+2)%3) |
544 |
|
545 |
int ax; |
546 |
MAT4 eqnmat; |
547 |
FVECT v1; |
548 |
int i, j; |
549 |
|
550 |
if (!smooth) /* no interpolation if no smoothing */ |
551 |
return(-1); |
552 |
/* find dominant axis */ |
553 |
VCOPY(v1, p0->n); |
554 |
fvsum(v1, v1, p1->n, 1.0); |
555 |
fvsum(v1, v1, p2->n, 1.0); |
556 |
fvsum(v1, v1, p3->n, 1.0); |
557 |
ax = ABS(v1[0]) > ABS(v1[1]) ? 0 : 1; |
558 |
ax = ABS(v1[ax]) > ABS(v1[2]) ? ax : 2; |
559 |
/* assign equation matrix */ |
560 |
eqnmat[0][0] = p0->p[u]*p0->p[v]; |
561 |
eqnmat[0][1] = p0->p[u]; |
562 |
eqnmat[0][2] = p0->p[v]; |
563 |
eqnmat[0][3] = 1.0; |
564 |
eqnmat[1][0] = p1->p[u]*p1->p[v]; |
565 |
eqnmat[1][1] = p1->p[u]; |
566 |
eqnmat[1][2] = p1->p[v]; |
567 |
eqnmat[1][3] = 1.0; |
568 |
eqnmat[2][0] = p2->p[u]*p2->p[v]; |
569 |
eqnmat[2][1] = p2->p[u]; |
570 |
eqnmat[2][2] = p2->p[v]; |
571 |
eqnmat[2][3] = 1.0; |
572 |
eqnmat[3][0] = p3->p[u]*p3->p[v]; |
573 |
eqnmat[3][1] = p3->p[u]; |
574 |
eqnmat[3][2] = p3->p[v]; |
575 |
eqnmat[3][3] = 1.0; |
576 |
/* invert matrix (solve system) */ |
577 |
if (!invmat4(eqnmat, eqnmat)) |
578 |
return(-1); /* no solution */ |
579 |
/* compute result matrix */ |
580 |
for (j = 0; j < 4; j++) |
581 |
for (i = 0; i < 3; i++) |
582 |
resmat[j][i] = eqnmat[j][0]*p0->n[i] + |
583 |
eqnmat[j][1]*p1->n[i] + |
584 |
eqnmat[j][2]*p2->n[i] + |
585 |
eqnmat[j][3]*p3->n[i]; |
586 |
return(ax); |
587 |
|
588 |
#undef u |
589 |
#undef v |
590 |
} |
591 |
|
592 |
|
593 |
double |
594 |
l_hermite(char *nm) |
595 |
{ |
596 |
double t; |
597 |
|
598 |
t = argument(5); |
599 |
return( argument(1)*((2.0*t-3.0)*t*t+1.0) + |
600 |
argument(2)*(-2.0*t+3.0)*t*t + |
601 |
argument(3)*((t-2.0)*t+1.0)*t + |
602 |
argument(4)*(t-1.0)*t*t ); |
603 |
} |
604 |
|
605 |
|
606 |
double |
607 |
l_bezier(char *nm) |
608 |
{ |
609 |
double t; |
610 |
|
611 |
t = argument(5); |
612 |
return( argument(1) * (1.+t*(-3.+t*(3.-t))) + |
613 |
argument(2) * 3.*t*(1.+t*(-2.+t)) + |
614 |
argument(3) * 3.*t*t*(1.-t) + |
615 |
argument(4) * t*t*t ); |
616 |
} |
617 |
|
618 |
|
619 |
double |
620 |
l_bspline(char *nm) |
621 |
{ |
622 |
double t; |
623 |
|
624 |
t = argument(5); |
625 |
return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) + |
626 |
argument(2) * (2./3.+t*t*(-1.+1./2.*t)) + |
627 |
argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) + |
628 |
argument(4) * (1./6.*t*t*t) ); |
629 |
} |