[ATM] Raytracing Function
Donald Good
donald.good at comcast.net
Wed Sep 27 10:12:14 JST 2006
How about this (in the C style)?
float OffsetRt(float a, float x ) {
if (a<0) Return (sqrt( a*a + x ) - a);
else Return (x/(sqrt( a*a + x) + a));
}
-----Original Message-----
From: atm-bounces at atmlist.net [mailto:atm-bounces at atmlist.net] On Behalf Of
Jim Burrows
Sent: Friday, September 22, 2006 5:56 PM
To: ATM List
Subject: Re: [ATM] Raytracing Function
At 2006-09-22 11:23 -0400, Richard F.L.R. Snashall wrote:
>One function that keeps recurring in [algebraic] raytracing is what I
>have come to call an offset root (or offset square root):
>
> OffsetRt( a, x ) = sqrt( a^2 + x ) - a
>
> root = root + ( |a| - a )
You will still run into the classical numerical problem: large - large =
small, with loss of precision. Sometimes it can be bad enough that even IEE
extended reals (19 digits) will give poor answers. The solution is
"rationalizing the numerator":
sqrt( a² + x) - a = (sqrt( a² + x) - a)*(sqrt( a² + x) + a)/(sqrt( a² + x)
+ a) = (a² + x - a²)/(sqrt( a² + x) + a) = x/(sqrt( a² + x) + a),
works fine and is used in lots & lots of places in my ATM programs.
-- Jim Burrows
-- mailto://burrjaw@earthlink.net
-- http://home.earthlink.net/~burrjaw
-- Seattle N47.4723 W122.3662 (WGS84)
_______________________________________________
ATM mailing list http://www.atmlist.net/
_______________________________________________
ATM mailing list http://www.atmlist.net/
More information about the ATM
mailing list