Two-dimensional Computer Graphics

Copyright (c) Susan Laflin. August 1999.

Computer graphics involves the use of computers to produce pictures and diagrams. This chapter relates to the production of diagrams made up of lines and curves and which may also be coloured and shaded in various ways.

The most fundamental form of graphical output is the ability to produce a straight line at any required position on whatever output medium is being used. Indeed, if the resolution is sufficiently fine, all other forms of graphics can be produced as a number of straight lines and the human eye will interpret the output as curves or symbols of whatever complexity is required. Since the range of possible results may depend critically on the limits of the available hardware, it is reasonable to start with a discussion of these output devices.

Graphical Output Devices.

The possible forms of two-dimensional graphical output split into two main types - computer screens of various sizes, colours and resolutions and "hard-copy" output such as printers and plotters.

References: Rogers and Adams chapter 1, Foley et al section 1.2 and chapter 4, Hearn and Baker chapter 2.

Drawing Straight Lines (Polyline)

There are actually several stages involved between the idea of a diagram in the mind of its creator and the illumination of a selection of pixels on a computer screen in order to present this diagram to someone else. The additional steps within the human brain required for the recipient to interpret what is seen on the screen will not be discussed here.

Under this heading, we discuss the coordinate systems necessary to generate straight lines on a computer screen; the mathematical equations for these lines and the calculation of points of intersection; the conditions to be satisfied by line-drawing algorithms; detail of the DDA algorithms for both lines and curves; and the problem of "jaggies".

References: Rogers and Adams section 2-5, Foley et al Sections 3.2, 3.3 and 3.14, Hearn and Baker chapter 3.

Text in Graphics (Polymarker and Text).

There are many occasions on which we require text to be mixed with drawings or images and so need some means of providing text output within a graphics system. This section discusses some general comments and also describes the options provided with the GKS standard.

References: Foley et al section 3.12.

Two-dimensional Transformations

Once a diagram has been defined in terms of straight lines expressed as the values of their end-points (x,y) in some Cartesian coordinate system, you may wish to change its position, size or orientation. All these involve the use of transformations to map from the old values of the coordinates to the new ones, after which the diagram is redrawn in its new position.

This section discusses the shift, scale and rotate transformations, with examples of the normalisation transformations needed to transfer from world coordinates the normalised device coordinates used by the GKS metafile standard for transfer between different systems.

References: Rogers and Adams chapter 2, Foley et al sections 5.1 to 5.6, Hearn and Baker chapter 5.

Shading of Polygons (Fill-area).

A polygon is an area enclosed by a sequence of linear segments. There is no restriction on the complexity of the shape produced by these segments, but the last point must always be connected to the first one giving a closed boundary. This differs from Polyline which may produce an open curve with the first and last points being any distance apart.

The section describes tests to decide whether a given point is inside or outside a polygon, and several algorithms to shade the interior of a polygon.

References: Foley et al sections 3.4 to 3.6, Hearn and Baker section 3.11.

Clipping and Windowing.

When you draw a diagram on a piece of paper, you automatically position and scale it so that the drawing remains on the paper. Similarly if you are drawing an object interactively on the screen of a terminal, you will not move the cursor off the screen and so your resulting drawing will be wholly visible. However, the majority of pictures generated in computer graphics do not have these visual checks on the size and position of the resulting output. Usually the coordinates will themselves be the result of lengthy calculations, and it is difficult if not impossible to predict the size of the resulting numbers. Some graphics devices cause the program to crash if you try to access a point outside the permitted area, while others detect this and merely present you with a blank drawing. In either case you will wish to avoid this problem.

In place of the piece of paper, you need to specify a "window" in world coordinates. This means that only x values between xmin and xmax and only y values between ymin and ymax will be plotted. Because these values are specified by the program in the world coordinates in which the problem is defined, the software can test them and if necessary shift the output to ensure that it is visible. This section discusses the methods for clipping either line-drawings or graphs involving shaded areas against a rectangular window in world coordinates.

References: Rogers and Adams section 1-4, Foley et al sections 3.8 to 3.11.

Interactive Graphics.

Most of the programs written today are interactive to some extent. The days when programs were punched on cards and left in a tray to be collected and run by the computer operators, who then returned cards and printout to the users' pigeonholes several hours later, are now past. "Batch-processing", as this rather slow and tedious process was called, may be a very efficient use of machine time but it is very wasteful of programmers' time, and as the cost of hardware falls and that of personnel rises so installations move from batch to interactive use. Interactive use generally results in a less efficient use of the mainframe computer, but gives the programmer a much faster response time, and so speeds up the development of software. This section discusses the techniques used for interactive graphics programs.

References: Rogers and Adams section 1-5, Foley et al sections 1.3, 4.5, and chapter 8.

Drawing Smooth Curves (GDP).

This section considers two topics related to the drawing of smooth curves through one or more points. Firstly it considers the drawing of conic sections (circles, ellipses, parabolae and hyperbolae). Secondly it discusses the problem of producing a curve through a given set of points which appears smooth when viewed on the computer screen. Linear, linear and circular arcs, linear and cubic segments and piecewise cubic interpolation are considered. Finally the special case of cubic splines is discussed, together with a worked example. The recent development of NURBS (Non-Uniform Ration B-Spline curves) is mentioned briefly.

References: Rogers and Adams chapter 4, Foley et al chapter 9, Hearn and Baker section 3.7.