bchgen.c
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* generate double bivariate Chebychev polynomial */
#ifndef lint
static const char SCCSID[]="@(#)bchgen.c 4.5 94/03/22 GIE REL";
#endif
#include "projects.h"
int
bchgen(projUV a, projUV b, int nu, int nv, projUV **f, projUV(*func)(projUV)) {
int i, j, k;
projUV arg, *t, bma, bpa, *c;
double d, fac;
bma.u = 0.5 * (b.u - a.u); bma.v = 0.5 * (b.v - a.v);
bpa.u = 0.5 * (b.u + a.u); bpa.v = 0.5 * (b.v + a.v);
for ( i = 0; i < nu; ++i) {
arg.u = cos(PI * (i + 0.5) / nu) * bma.u + bpa.u;
for ( j = 0; j < nv; ++j) {
arg.v = cos(PI * (j + 0.5) / nv) * bma.v + bpa.v;
f[i][j] = (*func)(arg);
if ((f[i][j]).u == HUGE_VAL)
return(1);
}
}
if (!(c = (projUV *) vector1(nu, sizeof(projUV)))) return 1;
fac = 2. / nu;
for ( j = 0; j < nv ; ++j) {
for ( i = 0; i < nu; ++i) {
arg.u = arg.v = 0.;
for (k = 0; k < nu; ++k) {
d = cos(PI * i * (k + .5) / nu);
arg.u += f[k][j].u * d;
arg.v += f[k][j].v * d;
}
arg.u *= fac;
arg.v *= fac;
c[i] = arg;
}
for (i = 0; i < nu; ++i)
f[i][j] = c[i];
}
pj_dalloc(c);
if (!(c = (projUV*) vector1(nv, sizeof(projUV)))) return 1;
fac = 2. / nv;
for ( i = 0; i < nu; ++i) {
t = f[i];
for (j = 0; j < nv; ++j) {
arg.u = arg.v = 0.;
for (k = 0; k < nv; ++k) {
d = cos(PI * j * (k + .5) / nv);
arg.u += t[k].u * d;
arg.v += t[k].v * d;
}
arg.u *= fac;
arg.v *= fac;
c[j] = arg;
}
f[i] = c;
c = t;
}
pj_dalloc(c);
return(0);
}