[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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/