# Vectors and Calculus

Have you ever wondered what practical use there might be for vectors and calculus? You may have studied them in school or college, and yet have no notion of where they might be used in the real world.

One practical use for vectors and calculus: shading in computer graphics. Take the simple sphere and three light sources. The positions and colours of the light sources are shown using circles. The shading is achieved by comparing the angle of the normal to the sphere at a given point to the angle of the light source.

The normal to a surface at a given point is the vector perpendicular to the surface at that point. In the case of a sphere or an ellipsoid, the vector from the centre to a point on the surface is parallel to the normal at that point. Therefore calculus is not needed when shading a sphere or an ellipsoid. When the light source is behind the object its circle is smaller, as it is further away from the ‘camera.’

With other shapes and surfaces, calculus is used for finding the normal to the surface at a given point.

In all cases, once the normal has been found, the angle between the normal and the vector representing a light source is found*. The closer the angle is to zero, the brighter the spot (i.e. the point on the surface). The closer it is to 90 degrees, the darker the spot. If the angle is 90 degrees or more, the spot is completely dark**. This is repeated for all light sources. A demo showing the light source vector in orange and the normal to the surface in red.

To see videos of the light sources rotating about the objects:
Sphere
Ellipsoid
Surface
Demo

* It’s actually the dot product of the unit normal vector and the unit light vector that’s calculated. With unit vectors, the dot product is the cosine of the angle between the vectors.

** To be more precise, the spot is completely lacking in the colour of that particular light source.