Calculating a surface normal
For a convex polygon (such as a triangle), a surface normal can be calculated as the vector cross product of two (non-parallel) edges of the polygon.
For a plane given by the equation the vector is a normal.
For a plane whose equation is given in parametric form
where is a point on the plane and are non-parallel vectors pointing along the plane, a normal to the plane is a vector normal to both and which can be found as the cross product
If a (possibly non-flat) surface in 3D space is parameterized by a system of curvilinear coordinates with and real variables, then a normal to S is by definition a normal to a tangent plane, given by the cross product of the partial derivatives
If a surface is given implicitly as the set of points satisfying then a normal at a point on the surface is given by the gradient
since the gradient at any point is perpendicular to the level set
For a surface in given as the graph of a function an upward-pointing normal can be found either from the parametrization giving
or more simply from its implicit form giving
Since a surface does not have a tangent plane at a singular point, it has no well-defined normal at that point: for example, the vertex of a cone. In general, it is possible to define a normal almost everywhere for a surface that is Lipschitz continuous.
in this section we only use the upper
matrix, as translation is irrelevant to the calculation
When applying a transform to a surface it is often useful to derive normals for the resulting surface from the original normals.
Specifically, given a 3×3 transformation matrix we can determine the matrix that transforms a vector perpendicular to the tangent plane into a vector perpendicular to the transformed tangent plane by the following logic:
Write n′ as We must find
Choosing such that or will satisfy the above equation, giving a perpendicular to or an perpendicular to as required.
Therefore, one should use the inverse transpose of the linear transformation when transforming surface normals. The inverse transpose is equal to the original matrix if the matrix is orthonormal, that is, purely rotational with no scaling or shearing.