At any point on the bounding surface,
we can compute the derivative vector [a,b,c] of function P(x,y,z).
The *surface normal* at point [x,y,z] can then be defined as
the unit length vector:

normalize([-a,-b,-c]).

A volume that is bound by a first degree surface
(ie: by a plane) is a *half space*.
A half space is defined by
the equation of its bounding plane [a,b,c,d] as follows:

ax + by + cz + d >= 0

*Example:*
The half space of all points such that z >= -1
can be written as:

z + 1 >= 0 or 0*x + 0*y + 1*z + 1 >= 0The bounding plane of this half space is therefore given by the vector of coefficients: [0,0,1,1].

**Half space surface normals:**

At every point on the boundary of ax+by+cz+d >= 0, the derivative vector is [a,b,c]. So the surface normal at any point on the surface is the unit length vector:

normalize([-a,-b,-c])

**Convex polyhedra:**

You can always describe a convex polyhedron as an intersection of half spaces. For example, the cube-shaped volume such that -1 <= x <= 1, -1 <= y <= 1, and -1 <= z <= 1, is the intersection of the following six half spaces:

[1,0,0,1], [-1,0,0,1],

[0,1,0,1], [0,-1,0,1],

[0,0,1,1], [0,0,-1,1].

**Ray tracing to a half space:**

Tracing a ray
to a half space consists of substituting
[v_{x} + t w_{x},
v_{y} + t w_{y},
v_{z} + t w_{z}] for [x,y,z],
to get:

a (vor_{x}+ t w_{x}) + b (v_{y}+ t w_{y}) + c (v_{z}+ t w_{z}) + d >= 0

(a wThis is an equation of the form At + B >= 0, whose solution is t = -B / A. When A = 0, then the ray is parallel to the defining plane of the half space, and it suffices to check whether the ray origin is inside the half space:_{x}+ b w_{y}+ c w_{z}) t + (a v_{x}+ b v_{y}+ c v_{z}+ d) >= 0

a v_{x}+ b v_{y}+ c v_{z}+ d >= 0

A volume that is bounded by a second degree surface in three dimensions is described by:

axwhich can be expressed as the vector of coefficients: [a,b,c,d,e,f,g,h,i,j].^{2}+ by^{2}+ cz^{2}+ dyz + ezx + fxy + gx + hy + iz + j >= 0

*Example:*
The equation of a sphere

(x - ccan be expressed as:_{x})^{2}+ (y - c_{y})^{2}+ (z - c_{z})^{2}- r^{2}<= 0

- (xwhich can be expressed as the vector of coefficients: [-1 , -1 , -1 , 0 , 0 , 0 , 2c^{2}- 2 x c_{x}+ c_{x}^{2}) - (y^{2}- 2 y c_{y}+ c_{y}^{2}) - (z^{2}- 2 z c_{z}+ c_{z}^{2}) + r^{2}>= 0

**Derivatives and normals:**

The vector-valued derivative of

axis given by:^{2}+ by^{2}+ cz^{2}+ dyz + ezx + fxy + gx + hy + iz + j

[2ax+ez+fy+g, 2by+dz+fx+h, 2cy+dy+ex+i]

Recall that for any volume bounded by a surface which is described by some inequality P(x,y,z) >= 0, the surface normal at point [x,y,z] is given by the unit length vector:

normalize([-a,-b,-c])where [a,b,c] is the derivative of P at [x,y,z].

Therefore, the surface normal at a point [x,y,z] on the surface is given by the unit length vector:

normalize([-2ax-ez-fy-g, -2by-dz-fx-h, -2cy-dy-ex-i])

x^{2}+ y^{2}- r^{2}<= 0

z >= -1

z <= 1

These three volumes can be defined, respectively, by the vectors of coefficients:

[-1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , r^{2}]

[ 0 , 0 , 1 , 1 ]

[ 0 , 0 , -1 , 1 ]

A ray traced to this shape will encounter three line segments. The line segment through the cylindrical tube may be null (ie: when the ray misses the cylindrical tube entirely). The line segments through each of the two half spaces will in general be semi-infinite: either of the form [ t ... ∞ ] or [ -∞ ... t ]. Since the ray consists only of positive values of t, the latter case is handled as [ 0 ... t].

The intersection of a ray with the cylinder is the intersection the three respective line segments. If this intersection is non-null, then one of the three surfaces (either the cylindrical tube or one of the the planar faces) will correspond to the first t in the intersection. We must compute the surface normal for that surface at the intersection point.