| 1 |
– |
/* Copyright (c) 1989 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 3 |
|
#endif |
| 4 |
|
|
| 5 |
+ |
/* Copyright (c) 1989 Regents of the University of California */ |
| 6 |
+ |
|
| 7 |
|
/* |
| 8 |
|
* gensurf.c - program to generate functional surfaces |
| 9 |
|
* |
| 16 |
|
* 4/3/87 |
| 17 |
|
*/ |
| 18 |
|
|
| 19 |
< |
#include <stdio.h> |
| 20 |
< |
#include "fvect.h" |
| 19 |
> |
#include "standard.h" |
| 20 |
|
|
| 21 |
|
#define XNAME "X_" /* x function name */ |
| 22 |
|
#define YNAME "Y_" /* y function name */ |
| 23 |
|
#define ZNAME "Z_" /* z function name */ |
| 24 |
|
|
| 26 |
– |
#define PI 3.14159265358979323846 |
| 27 |
– |
|
| 28 |
– |
#define FTINY 1e-7 |
| 29 |
– |
|
| 25 |
|
#define ABS(x) ((x)>=0 ? (x) : -(x)) |
| 26 |
|
|
| 27 |
|
#define pvect(p) printf(vformat, (p)[0], (p)[1], (p)[2]) |
| 34 |
|
|
| 35 |
|
char *modname, *surfname; |
| 36 |
|
|
| 37 |
< |
double funvalue(), l_hermite(), argument(); |
| 37 |
> |
double funvalue(), l_hermite(), l_bezier(), l_bspline(), argument(); |
| 38 |
|
|
| 39 |
|
typedef struct { |
| 40 |
|
FVECT p; /* vertex position */ |
| 46 |
|
int argc; |
| 47 |
|
char *argv[]; |
| 48 |
|
{ |
| 49 |
+ |
extern long eclock; |
| 50 |
|
POINT *row0, *row1, *row2, *rp; |
| 51 |
|
int i, j, m, n; |
| 52 |
|
char stmp[256]; |
| 53 |
|
|
| 54 |
|
varset("PI", PI); |
| 55 |
|
funset("hermite", 5, l_hermite); |
| 56 |
+ |
funset("bezier", 5, l_bezier); |
| 57 |
+ |
funset("bspline", 5, l_bspline); |
| 58 |
|
|
| 59 |
|
if (argc < 8) |
| 60 |
|
goto userror; |
| 92 |
|
row0++; row1++; row2++; |
| 93 |
|
/* print header */ |
| 94 |
|
printhead(argc, argv); |
| 95 |
+ |
eclock = 0; |
| 96 |
|
/* initialize */ |
| 97 |
|
comprow(-1.0/m, row0, n); |
| 98 |
|
comprow(0.0, row1, n); |
| 221 |
|
int siz; |
| 222 |
|
{ |
| 223 |
|
double st[2]; |
| 224 |
+ |
int end; |
| 225 |
|
register int i; |
| 226 |
< |
/* compute one past each end */ |
| 226 |
> |
|
| 227 |
> |
if (smooth) { |
| 228 |
> |
i = -1; /* compute one past each end */ |
| 229 |
> |
end = siz+1; |
| 230 |
> |
} else { |
| 231 |
> |
if (s < -FTINY || s > 1.0+FTINY) |
| 232 |
> |
return; |
| 233 |
> |
i = 0; |
| 234 |
> |
end = siz; |
| 235 |
> |
} |
| 236 |
|
st[0] = s; |
| 237 |
< |
for (i = -1; i <= siz+1; i++) { |
| 237 |
> |
while (i <= end) { |
| 238 |
|
st[1] = (double)i/siz; |
| 239 |
|
row[i].p[0] = funvalue(XNAME, 2, st); |
| 240 |
|
row[i].p[1] = funvalue(YNAME, 2, st); |
| 241 |
|
row[i].p[2] = funvalue(ZNAME, 2, st); |
| 242 |
+ |
i++; |
| 243 |
|
} |
| 244 |
|
} |
| 245 |
|
|
| 344 |
|
register int i,j,k; |
| 345 |
|
register double temp; |
| 346 |
|
|
| 347 |
< |
bcopy(mat, m4tmp, sizeof(m4tmp)); |
| 347 |
> |
bcopy((char *)mat, (char *)m4tmp, sizeof(m4tmp)); |
| 348 |
|
/* set inverse to identity */ |
| 349 |
|
for (i = 0; i < 4; i++) |
| 350 |
|
for (j = 0; j < 4; j++) |
| 430 |
|
argument(2)*(-2.0*t+3.0)*t*t + |
| 431 |
|
argument(3)*((t-2.0)*t+1.0)*t + |
| 432 |
|
argument(4)*(t-1.0)*t*t ); |
| 433 |
+ |
} |
| 434 |
+ |
|
| 435 |
+ |
|
| 436 |
+ |
double |
| 437 |
+ |
l_bezier() |
| 438 |
+ |
{ |
| 439 |
+ |
double t; |
| 440 |
+ |
|
| 441 |
+ |
t = argument(5); |
| 442 |
+ |
return( argument(1) * (1.+t*(-3.+t*(3.-t))) + |
| 443 |
+ |
argument(2) * 3.*t*(1.+t*(-2.+t)) + |
| 444 |
+ |
argument(3) * 3.*t*t*(1.-t) + |
| 445 |
+ |
argument(4) * t*t*t ); |
| 446 |
+ |
} |
| 447 |
+ |
|
| 448 |
+ |
|
| 449 |
+ |
double |
| 450 |
+ |
l_bspline() |
| 451 |
+ |
{ |
| 452 |
+ |
double t; |
| 453 |
+ |
|
| 454 |
+ |
t = argument(5); |
| 455 |
+ |
return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) + |
| 456 |
+ |
argument(2) * (2./3.+t*t*(-1.+1./2.*t)) + |
| 457 |
+ |
argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) + |
| 458 |
+ |
argument(4) * (1./6.*t*t*t) ); |
| 459 |
|
} |