COMP 290-001: Algorithm Library Design: Lecture Notes

6. Design Example for an Affine-Geometry Kernel


Introduction

This design example is influenced by
CGAL, recent proposals on the internal redesign of the kernel in CGAL, and ideas from coordinate free geometry [DeRose89], see also http://www.cgl.uwaterloo.ca/~njlitke/geometry/.


Domain Dictionary

Affine Space An affine space consists of a point space and a linear vector space. The vector space is connected with the point space as follows: For each pair of points in the point space the difference between the two points is a vector in the vector space. For each vector in the vector space and for each point in the point space, adding the vector to the point results in a point in the point space. Every triple of points, p, q, r, satisfies (p-q) + (q-r) = p-r.
Reference Frame A reference frame (frame for short) defines a new affine space in an existing one. A reference frame consist of a distinguished base point (the new origin) and a basis for the vector space, i.e., d linear independent vectors if d is the dimension of the affine space (which is the same as for the vector space). A reference frame defines a coordinate system for the points in an affine space.
Point A point is an element of the point space of an affine space. In an affine space of dimension d a point pcan be represented using d Cartesian coordinates, (p1, p2, ..., pd), with respect to a reference frame.
Origin The origin is a distinguished point in the current reference frame with all coordinates equal to zero.
Vector A vector is an element of the vector space of an affine space. A vector is the difference vector between two points. In an affine space of dimension d a vector vcan be represented using d Cartesian coordinates, (v1, v2, ..., vd), with respect to a reference frame.
Hyperplane A hyperplane h is defined using d+1 coefficient (h0, h1, h2, ..., hd). A point p that lies in the hyperplane h satisfies the equation h0 + h1 p1 + h2 p2 + ... + hd pd = 0 . Adding a zeroth coordinate to points that is constantly one, the equation homogenizes to the inner vector product <h, p> = hT · p = 0.
Affine Combination An affine combination of n points, p1, p2, ...,pn, is defined as a1 p1 + a2 p2 + ... + an pn , where the sum of the coefficients ai equals 1, a1 + a2 + ... + an = 1 .
Affine Transformation An affine transformation is a linear mapping from an affine space to an affine space that preserves affine combinations. An affine transformation in a d-dimensional affine space is fully specified by giving the image and pre-image of d+1 points (i.e. a d-simplex). The mapping for the points extends uniquely for the vector space since affine transformations are linear mappings. This implies that the affine transformation of the difference of two points (a vector) is the same as the difference of two affine transformed points.

If the image space is not the same as the pre-image space, i.e., more than one reference frame is involved, it is necessary to keep track in which spaces the affine transformation operates. Let X be the space of the pre-image, Y the space of the image, pX the pre-image point in X, and qY the image point in Y. The affine transformation AYX maps pX to qY, qY = AYX pX. Note, how the indices for the space line up nicely if we compose two affine transformation to go from space X to Y and to Z: rZ = BZY AYX pX.

An affine transformation for fixed reference frames can be represented as a vector and a matrix. The vector is a translation vector and the matrix represents a linear transformation acting on the vector space.

Change of Reference
Frame
Points have different coordinate representations in different reference frames. Going from one reference frame to another reference frame is a specific affine transformation (affine combinations are preserved). Assuming the reference frame for the new space is given in the reference frame of the points, the affine transformation is easily specified as follows; the base point of the reference frame maps to the origin and each vector in the basis of the reference frame maps to the unit vectors of the standard basis.

We use the same index notation as for affine transformations to indicate the involved affine spaces.

Line Defined by two distinct points through which the line passes. In dimension two hyperplanes are lines, see hyperplanes for an alternative representation in this case. In general, lines can also be represented as the intersection of d-1 hyperplanes.
Ray Defined by a base point and a vector for the direction.
Segment Defined by two distinct endpoints.
Triangle Defined by three pairwise distinct endpoints.
...

Affine transformations do not preserve angles and distances. We need Euclidean geometry and rigid motions for that.


Domain Analysis

Points versus vectors

Points and vectors are not the same. Their coordinate representation looks the same, but, for example, they do not transform the same way under affine transformations. Furthermore, all vector operations are defined for the vectors, but with the exception of affine combinations none are allowed on points.

Points are vectors are related to each other. Vectors are difference vectors between points and we can add a vector to a point to get a translated point. The origin as distinguished point allows to convert between points and vectors (the locus vector of the point in the current reference frame). See the section Geometric Kernel in the Chapter about CGAL for a description of the solution in CGAL that uses a symbolic origin to make this conversion efficient (see also Origin.C for an example point/vector/origin implementation).

Hyperplanes and covectors

The coefficient list of a hyperplane consists of a normal vector ( h1, h2, ..., hd) (a vector orthogonal to the hyperplane) and a scalar h0 that specifies the distance of the hyperplane from the origin. However, hyperplanes and normal vectors do not transform like vectors under affine transformations. (Normal vectors are also called covectors which emphasizes there difference to regular vectors as defined above.)

Consider a hyperplane h and a point p in the hyperplane, i.e., h p = 0 assuming the extended coordinate representation for points. This linear equation must stay invariant under an affine transformation A. We assume a matrix representation for the affine transformation A. Denote the unknown transformation matrix for the hyperplane with B.

0 = hT · p
= (B h)T · (A p)
= hT BT · (A p)

In order to satisfy this equation we have to choose BT equal to A-1. The correct application of an affine transformation to a hyperplane is therefore:

h' = (A-1)T h

Change of reference frames and affine transformations

Even though the change of a reference frame can be expressed as an affine transformation they should be distinguished painstakingly. Reference frames serve the purpose of representing the same geometric configuration in different coordinate systems. On the other hand, affine transformations move the geometric configuration around. Without separating these two concepts, the following exercise gets hard. Assume two affine spaces, X and Y, and an affine transformation AXX in space X that is supposed to transform some points in space Y. Express the affine transformation in the reference frame of space Y.

Assume we have constructed the affine transformations M for the reference frame of Y to go from X to Y with MYX and to go from Y to X with MXY = M-1YX. Now, the correct way of transforming a point p represented in Y is to map the point first to X, transform it, and map the result back to Y.

qY = MYX AXX MXY pX.

We can conclude that the correct affine transformation in space Y is:

AYY = MYX AXX MXY = MYX AXX M-1YX.

Note how the indices for the different affine spaces line up nicely in the equations (a kind of type checking in mathematics).


COMP 290-001: Algorithm Library Design: Lecture Notes
Lutz Kettner () 27.04.2000