﻿ Vector Graphics Algorithms
Vector Graphics
Algorithms
 Site Map Feedback
 gCoord Points Vectors PV Planes

Fundamentals

The code in this section is designed to allow you to store and draw lines, arcs and splines which may represent three-dimensional objects.

People used to worry about speed differences in using integers or floating-point arithmetic for graphics. Modern processors and graphics boards mean that whatever is most natural can often be used, so floating-point arithmetic is used here and rounding errors dealt with by specifying a "Tolerance". This Tolerance is the core of the whole system on these pages and, consequently, discussed in depth later. Using floating-point arithmetic allows you to debug and see real values. Conversion from double to integer still needs some thought though, because current floating point processors clear the processor pipeline when setting the rounding mode. Methods Floor and Round provided in Global.h work around this.

The Graphics Primitive structures are all prefixed with "g" (for "graphic") and a number representing the number of Dimensions the structure will handle (2 or 3). So the three-dimensional Point structure is a g3Point. Two and three dimensional structures are presented for each concept and abuse the whole idea of object orientation by defining the structures in terms of the data they will hold rather than the object they represent. At first this seems bizarre, but when you are actually working with the classes you'll be surprised at how rarely you think about the object you're dealing with: you're almost always more concerned with the maths defining the object. So, for example, there is a class which contains a Vertex and a Vector... The word "Point" is used instead of "Vertex" so that the class for a for "PointVector" can be called "g3PV"... This class could represent a Position Vector, or a Line, or an axially-aligned Box (Point is one corner, Vector points to opposite corner). The maths for each possibility is likely to be in the primitive, so a g3PV will have a "Hit" function to to see if a point lies on the line; a "HitBox" function to see if it lies in the Box etc. That's why these structures are referred to as "Primitives": you can derive "proper" classes from them, but at this level, they are simple open boxes to hold things in.