[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[ATM] Raytracing Function
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
I am trying to implement this as a Java function with the
following basic algorithm:
root = sqrt( |a| * |a| + x ) - |a|
root = 0.5 * ( root * root + x ) / ( |a| + root )
root = 0.5 * ( root * root + x ) / ( |a| + root )
...
root = root + ( |a| - a )
The first line creates an initial guess using the base square root
function. The middle line[s] apply Newton-Raephson iteration to
refine the root. The last line adjusts the solution for negative
values of parameter a.
When |x| is small relative to |a|, square root in the initial guess
and the final term nearly cancel; the result can have a large amount
of relative error. However, in that case the iteration converges
quickly. I have reason to suspect, then, that the number of
Newton-Raephson iterations needed is quite low, maybe even just one.
Opinions?
_______________________________________________
ATM mailing list http://www.atmlist.net/