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

Re: [ATM] Raytracing Function



> You will still run into the classical numerical problem:  large - 
> large = small, with loss of precision.

Alternately, if you are using Java 1.5 then you can represent the numbers using the BigDecimal class (BigDecimal is not fully fledged in 1.4).  BigDecimal offers very very high precision (if you want), plus it has methods such as pow() that you can use to perform your calculation.

http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html

Clear skies,

Justin Morgan,
Bellevue, WA

-----Original Message-----
From: atm-bounces@atmlist.net [mailto:atm-bounces@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/