Newton's law of universal gravitation enables us to calculate the field set up by an array of point masses (or uniform spheres). We can do this wherever we wish in the vicinity of the mass array, and this enables us to plot fieldlines, continuous curves tangent to the field, and equipotentials, continuous curves perpendicular to the field, at every point along their length. For a single point mass, a fieldline is a straight line extending in from infinity and terminating at the point mass. Equipotentials are circles centred on the point mass. A small particle released from rest at a point on the fieldline will move along it, accelerating until it collides with the point mass. (For curved fieldlines, the acceleration of the particle, not the velocity, is tangent to the fieldline). In terms of potential, the particle falls down into a potential well gaining kinetic energy as it goes.
Electrostatic fields are much stronger than gravitational fields, and the force can be repulsive (for like charges) or attractive (for unlike charges). Arrays of charges usually are neutral, with fieldlines starting on positive changes and terminating on negative charges. The electrostatic potential is positive and increasing as one approaches a positive charge, and negative and decreasing as one approaches a negative charge.
Both fields obey an inverse-square law, so only one routine (Lplot) is needed. The two examples in the applet have uniform spheres at the vertices of an equilateral triangle. In the gravitational case the masses of the spheres are identical. In the electrostatic case, the charge of the positive sphere is twice the magnitude of the charge of the two negative spheres. In the gravitational case, the fieldlines could be started around the perimeter of the plot, but it is easier to start them uniformly spaced around the spheres and plot them in the reverse direction. In the electrostatic case, the fieldlines start at the positive charge, and are expected to terminate on the negative charges. To get an accurate plot, the algorithm uses a Feynman half-step look ahead when calculating the field direction. It is not easy to see if a fieldline is drawn accurately, but an inaccurate equipotential shows up clearly because it fails to close (equipotentials are drawn perpendicular to the field using the fact that the product of the slopes of perpendicular curves is -1).
Another type of plot can be generated by calculating the gravitational potential at each pixel in the field of view, and using it to set the pixel's colour (Cplot). Equipotentials are not 'drawn' - they appear as the boundaries between regions of different colour. The computational aspect of the program that generates this type of plot is very simple. The only decision that needs to be made concerns the width of the potential region to be plotted as a single colour. The program uses six colours and linear scaling, i.e. the potential changes by the same amount across each colour band.
Note that symmetry constrains the gravitational fieldlines to intersect at the center of the equilateral triangle. (More is said about this in Laplace's Equation.) The field is zero at the center, and the potential is nearly constant over the entire central region. As expected, the electrostatic fieldlines all manage to find their way to a negative charge.
The central red triangle in the gravitational potential plot is an artifact of the (deliberate) choice of boundary in a region where the potential is changing very slowly. A similar choice of boundary in The Thre-Body Problem is used highlight a peak in the potential and explain the motion of the Trojan asteroid group.
The PostScript program lays out the four plots produced in this section and adds two colour potential plots in which hue varies continuously with potential.