(x-a)2 + (y-b)2 + (z-c)2 = r2 // original sphere equation (z-c)2 = r2 - (x-a)2 - (y-b)2 // solving for z z - c = SQRT( r2 - (x-a)2 - (y-b)2 ) z = c + SQRT( r2 - (x-a)2 - (y-b)2 )Again in order to be efficient, we would like to make as much use as possible of the linear expression evaluator and any previously computed values. Clearly we will have a difficult time linearing this equation, so instead we will approximate the depth values by a paraboloid with the following properties:
Parabola 1: XZ-plane passing through points (a+r,c), (a-r,c), (a,c+r)
f(x) = [ x2 x 1 ] [ A B C ]^T = z [ (a+r)2 (a+r) 1 ] [ A ] [ c ] [ (a-r)2 (a-r) 1 ] [ B ] = [ c ] [ a2 a 1 ] [ C ] = [ c+r ]Parabola 2: YZ-plane passing through points (b+r,c), (b-r,c), (b,c+r)
f(y) = [ y2 y 1 ] [ A B C ]^T = z [ (b+r)2 (b+r) 1 ] [ A ] [ c ] [ (b-r)2 (b-r) 1 ] [ B ] = [ c ] [ b2 b 1 ] [ C ] = [ c+r ]If we solve for this system, we obtain the values for A,B,C and the resulting paraboloid equation is written follows:
A=-1/r B=0 C=c+r f(x) = -(x-a)2/r + (c+r) f(y) = -(y-b)2/r + (c+r) f(x,y) = f(x) + (f(y)-(c+r)) = c + ( (r2 - (x-a)2 - (y-b)2) / r )NOTE: the above equations can be greatly simplified by assuming a center of (a,b,c)=(0,0,0) and then finding f(x,y) in the following form:
f(x,y) = z = -(x2 + y2)/r + rand then converting to the form centered about (a,b,c):
z-c = -((x-a)2 + (y-b)2)/r + rWorking through the algebra will result in the same f(x,y) as done previously.