Hacker News new | ask | show | jobs
by sp332 880 days ago

  W=1/SQR(U*U+V*V+1)
This makes a sphere. It gets multiplied by two coordinates to make spheres at different places, U and V.
1 comments

i think this is incorrect, i think that's computing the z component of the initial direction vector of the ray being traced

if you change the initialization of i from sgn u to 1.2 * sgn u you will get an image with the spheres a little further apart

Yeah, that's something of a red herring. The actual ray-sphere intersection happens on line 50:

    // sphere_center = (E, F, Z)
    E = X - I 
    F = Y - I
    // solving the ray-sphere quadratic eqn...
    P = U * E + V * F - W * Z
    // discriminant
    D = P * P - E * E - F * F - Z * Z + 1
    // if solution (ie. intersection) exists
    IF D > 0 
      // intersect_point = ray_orig + T * ray_dir
      // this is the closer pt, -P + SQR D is the other 
      T = -P - SQR D
yeah, that was what i guessed it was doing, but i couldn't remember or rederive the ray-sphere intersection formula to be sure