1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Routines to compute "ambient" values using Monte Carlo |
6 |
+ |
* |
7 |
+ |
* Declarations of external symbols in ambient.h |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "copyright.h" |
11 |
+ |
|
12 |
|
#include "ray.h" |
13 |
|
|
14 |
|
#include "ambient.h" |
15 |
|
|
16 |
|
#include "random.h" |
17 |
|
|
17 |
– |
typedef struct { |
18 |
– |
short t, p; /* theta, phi indices */ |
19 |
– |
COLOR v; /* value sum */ |
20 |
– |
float r; /* 1/distance sum */ |
21 |
– |
float k; /* variance for this division */ |
22 |
– |
int n; /* number of subsamples */ |
23 |
– |
} AMBSAMP; /* ambient sample division */ |
18 |
|
|
19 |
< |
typedef struct { |
20 |
< |
FVECT ux, uy, uz; /* x, y and z axis directions */ |
21 |
< |
short nt, np; /* number of theta and phi directions */ |
22 |
< |
} AMBHEMI; /* ambient sample hemisphere */ |
23 |
< |
|
24 |
< |
extern double sin(), cos(), sqrt(); |
25 |
< |
|
32 |
< |
|
33 |
< |
static int |
34 |
< |
ambcmp(d1, d2) /* decreasing order */ |
35 |
< |
AMBSAMP *d1, *d2; |
19 |
> |
void |
20 |
> |
inithemi( /* initialize sampling hemisphere */ |
21 |
> |
register AMBHEMI *hp, |
22 |
> |
RAY *r, |
23 |
> |
COLOR ac, |
24 |
> |
double wt |
25 |
> |
) |
26 |
|
{ |
27 |
< |
if (d1->k < d2->k) |
28 |
< |
return(1); |
29 |
< |
if (d1->k > d2->k) |
30 |
< |
return(-1); |
31 |
< |
return(0); |
27 |
> |
register int i; |
28 |
> |
/* set number of divisions */ |
29 |
> |
hp->nt = sqrt(ambdiv * wt * (1./PI/AVGREFL)) + 0.5; |
30 |
> |
i = ambacc > FTINY ? 3 : 1; /* minimum number of samples */ |
31 |
> |
if (hp->nt < i) |
32 |
> |
hp->nt = i; |
33 |
> |
hp->np = PI * hp->nt + 0.5; |
34 |
> |
/* set number of super-samples */ |
35 |
> |
hp->ns = ambssamp * wt + 0.5; |
36 |
> |
/* assign coefficients */ |
37 |
> |
copycolor(hp->acoef, ac); |
38 |
> |
if (wt >= r->rweight) |
39 |
> |
hp->drc = 1.; |
40 |
> |
else |
41 |
> |
hp->drc = wt / r->rweight; |
42 |
> |
/* make axes */ |
43 |
> |
VCOPY(hp->uz, r->ron); |
44 |
> |
hp->uy[0] = hp->uy[1] = hp->uy[2] = 0.0; |
45 |
> |
for (i = 0; i < 3; i++) |
46 |
> |
if (hp->uz[i] < 0.6 && hp->uz[i] > -0.6) |
47 |
> |
break; |
48 |
> |
if (i >= 3) |
49 |
> |
error(CONSISTENCY, "bad ray direction in inithemi"); |
50 |
> |
hp->uy[i] = 1.0; |
51 |
> |
fcross(hp->ux, hp->uy, hp->uz); |
52 |
> |
normalize(hp->ux); |
53 |
> |
fcross(hp->uy, hp->uz, hp->ux); |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
< |
static int |
58 |
< |
ambnorm(d1, d2) /* standard order */ |
59 |
< |
AMBSAMP *d1, *d2; |
57 |
> |
int |
58 |
> |
divsample( /* sample a division */ |
59 |
> |
register AMBSAMP *dp, |
60 |
> |
AMBHEMI *h, |
61 |
> |
RAY *r |
62 |
> |
) |
63 |
|
{ |
49 |
– |
register int c; |
50 |
– |
|
51 |
– |
if (c = d1->t - d2->t) |
52 |
– |
return(c); |
53 |
– |
return(d1->p - d2->p); |
54 |
– |
} |
55 |
– |
|
56 |
– |
|
57 |
– |
double |
58 |
– |
divsample(dp, h, r) /* sample a division */ |
59 |
– |
register AMBSAMP *dp; |
60 |
– |
AMBHEMI *h; |
61 |
– |
RAY *r; |
62 |
– |
{ |
64 |
|
RAY ar; |
65 |
< |
int hlist[4]; |
65 |
> |
int hlist[3]; |
66 |
> |
double spt[2]; |
67 |
|
double xd, yd, zd; |
68 |
|
double b2; |
69 |
|
double phi; |
70 |
|
register int i; |
71 |
< |
|
72 |
< |
if (rayorigin(&ar, r, AMBIENT, 0.5) < 0) |
73 |
< |
return(0.0); |
71 |
> |
/* ambient coefficient for weight */ |
72 |
> |
setcolor(ar.rcoef, h->drc, h->drc, h->drc); |
73 |
> |
if (rayorigin(&ar, AMBIENT, r, ar.rcoef) < 0) |
74 |
> |
return(-1); |
75 |
> |
copycolor(ar.rcoef, h->acoef); /* correct coefficient for trace */ |
76 |
> |
b2 = 1.0/(h->nt*h->np + h->ns); /* XXX not uniform if ns > 0 */ |
77 |
> |
scalecolor(ar.rcoef, b2); |
78 |
|
hlist[0] = r->rno; |
79 |
|
hlist[1] = dp->t; |
80 |
|
hlist[2] = dp->p; |
81 |
< |
hlist[3] = 0; |
82 |
< |
zd = sqrt((dp->t+urand(ilhash(hlist,4)+dp->n))/h->nt); |
83 |
< |
hlist[3] = 1; |
84 |
< |
phi = 2.0*PI * (dp->p+urand(ilhash(hlist,4)+dp->n))/h->np; |
85 |
< |
xd = cos(phi) * zd; |
80 |
< |
yd = sin(phi) * zd; |
81 |
> |
multisamp(spt, 2, urand(ilhash(hlist,3)+dp->n)); |
82 |
> |
zd = sqrt((dp->t + spt[0])/h->nt); |
83 |
> |
phi = 2.0*PI * (dp->p + spt[1])/h->np; |
84 |
> |
xd = tcos(phi) * zd; |
85 |
> |
yd = tsin(phi) * zd; |
86 |
|
zd = sqrt(1.0 - zd*zd); |
87 |
|
for (i = 0; i < 3; i++) |
88 |
|
ar.rdir[i] = xd*h->ux[i] + |
92 |
|
rayvalue(&ar); |
93 |
|
ndims--; |
94 |
|
addcolor(dp->v, ar.rcol); |
95 |
< |
if (ar.rot < FHUGE) |
96 |
< |
dp->r += 1.0/ar.rot; |
95 |
> |
/* use rt to improve gradient calc */ |
96 |
> |
if (ar.rt > FTINY && ar.rt < FHUGE) |
97 |
> |
dp->r += 1.0/ar.rt; |
98 |
|
/* (re)initialize error */ |
99 |
|
if (dp->n++) { |
100 |
|
b2 = bright(dp->v)/dp->n - bright(ar.rcol); |
102 |
|
dp->k = b2/(dp->n*dp->n); |
103 |
|
} else |
104 |
|
dp->k = 0.0; |
105 |
< |
return(ar.rot); |
105 |
> |
return(0); |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
+ |
static int |
110 |
+ |
ambcmp( /* decreasing order */ |
111 |
+ |
const void *p1, |
112 |
+ |
const void *p2 |
113 |
+ |
) |
114 |
+ |
{ |
115 |
+ |
const AMBSAMP *d1 = (const AMBSAMP *)p1; |
116 |
+ |
const AMBSAMP *d2 = (const AMBSAMP *)p2; |
117 |
+ |
|
118 |
+ |
if (d1->k < d2->k) |
119 |
+ |
return(1); |
120 |
+ |
if (d1->k > d2->k) |
121 |
+ |
return(-1); |
122 |
+ |
return(0); |
123 |
+ |
} |
124 |
+ |
|
125 |
+ |
|
126 |
+ |
static int |
127 |
+ |
ambnorm( /* standard order */ |
128 |
+ |
const void *p1, |
129 |
+ |
const void *p2 |
130 |
+ |
) |
131 |
+ |
{ |
132 |
+ |
const AMBSAMP *d1 = (const AMBSAMP *)p1; |
133 |
+ |
const AMBSAMP *d2 = (const AMBSAMP *)p2; |
134 |
+ |
register int c; |
135 |
+ |
|
136 |
+ |
if ( (c = d1->t - d2->t) ) |
137 |
+ |
return(c); |
138 |
+ |
return(d1->p - d2->p); |
139 |
+ |
} |
140 |
+ |
|
141 |
+ |
|
142 |
|
double |
143 |
< |
doambient(acol, r, pg, dg) /* compute ambient component */ |
144 |
< |
COLOR acol; |
145 |
< |
RAY *r; |
146 |
< |
FVECT pg, dg; |
143 |
> |
doambient( /* compute ambient component */ |
144 |
> |
COLOR acol, |
145 |
> |
RAY *r, |
146 |
> |
COLOR ac, |
147 |
> |
double wt, |
148 |
> |
FVECT pg, |
149 |
> |
FVECT dg |
150 |
> |
) |
151 |
|
{ |
152 |
|
double b, d; |
153 |
|
AMBHEMI hemi; |
155 |
|
AMBSAMP dnew; |
156 |
|
register AMBSAMP *dp; |
157 |
|
double arad; |
158 |
< |
int ndivs, ns; |
158 |
> |
int ndivs; |
159 |
|
register int i, j; |
160 |
|
/* initialize color */ |
161 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
162 |
|
/* initialize hemisphere */ |
163 |
< |
inithemi(&hemi, r); |
163 |
> |
inithemi(&hemi, r, ac, wt); |
164 |
|
ndivs = hemi.nt * hemi.np; |
165 |
|
if (ndivs == 0) |
166 |
|
return(0.0); |
167 |
< |
/* set number of super-samples */ |
168 |
< |
ns = ambssamp * r->rweight + 0.5; |
126 |
< |
if (ns > 0 || pg != NULL || dg != NULL) { |
167 |
> |
/* allocate super-samples */ |
168 |
> |
if (hemi.ns > 0 || pg != NULL || dg != NULL) { |
169 |
|
div = (AMBSAMP *)malloc(ndivs*sizeof(AMBSAMP)); |
170 |
|
if (div == NULL) |
171 |
|
error(SYSTEM, "out of memory in doambient"); |
181 |
|
setcolor(dp->v, 0.0, 0.0, 0.0); |
182 |
|
dp->r = 0.0; |
183 |
|
dp->n = 0; |
184 |
< |
if ((d = divsample(dp, &hemi, r)) == 0.0) |
184 |
> |
if (divsample(dp, &hemi, r) < 0) |
185 |
|
goto oopsy; |
186 |
+ |
arad += dp->r; |
187 |
|
if (div != NULL) |
188 |
|
dp++; |
189 |
< |
else { |
189 |
> |
else |
190 |
|
addcolor(acol, dp->v); |
148 |
– |
arad += dp->r; |
149 |
– |
} |
191 |
|
} |
192 |
< |
if (ns > 0) { /* perform super-sampling */ |
193 |
< |
comperrs(div, hemi); /* compute errors */ |
192 |
> |
if (hemi.ns > 0 && arad > FTINY && ndivs/arad < minarad) |
193 |
> |
hemi.ns = 0; /* close enough */ |
194 |
> |
else if (hemi.ns > 0) { /* else perform super-sampling */ |
195 |
> |
comperrs(div, &hemi); /* compute errors */ |
196 |
|
qsort(div, ndivs, sizeof(AMBSAMP), ambcmp); /* sort divs */ |
154 |
– |
dp = div + ndivs; /* skim excess */ |
155 |
– |
for (i = ndivs; i > ns; i--) { |
156 |
– |
dp--; |
157 |
– |
addcolor(acol, dp->v); |
158 |
– |
arad += dp->r; |
159 |
– |
} |
197 |
|
/* super-sample */ |
198 |
< |
for (i = ns; i > 0; i--) { |
199 |
< |
copystruct(&dnew, div); |
200 |
< |
if ((d = divsample(&dnew, &hemi)) == 0.0) |
198 |
> |
for (i = hemi.ns; i > 0; i--) { |
199 |
> |
dnew = *div; |
200 |
> |
if (divsample(&dnew, &hemi, r) < 0) |
201 |
|
goto oopsy; |
165 |
– |
if (d < FHUGE) |
166 |
– |
arad += 1.0 / d; |
202 |
|
/* reinsert */ |
203 |
|
dp = div; |
204 |
|
j = ndivs < i ? ndivs : i; |
205 |
|
while (--j > 0 && dnew.k < dp[1].k) { |
206 |
< |
copystruct(dp, dp+1); |
206 |
> |
*dp = *(dp+1); |
207 |
|
dp++; |
208 |
|
} |
209 |
< |
copystruct(dp, &dnew); |
175 |
< |
/* extract darkest */ |
176 |
< |
if (i <= ndivs) { |
177 |
< |
dp = div + i-1; |
178 |
< |
arad += dp->r; |
179 |
< |
if (dp->n > 1) { |
180 |
< |
b = 1.0/dp->n; |
181 |
< |
scalecolor(dp->v, b); |
182 |
< |
dp->r *= b; |
183 |
< |
dp->n = 1; |
184 |
< |
} |
185 |
< |
addcolor(acol, dp->v); |
186 |
< |
} |
209 |
> |
*dp = dnew; |
210 |
|
} |
211 |
|
if (pg != NULL || dg != NULL) /* restore order */ |
212 |
|
qsort(div, ndivs, sizeof(AMBSAMP), ambnorm); |
213 |
|
} |
214 |
|
/* compute returned values */ |
215 |
< |
if (pg != NULL) |
216 |
< |
posgradient(pg, div, &hemi); |
217 |
< |
if (dg != NULL) |
218 |
< |
dirgradient(dg, div, &hemi); |
219 |
< |
if (div != NULL) |
220 |
< |
free((char *)div); |
215 |
> |
if (div != NULL) { |
216 |
> |
arad = 0.0; |
217 |
> |
for (i = ndivs, dp = div; i-- > 0; dp++) { |
218 |
> |
arad += dp->r; |
219 |
> |
if (dp->n > 1) { |
220 |
> |
b = 1.0/dp->n; |
221 |
> |
scalecolor(dp->v, b); |
222 |
> |
dp->r *= b; |
223 |
> |
dp->n = 1; |
224 |
> |
} |
225 |
> |
addcolor(acol, dp->v); |
226 |
> |
} |
227 |
> |
b = bright(acol); |
228 |
> |
if (b > FTINY) { |
229 |
> |
b = ndivs/b; |
230 |
> |
if (pg != NULL) { |
231 |
> |
posgradient(pg, div, &hemi); |
232 |
> |
for (i = 0; i < 3; i++) |
233 |
> |
pg[i] *= b; |
234 |
> |
} |
235 |
> |
if (dg != NULL) { |
236 |
> |
dirgradient(dg, div, &hemi); |
237 |
> |
for (i = 0; i < 3; i++) |
238 |
> |
dg[i] *= b; |
239 |
> |
} |
240 |
> |
} else { |
241 |
> |
if (pg != NULL) |
242 |
> |
for (i = 0; i < 3; i++) |
243 |
> |
pg[i] = 0.0; |
244 |
> |
if (dg != NULL) |
245 |
> |
for (i = 0; i < 3; i++) |
246 |
> |
dg[i] = 0.0; |
247 |
> |
} |
248 |
> |
free((void *)div); |
249 |
> |
} |
250 |
|
b = 1.0/ndivs; |
251 |
|
scalecolor(acol, b); |
252 |
|
if (arad <= FTINY) |
201 |
– |
arad = FHUGE; |
202 |
– |
else |
203 |
– |
arad = (ndivs+ns)/arad; |
204 |
– |
if (arad > maxarad) |
253 |
|
arad = maxarad; |
254 |
< |
else if (arad < minarad) |
254 |
> |
else |
255 |
> |
arad = (ndivs+hemi.ns)/arad; |
256 |
> |
if (pg != NULL) { /* reduce radius if gradient large */ |
257 |
> |
d = DOT(pg,pg); |
258 |
> |
if (d*arad*arad > 1.0) |
259 |
> |
arad = 1.0/sqrt(d); |
260 |
> |
} |
261 |
> |
if (arad < minarad) { |
262 |
|
arad = minarad; |
263 |
< |
arad /= sqrt(r->rweight); |
263 |
> |
if (pg != NULL && d*arad*arad > 1.0) { /* cap gradient */ |
264 |
> |
d = 1.0/arad/sqrt(d); |
265 |
> |
for (i = 0; i < 3; i++) |
266 |
> |
pg[i] *= d; |
267 |
> |
} |
268 |
> |
} |
269 |
> |
if ((arad /= sqrt(wt)) > maxarad) |
270 |
> |
arad = maxarad; |
271 |
|
return(arad); |
272 |
|
oopsy: |
273 |
|
if (div != NULL) |
274 |
< |
free((char *)div); |
274 |
> |
free((void *)div); |
275 |
|
return(0.0); |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
< |
inithemi(hp, r) /* initialize sampling hemisphere */ |
280 |
< |
register AMBHEMI *hp; |
281 |
< |
RAY *r; |
279 |
> |
void |
280 |
> |
comperrs( /* compute initial error estimates */ |
281 |
> |
AMBSAMP *da, /* assumes standard ordering */ |
282 |
> |
register AMBHEMI *hp |
283 |
> |
) |
284 |
|
{ |
221 |
– |
register int i; |
222 |
– |
/* set number of divisions */ |
223 |
– |
hp->nt = sqrt(ambdiv * r->rweight * 0.5) + 0.5; |
224 |
– |
hp->np = 2 * hp->nt; |
225 |
– |
/* make axes */ |
226 |
– |
VCOPY(hp->uz, r->ron); |
227 |
– |
hp->uy[0] = hp->uy[1] = hp->uy[2] = 0.0; |
228 |
– |
for (i = 0; i < 3; i++) |
229 |
– |
if (hp->uz[i] < 0.6 && hp->uz[i] > -0.6) |
230 |
– |
break; |
231 |
– |
if (i >= 3) |
232 |
– |
error(CONSISTENCY, "bad ray direction in inithemi"); |
233 |
– |
hp->uy[i] = 1.0; |
234 |
– |
fcross(hp->ux, hp->uz, hp->uy); |
235 |
– |
normalize(hp->ux); |
236 |
– |
fcross(hp->uy, hp->ux, hp->uz); |
237 |
– |
} |
238 |
– |
|
239 |
– |
|
240 |
– |
comperrs(da, hp) /* compute initial error estimates */ |
241 |
– |
AMBSAMP *da; /* assumes standard ordering */ |
242 |
– |
register AMBHEMI *hp; |
243 |
– |
{ |
285 |
|
double b, b2; |
286 |
|
int i, j; |
287 |
|
register AMBSAMP *dp; |
289 |
|
dp = da; |
290 |
|
for (i = 0; i < hp->nt; i++) |
291 |
|
for (j = 0; j < hp->np; j++) { |
292 |
+ |
#ifdef DEBUG |
293 |
+ |
if (dp->t != i || dp->p != j) |
294 |
+ |
error(CONSISTENCY, |
295 |
+ |
"division order in comperrs"); |
296 |
+ |
#endif |
297 |
|
b = bright(dp[0].v); |
298 |
|
if (i > 0) { /* from above */ |
299 |
|
b2 = bright(dp[-hp->np].v) - b; |
306 |
|
b2 *= b2 * 0.25; |
307 |
|
dp[0].k += b2; |
308 |
|
dp[-1].k += b2; |
309 |
< |
} |
310 |
< |
if (j == hp->np-1) { /* around */ |
265 |
< |
b2 = bright(dp[-(hp->np-1)].v) - b; |
309 |
> |
} else { /* around */ |
310 |
> |
b2 = bright(dp[hp->np-1].v) - b; |
311 |
|
b2 *= b2 * 0.25; |
312 |
|
dp[0].k += b2; |
313 |
< |
dp[-(hp->np-1)].k += b2; |
313 |
> |
dp[hp->np-1].k += b2; |
314 |
|
} |
315 |
|
dp++; |
316 |
|
} |
328 |
|
} |
329 |
|
|
330 |
|
|
331 |
< |
posgradient(gv, da, hp) /* compute position gradient */ |
332 |
< |
FVECT gv; |
333 |
< |
AMBSAMP *da; /* assumes standard ordering */ |
334 |
< |
AMBHEMI *hp; |
331 |
> |
void |
332 |
> |
posgradient( /* compute position gradient */ |
333 |
> |
FVECT gv, |
334 |
> |
AMBSAMP *da, /* assumes standard ordering */ |
335 |
> |
register AMBHEMI *hp |
336 |
> |
) |
337 |
|
{ |
338 |
|
register int i, j; |
339 |
< |
double b, d; |
339 |
> |
double nextsine, lastsine, b, d; |
340 |
|
double mag0, mag1; |
341 |
|
double phi, cosp, sinp, xd, yd; |
342 |
|
register AMBSAMP *dp; |
345 |
|
for (j = 0; j < hp->np; j++) { |
346 |
|
dp = da + j; |
347 |
|
mag0 = mag1 = 0.0; |
348 |
+ |
lastsine = 0.0; |
349 |
|
for (i = 0; i < hp->nt; i++) { |
350 |
|
#ifdef DEBUG |
351 |
|
if (dp->t != i || dp->p != j) |
356 |
|
if (i > 0) { |
357 |
|
d = dp[-hp->np].r; |
358 |
|
if (dp[0].r > d) d = dp[0].r; |
359 |
< |
d *= 1.0 - sqrt((double)i/hp->nt); |
359 |
> |
/* sin(t)*cos(t)^2 */ |
360 |
> |
d *= lastsine * (1.0 - (double)i/hp->nt); |
361 |
|
mag0 += d*(b - bright(dp[-hp->np].v)); |
362 |
|
} |
363 |
+ |
nextsine = sqrt((double)(i+1)/hp->nt); |
364 |
|
if (j > 0) { |
365 |
|
d = dp[-1].r; |
366 |
|
if (dp[0].r > d) d = dp[0].r; |
367 |
< |
mag1 += d*(b - bright(dp[-1].v)); |
367 |
> |
mag1 += d * (nextsine - lastsine) * |
368 |
> |
(b - bright(dp[-1].v)); |
369 |
|
} else { |
370 |
|
d = dp[hp->np-1].r; |
371 |
|
if (dp[0].r > d) d = dp[0].r; |
372 |
< |
mag1 += d*(b - bright(dp[hp->np-1].v)); |
372 |
> |
mag1 += d * (nextsine - lastsine) * |
373 |
> |
(b - bright(dp[hp->np-1].v)); |
374 |
|
} |
375 |
|
dp += hp->np; |
376 |
+ |
lastsine = nextsine; |
377 |
|
} |
378 |
< |
if (hp->nt > 1) { |
326 |
< |
mag0 /= (double)(hp->nt-1); |
327 |
< |
mag1 /= (double)hp->nt; |
328 |
< |
} |
378 |
> |
mag0 *= 2.0*PI / hp->np; |
379 |
|
phi = 2.0*PI * (double)j/hp->np; |
380 |
< |
cosp = cos(phi); sinp = sin(phi); |
380 |
> |
cosp = tcos(phi); sinp = tsin(phi); |
381 |
|
xd += mag0*cosp - mag1*sinp; |
382 |
|
yd += mag0*sinp + mag1*cosp; |
383 |
|
} |
384 |
|
for (i = 0; i < 3; i++) |
385 |
< |
gv[i] = (xd*hp->ux[i] + yd*hp->uy[i])/hp->np; |
385 |
> |
gv[i] = (xd*hp->ux[i] + yd*hp->uy[i])/PI; |
386 |
|
} |
387 |
|
|
388 |
|
|
389 |
< |
dirgradient(gv, da, hp) /* compute direction gradient */ |
390 |
< |
FVECT gv; |
391 |
< |
AMBSAMP *da; /* assumes standard ordering */ |
392 |
< |
AMBHEMI *hp; |
389 |
> |
void |
390 |
> |
dirgradient( /* compute direction gradient */ |
391 |
> |
FVECT gv, |
392 |
> |
AMBSAMP *da, /* assumes standard ordering */ |
393 |
> |
register AMBHEMI *hp |
394 |
> |
) |
395 |
|
{ |
396 |
|
register int i, j; |
397 |
|
double mag; |
408 |
|
error(CONSISTENCY, |
409 |
|
"division order in dirgradient"); |
410 |
|
#endif |
411 |
< |
mag += sqrt((i+.5)/hp->nt)*bright(dp->v); |
411 |
> |
/* tan(t) */ |
412 |
> |
mag += bright(dp->v)/sqrt(hp->nt/(i+.5) - 1.0); |
413 |
|
dp += hp->np; |
414 |
|
} |
415 |
|
phi = 2.0*PI * (j+.5)/hp->np + PI/2.0; |
416 |
< |
xd += mag * cos(phi); |
417 |
< |
yd += mag * sin(phi); |
416 |
> |
xd += mag * tcos(phi); |
417 |
> |
yd += mag * tsin(phi); |
418 |
|
} |
419 |
|
for (i = 0; i < 3; i++) |
420 |
|
gv[i] = (xd*hp->ux[i] + yd*hp->uy[i])/(hp->nt*hp->np); |