Modelling Three-Dimensional Objects (Introduction to Computer Graphics Using Java 2D and 3D) Part 5

Normal Vectors for Surfaces

Aspects of illumination and shading in connection with light reflections are crucial for generating realistic 3D images. Light reflections depend on the angle of the light with respect to the surface. Surface normal vectors are needed for the calculation of these angles. Illumination and shading techniques will be described in detail in Sect. 8. In this section, normal vectors are introduced that will be needed later on for illumination and shading purposes.

A triangle always defines a plane and all normal vectors of such a flat triangle point in the same direction. If the plane induced by a triangle is given by the equation

tmpc009-381_thumb[2][2][2][2]

then the vector (A, B,C)T is a nonnormalised2 normal vector to the plane. This is true for the following reason. If n = (nx,ny,nz)T is a not necessarily normalised normal vector to the plane and v = (vx,vy,vz)T is a point in the plane, then the point (x,y,z)T lies also in the plane if and only if the vector connecting v and (x,y,z)T lies in the plane. This means the connecting vector must be orthogonal to the normal vector.


tmpc009-382_thumb[2][2][2][2]

Choosing A = nx, B = ny, C = nz and D = nT · v, (6.4) for the plane is obtained.

When a triangle is given by the three noncollinear points P1, P2, P3, the normal vector can be calculated by the cross product by

tmpc009-383_thumb[2][2][2][2]

The cross product of two vectors (x1,y1,z1)T and (x2,y2,z2)T is defined as the vector

tmpc009-384_thumb[2][2][2][2]

The cross product is zero when the two vectors are collinear.

Equation (6.4) provides a nonnormalised normal vector to the plane. The value D is obtained by inserting one of the points of the triangle, i.e., one point in the plane, into this equation.

tmpc009-385_thumb[2][2][2][2]

The normal vector at a point x(s0,t0) of a freeform surface is the normal vector to the tangent plane in the corresponding point. The tangent plane is determined by the tangent vectors at x(s0,t0) to the two parametric curves p(s) = x(s, t0) and q(t) = x(s0,t).

tmpc009-386_thumb[2][2][2][2]

These two tangent vectors are parallel to the surface in the point (s0,t0) and induce the tangent plane in this point. The cross product of these tangent vectors is then the normal vector to the surface at the point x(s0,t0).

When a freeform surface is approximated by triangles, the normal vectors for the triangles should not be derived from the triangles but from the freeform surface directly. Of course, it is impossible to store a normal vector for every single point in an approximating triangle. But at least, the normal vectors for the three vertices of the triangle should be computed and stored as the normal vectors to the surface in the corresponding points. In this way, a plane triangle can have three different normal vectors that are inherited from the original surface. None of these normal vectors might coincide with the normal vector to the plane defined by the triangle as can be seen in Fig. 6.24.

Fig. 6.24 Normal vectors to the original surface in the vertices of an approximating triangle

Normal vectors to the original surface in the vertices of an approximating triangle

Normal Vectors in Java 3D

The normal vectors for the elementary geometric objects cube, sphere, cylinder and cone are determined automatically in Java 3D. For objects loaded from a file, for instance in Wavefront Object format, the normal vectors are usually provided in the file along with object coordinates. When objects are modelled directly by triangles in Java 3D, the normal vectors can also be specified explicitly. This will seldom be needed since complex objects are usually not designed directly in Java 3D. They will be constructed with a suitable design tool and imported to Java 3D as Wavefront Object files. Nevertheless, a simple technique for controlling the generation of normal vectors in the class GeometryArray shall be described here.

When an object is defined by triangles in Java 3D with the class GeometryArray, an instance ng of the class NormalGenerator must be created as described on page 139. It is possible to modify the computation of normal vectors before the normal vectors for the GeometryInfo object gi are calculated by calling the method ng.generateNormals(gi). The method ng.setCreaseAngle(angle); should be called directly before the method ng.generateNormals(gi). The value angle specifies up to which angle the normal vectors of neighbouring triangles should be interpolated. The idea behind this interpolation is that neighbouring triangles with a very flat angle approximate a smooth curved surface. So the edge between the triangles is not part of the approximated surface. However, if the angle is too sharp, then the neighbouring triangles model a real edge on the approximated surface and this edge should be preserved. Figure 6.25 illustrates the principle of interpolated normal vectors on the left-hand side. The angle between the two triangles is so flat that it can be assumed that the edge is not desired and therefore, the normal vectors are interpolated. There is a very sharp angle between the two triangles on the right-hand side of Fig. 6.25. The resulting edge is intended and the normal vectors should not be interpolated.

When the default constructor new NormalGenerator() is used, the angle will be set to zero. Interpolation between normal vectors will not be carried out. The method setCreaseAngle can change the angle and set it even to a value that will cause interpolation between triangles with a very sharp edge in between. In the program NormalsForGeomArrays.java, the same tetrahedron as in the program GeomArrayExample.java is generated. However, the angle for interpolation is set to π, i.e., 180°, so that normal vectors between neighbouring triangles are always interpolated. The edges of the tetrahedron, which were clearly visible in the program GeomArrayExample.java, become almost invisible now. 

Fig. 6.25 Interpolated and noninterpolated normal vectors

Interpolated and noninterpolated normal vectors

Next post:

Previous post: