9 |
|
* |
10 |
|
* No interpolation in this version. |
11 |
|
* |
12 |
< |
* External symbols declared in standard.h |
12 |
> |
* External symbols declared in rtmath.h |
13 |
|
*/ |
14 |
|
|
15 |
< |
/* ==================================================================== |
16 |
< |
* The Radiance Software License, Version 1.0 |
17 |
< |
* |
18 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
19 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
20 |
< |
* |
21 |
< |
* Redistribution and use in source and binary forms, with or without |
22 |
< |
* modification, are permitted provided that the following conditions |
23 |
< |
* are met: |
24 |
< |
* |
25 |
< |
* 1. Redistributions of source code must retain the above copyright |
26 |
< |
* notice, this list of conditions and the following disclaimer. |
27 |
< |
* |
28 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
29 |
< |
* notice, this list of conditions and the following disclaimer in |
30 |
< |
* the documentation and/or other materials provided with the |
31 |
< |
* distribution. |
32 |
< |
* |
33 |
< |
* 3. The end-user documentation included with the redistribution, |
34 |
< |
* if any, must include the following acknowledgment: |
35 |
< |
* "This product includes Radiance software |
36 |
< |
* (http://radsite.lbl.gov/) |
37 |
< |
* developed by the Lawrence Berkeley National Laboratory |
38 |
< |
* (http://www.lbl.gov/)." |
39 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
40 |
< |
* if and wherever such third-party acknowledgments normally appear. |
41 |
< |
* |
42 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
43 |
< |
* and "The Regents of the University of California" must |
44 |
< |
* not be used to endorse or promote products derived from this |
45 |
< |
* software without prior written permission. For written |
46 |
< |
* permission, please contact [email protected]. |
47 |
< |
* |
48 |
< |
* 5. Products derived from this software may not be called "Radiance", |
49 |
< |
* nor may "Radiance" appear in their name, without prior written |
50 |
< |
* permission of Lawrence Berkeley National Laboratory. |
51 |
< |
* |
52 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
53 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
54 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
55 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
56 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
57 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
58 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
59 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
60 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
61 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
62 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
63 |
< |
* SUCH DAMAGE. |
64 |
< |
* ==================================================================== |
65 |
< |
* |
66 |
< |
* This software consists of voluntary contributions made by many |
67 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
68 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
69 |
< |
* <http://www.lbl.gov/>. |
70 |
< |
*/ |
15 |
> |
#include "copyright.h" |
16 |
|
|
17 |
|
#include <math.h> |
18 |
|
|
19 |
+ |
#include "rtmath.h" |
20 |
+ |
|
21 |
|
#ifndef NCOSENTRY |
22 |
< |
#define NCOSENTRY 256 |
22 |
> |
#define NCOSENTRY 1024 |
23 |
|
#endif |
24 |
|
|
78 |
– |
#ifdef M_PI |
79 |
– |
#define PI ((double)M_PI) |
80 |
– |
#else |
81 |
– |
#define PI 3.14159265358979323846 |
82 |
– |
#endif |
25 |
|
|
84 |
– |
|
26 |
|
double |
27 |
< |
tcos(x) /* approximate cosine */ |
87 |
< |
register double x; |
27 |
> |
tcos(double x) /* approximate cosine */ |
28 |
|
{ |
29 |
|
static double costab[NCOSENTRY+1]; |
30 |
|
register int i; |
36 |
|
if (x < 0.) |
37 |
|
x = -x; |
38 |
|
i = (NCOSENTRY*2./PI) * x + 0.5; |
39 |
< |
if (i >= 4*NCOSENTRY) |
40 |
< |
i %= 4*NCOSENTRY; |
39 |
> |
while (i >= 4*NCOSENTRY) |
40 |
> |
i -= 4*NCOSENTRY; |
41 |
|
switch (i / NCOSENTRY) { |
42 |
|
case 0: |
43 |
|
return(costab[i]); |
49 |
|
return(costab[(4*NCOSENTRY)-i]); |
50 |
|
} |
51 |
|
return(0.); /* should never be reached */ |
52 |
+ |
} |
53 |
+ |
|
54 |
+ |
|
55 |
+ |
/* Fast arctangent approximation due to Rajan et al. 2006 */ |
56 |
+ |
double |
57 |
+ |
atan2a(double y, double x) |
58 |
+ |
{ |
59 |
+ |
double ratio, aratio, val; |
60 |
+ |
|
61 |
+ |
if (x == 0) |
62 |
+ |
return (y > 0) ? PI/2. : 3./2.*PI; |
63 |
+ |
|
64 |
+ |
aratio = (ratio = y/x) >= 0 ? ratio : -ratio; |
65 |
+ |
|
66 |
+ |
if (aratio > 1.01) |
67 |
+ |
return PI/2. - aatan2(x, y); |
68 |
+ |
|
69 |
+ |
val = PI/4.*ratio - ratio*(aratio - 1.)*(0.2447 + 0.0663*aratio); |
70 |
+ |
|
71 |
+ |
return val + PI*(x < 0); |
72 |
|
} |