Ray equation is used to find the coordinates of any point P along a ray path:

P = P0 + su

Where, P0 = Initial position of ray

P= any point along ray path

s = distance of point along ray path

u = Unit direction vector

u = (Ppixel – Pprojection) / |Ppixel – Pprojection|

Ppixel = Position of pixel through which ray passes

Projection = Projection reference point.

For a sphere,

r = radius

Pc = Center

P = any point in sphere

Sphere equation:

| P – Pc|² – r² = 0

Using Ray equation,

| P0 + su – Pc|² – r² = 0

ΔP = Pc – P0

s² – 2 (u.ΔP)s + ( |ΔP|² – r²) = 0

= > s = u. ΔP ± √ (u. ΔP)² – |ΔP|² + r²

If discriminant is negative, ray does not intersects the sphere

If discriminant is positive, then we can obtain the coordinates from the above equation.

For a polyhedron bounded by a sphere:

u. N <0

where, N = surface normal

By plane euation,

N. P = -D

By Ray equation,

N. (P0 + su) = -D

= > s = – (D + N. P0) / (N. u)

## Leave a Reply