i
i
i
i
i
i
i
i
2
Miscellaneous Math
Much of graphics is just translating math directly into code. The cleaner the math,
the cleaner the resulting code; so much of this book concentrates on using just the
right math for the job. This chapter reviews various tools from high school and
college mathematics and is designed to be used more as a reference than as a tu-
torial. It may appear to be a hodge-podge of topics and indeed it is; each topic
is chosen because it is a bit unusual in “standard” math curricula, because it is
of central importance in graphics, or because it is not typically treated from a ge-
ometric standpoint. In addition to establishing a review of the notation used in
the book, the chapter also emphasizes a few points that are sometimes skipped
in the standard undergraduate curricula, such as barycentric coordinates on tri-
angles. This chapter is not intended to be a rigorous treatment of the material;
instead intuition and geometric interpretation are emphasized. A discussion of
linear algebra is deferred until Chapter 5 just before transformation matrices are
discussed. Readers are encouraged to skim this chapter to familiarize themselves
with the topics covered and to refer back to it as needed. The exercises at the end
of the chapter may be useful in determining which topics need a refresher.
2.1 Sets and Mappings
Mappings, also called functions, are basic to mathematics and programming. Like
a function in a program, a mapping in math takes an argument of one type and
maps it to (returns) an object of a particular type. In a program we say “type;” in
13
i
i
i
i
i
i
i
i
14 2. Miscellaneous Math
math we would identify the set. When we have an object that is a member of a
set, we use the symbol. For example,
a S,
can be read a is a member of set S. Given any two sets A and B, we can create
a third set by taking the Cartesian product of the two sets, denoted A × B.This
set A × B is composed of all possible ordered pairs (a, b) where a A and
b B. As a shorthand, we use the notation A
2
to denote A × A. We can extend
the Cartesian product to create a set of all possible ordered triples from three sets
and so on for arbitrarily long ordered tuples from arbitrarily many sets.
Common sets of interest include:
R—the real numbers;
R
+
—the non-negative real numbers (includes zero);
R
2
—the ordered pairs in the real 2D plane;
R
n
—the points in n-dimensional Cartesian space;
Z—the integers;
S
2
—the set of 3D points (points in R
3
) on the unit sphere.
Note that although S
2
is composed of points embedded in three-dimensional
space, they are on a surface that can be parameterized with two variables, so it
can be thought of as a 2D set. Notation for mappings uses the arrow and a colon,
for example:
f : R → Z,
which you can read as “There is a function called f that takes a real number as
input and maps it to an integer. Here, the set that comes before the arrow is called
the domain of the function, and the set on the right-hand side is called the target.
Computer programmers might be more comfortable with the following equivalent
language: “There is a function called f which has one real argument and returns
an integer. In other words, the set notation above is equivalent to the common
programming notation:
Figure 2.1. A bijection
f
and the inverse function
f
1
. Note that
f
–1
is also
a bijection.
integer f(real) equivalent f : R → Z.
So the colon-arrow notation can be thought of as a programming syntax. It’s that
simple.
The point f(a) is called the image of a, and the image of a set A (a subset of
the domain) is the subset of the target that contains the images of all points in A.
The image of the whole domain is called the range of the function.

Get Fundamentals of Computer Graphics, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.