18.1 Basic Graphics Concepts

Picturing the relationships between two kinds of data is commonly done using points on a Cartesian plane as described in section 6.9. In that section, however, only the algebraic characteristics of points in a plane were realized--no graphical results were achieved. This type of support more difficult to achieve for three reasons:

first because providing support for drawing on the screen of the computer requires at least some platform specific abilities,

second because, although the mathematical model for graphing envisions a coordinate system employing real numbers, the graphics environment on computers uses discrete dots, and these are limited in number. This requires some compromises in the visual presentation,

third because the number of dots (pixels) available in the vertical and horizontal directions cannot be know ahead of time, and

fourth because even in typical mathematical use there is more than one type of coordinate system.

It should be noted at this stage that the ISO committee made no attempt to include any form of graphics support in its standard library, so this leaves the student on her own for such important tasks.

The underlying graphics user interface supplied by the computer manufacturer, and to which the compiler vendor will no doubt provide some interface will probably include a number of tools for indicating points on the screen, drawing lines, curves, and even a few predefined shapes. As these are quite system dependent, consideration of them will be postponed for a few sections.

18.1.1 Discrete Grids--Graphing Pixels

The standard rectangular or Cartesian (named after Ren้ Descartes) has two perpendicular real number lines (axes) which divide the plane into four quadrants. The place where the number lines cross is the origin (0, 0) and the numbering is positive to the right and up; negative to the left and down. This abstraction includes the ability to graph a line as a set of continuous points, including those such as (ผ, 1) where the decimal representation continues indefinitely without repetition or terminating.

On a typical computer generated graphics raster, there are several hundred pixel points available in both the horizontal and vertical directions, and they are much closer together than suggested in figure 18.1 below. The standard grid could simply be modified to take this into account, but only points with whole number coordinates can be properly depicted. The point (ผ, 1) would have to be depicted as (3,1) unless some form of scaling were used. Indeed, since the individual pixels are rather close together on the screen, it might be better to magnify this and use, say, ten points for a unit, marking (31, 10) on the raster to represent this point.

18.1.2 Where is the origin?

When the Macintosh--the first popular graphics-oriented computer was developed--it had the origin not at the centre of the screen as suggested in the above diagrams, but at the top left corner. The positive horizontal direction was still to the right, but the positive vertical direction goes down, rather than up. There are still four quadrants, as points can have negative coordinates, but three of the quadrants are off the screen. As with many other parts of the interface, this arrangement was subsequently copied into other graphics user systems, including the various versions of Windows. The standard mathematical system and the Mac/Windows screen are illustrated in figure 18.2.

A graphing module used on either of these systems will need to have the option of using the native system directly, or passing conventional mathematical coordinates and then translating to the native screen.

18.1.3 Measuring Angles

Yet another option needed for graphing is created by the fact that when the focus is on polar coordinates--that is, the angle and distance from the origin are given--rather than on rectangular coordinates, there are two common systems for measuring angles. In the standard system used in mathematics and physics, the angle zero is the positive horizontal axis (East; also called the polar axis) and angles are measured counterclockwise (either in degrees or radians.) However, in the bearing system used in navigation, the positive vertical axis (North) is taken as the zero angle, and bearings are measured clockwise. For the Macintosh/Windows raster, it makes sense to use the positive horizontal axis for zero and measure counterclockwise, as only one quadrant is on the screen.

In addition, because some people prefer to graph in degrees and others in radians, a graphing module perhaps ought to provide the option to do either.