Contents
Introduction
1
Cartesian Coordinate Systems
1.1
1D Mathematics
1.2
2D Cartesian Space
1.2.1
An Example: The Hypothetical City of Cartesia
1.2.2
Arbitrary 2D Coordinate Spaces
1.2.3
Specifying Locations in 2D Using Cartesian Coordinates
1.3
3D Cartesian Space
1.3.1
Extra Dimension, Extra Axis
1.3.2
Specifying Locations in 3D
1.3.3
Left-handed versus Right-handed Coordinate Spaces
1.3.4
Some Important Conventions Used in This Book
1.4
Odds and Ends
1.4.1
Summation and Product Notation
1.4.2
Interval Notation
1.4.3
Angles, Degrees, and Radians
1.4.4
Trig Functions
1.4.5
Trig Identities
1.5
Exercises
2
Vectors
2.1
Mathematical Definition of Vector,
and Other Boring Stuff
2.2
Geometric Definition of Vector
2.3
Specifying Vectors with Cartesian Coordinates
2.3.1
Vector as a Sequence of Displacements
2.3.2
The Zero Vector
2.4
Vectors versus Points
2.4.1
Relative Position
2.4.2
The Relationship between Points and Vectors
2.4.3
It's All Relative
2.5
Negating a Vector
2.5.1
Official Linear Algebra Rules
2.5.2
Geometric Interpretation
2.6
Vector Multiplication by a Scalar
2.6.1
Official Linear Algebra Rules
2.6.2
Geometric Interpretation
2.7
Vector Addition and Subtraction
2.7.1
Official Linear Algebra Rules
2.7.2
Geometric Interpretation
2.7.3
Displacement Vector from One Point to Another
2.8
Vector Magnitude (Length)
2.8.1
Official Linear Algebra Rules
2.8.2
Geometric Interpretation
2.9
Unit Vectors
2.9.1
Official Linear Algebra Rules
2.9.2
Geometric Interpretation
2.10
The Distance Formula
2.11
Vector Dot Product
2.11.1
Official Linear Algebra Rules
2.11.2
Geometric Interpretation
2.12
Vector Cross Product
2.12.1
Official Linear Algebra Rules
2.12.2
Geometric Interpretation
2.13
Linear Algebra Identities
2.14
Exercises
3
Multiple Coordinate Spaces
3.1
Why Bother with Multiple Coordinate Spaces?
3.2
Some Useful Coordinate Spaces
3.2.1
World Space
3.2.2
Object Space
3.2.3
Camera Space
3.2.4
Upright Space
3.3
Basis Vectors and Coordinate Space
Transformations
3.3.1
Dual Perspectives
3.3.2
Specifying Coordinate Spaces
3.3.3
Basis Vectors
3.4
Nested Coordinate Spaces
3.5
In Defense of Upright Space
3.6
Exercises
4
Introduction to Matrices
4.1
Mathematical Definition of Matrix
4.1.1
Matrix Dimensions and Notation
4.1.2
Square Matrices
4.1.3
Vectors as Matrices
4.1.4
Matrix Transposition
4.1.5
Multiplying a Matrix with a Scalar
4.1.6
Multiplying Two Matrices
4.1.7
Multiplying a Vector and a Matrix
4.1.8
Row versus Column Vectors
4.2
Geometric Interpretation of Matrix
4.3
The Bigger Picture of Linear Algebra
4.4
Exercises
5
Matrices and Linear Transformations
5.1
Rotation
5.1.1
Rotation in 2D
5.1.2
3D Rotation about Cardinal Axes
5.1.3
3D Rotation about an Arbitrary Axis
5.2
Scale
5.2.1
Scaling along the Cardinal Axes
5.2.2
Scaling in an Arbitrary Direction
5.3
Orthographic Projection
5.3.1
Projecting onto a Cardinal Axis or Plane
5.3.2
Projecting onto an Arbitrary Line or Plane
5.4
Reflection
5.5
Shearing
5.6
Combining Transformations
5.7
Classes of Transformations
5.7.1
Linear Transformations
5.7.2
Affine Transformations
5.7.3
Invertible Transformations
5.7.4
Angle-Preserving Transformations
5.7.5
Orthogonal Transformations
5.7.6
Rigid Body Transformations
5.7.7
Summary of Types of Transformations
5.8
Exercises
6
More on Matrices
6.1
Determinant of a Matrix
6.1.1
Determinants of
2
×
2
and
3
×
3
matrices
6.1.2
Minors and Cofactors
6.1.3
Determinants of Arbitrary
n
×
n
Matrices
6.1.4
Geometric Interpretation of Determinant
6.2
Inverse of a Matrix
6.2.1
The Classical Adjoint
6.2.2
Matrix Inverse—Official Linear Algebra Rules
6.2.3
Matrix Inverse—Geometric Interpretation
6.3
Orthogonal Matrices
6.3.1
Orthogonal Matrices—Official Linear Algebra Rules
6.3.2
Orthogonal Matrices—Geometric Interpretation
6.3.3
Orthogonalizing a Matrix
6.4
4
×
4
Homogeneous Matrices
6.4.1
4D Homogeneous Space
6.4.2
4
×
4
Translation Matrices
6.4.3
General Affine Transformations
6.5
4
×
4
Matrices and Perspective Projection
6.5.1
A Pinhole Camera
6.5.2
Perspective Projection Matrices
6.6
Exercises
7
Polar Coordinate Systems
7.1
2D Polar Space
7.1.1
Locating Points by Using 2D Polar Coordinates
7.1.2
Aliasing
7.1.3
Converting between Cartesian and
Polar Coordinates in 2D
7.2
Why Would Anybody Use Polar Coordinates?
7.3
3D Polar Space
7.3.1
Cylindrical Coordinates
7.3.2
Spherical Coordinates
7.3.3
Some Polar Conventions Useful in 3D Virtual Worlds
7.3.4
Aliasing of Spherical Coordinates
7.3.5
Converting between Spherical and Cartesian Coordinates
7.4
Using Polar Coordinates to Specify Vectors
7.5
Exercises
8
Rotation in Three Dimensions
8.1
What Exactly is “Orientation”?
8.2
Matrix Form
8.2.1
Which Matrix?
8.2.2
Direction Cosines Matrix
8.2.3
Advantages of Matrix Form
8.2.4
Disadvantages of Matrix Form
8.2.5
Summary of Matrix Form
8.3
Euler Angles
8.3.1
What Are Euler Angles?
8.3.2
Other Euler Angle Conventions
8.3.3
Advantages of Euler Angles
8.3.4
Disadvantages of Euler Angles
8.3.5
Summary of Euler Angles
8.4
Axis-Angle and Exponential Map
Representations
8.5
Quaternions
8.5.1
Quaternion Notation
8.5.2
What Do Those Four Numbers Mean?
8.5.3
Quaternion Negation
8.5.4
Identity Quaternion(s)
8.5.5
Quaternion Magnitude
8.5.6
Quaternion Conjugate and Inverse
8.5.7
Quaternion Multiplication
8.5.8
Quaternion “Difference”
8.5.9
Quaternion Dot Product
8.5.10
Quaternion log, exp, and Multiplication by a Scalar
8.5.11
Quaternion Exponentiation
8.5.12
Quaternion Interpolation, a.k.a. Slerp
8.5.13
Advantages and Disadvantages of Quaternions
8.5.14
Quaternions as Complex Numbers
8.5.15
Summary of Quaternions
8.6
Comparison of Methods
8.7
Converting between Representations
8.7.1
Converting Euler Angles to a Matrix
8.7.2
Converting a Matrix to Euler angles
8.7.3
Converting a Quaternion to a Matrix
8.7.4
Converting a Matrix to a Quaternion
8.7.5
Converting Euler Angles to a Quaternion
8.7.6
Converting a Quaternion to Euler Angles
8.8
Exercises
9
Geometric Primitives
9.1
Representation Techniques
9.2
Lines and Rays
9.2.1
Rays
9.2.2
Special 2D Representations of Lines
9.2.3
Converting between Representations
9.3
Spheres and Circles
9.4
Bounding Boxes
9.4.1
Representing AABBs
9.4.2
Computing AABBs
9.4.3
AABBs versus Bounding Spheres
9.4.4
Transforming AABBs
9.5
Planes
9.5.1
The Plane Equation: An Implicit Definition of a Plane
9.5.2
Defining a Plane by Using Three Points
9.5.3
“Best Fit” Plane for More than Three Points
9.5.4
Distance from Point to Plane
9.6
Triangles
9.6.1
Notation
9.6.2
Area of a Triangle
9.6.3
Barycentric Space
9.6.4
Calculating Barycentric Coordinates
9.6.5
Special Points
9.7
Polygons
9.7.1
Simple versus Complex Polygons
9.7.2
Convex versus Concave Polygons
9.7.3
Triangulation and Fanning
9.8
Exercises
10
Mathematical Topics
from 3D Graphics
10.1
How Graphics Works
10.1.1
The Two Major Approaches to Rendering
10.1.2
Describing Surface Properties: The BRDF
10.1.3
A Very Brief Introduction to Colorimetry
and Radiometry
10.1.4
The Rendering Equation
10.2
Viewing in 3D
10.2.1
Specifying the Output Window
10.2.2
Pixel Aspect Ratio
10.2.3
The View Frustum
10.2.4
Field of View and Zoom
10.2.5
Orthographic Projection
10.3
Coordinate Spaces
10.3.1
Model, World, and Camera Space
10.3.2
Clip Space and the Clip Matrix
10.3.3
The Clip Matrix: Preparing for Projection
10.3.4
The Clip Matrix: Applying Zoom and
Preparing for Clipping
10.3.5
Screen Space
10.3.6
Summary of Coordinate Spaces
10.4
Polygon Meshes
10.4.1
Indexed Triangle Mesh
10.4.2
Surface Normals
10.5
Texture Mapping
10.6
The Standard Local Lighting Model
10.6.1
The Standard Lighting Equation: Overview
10.6.2
The Specular Component
10.6.3
The Diffuse Component
10.6.4
The Ambient and Emmissive Components
10.6.5
The Lighting Equation: Putting It All Together
10.6.6
Limitations of the Standard Model
10.6.7
Flat and Gouraud Shading
10.7
Light Sources
10.7.1
Standard Abstract Light Types
10.7.2
Light Attenuation
10.7.3
Doom
-style Volumetric Lights
10.7.4
Precalculated Lighting
10.8
Skeletal Animation
10.9
Bump Mapping
10.9.1
Tangent Space
10.9.2
Calculating Tangent Space Basis Vectors
10.10
The Real-Time Graphics Pipeline
10.10.1
Buffers
10.10.2
Delivering the Geometry
10.10.3
Vertex-Level Operations
10.10.4
Clipping
10.10.5
Backface Culling
10.10.6
Rasterization, Shading, and Output
10.11
Some HLSL Examples
10.11.1
Decal Shading and HLSL Basics
10.11.2
Basic Per-Pixel Blinn-Phong Lighting
10.11.3
Gouraud Shading
10.11.4
Bump Mapping
10.11.5
Skinned Mesh
10.12
Further Reading
10.13
Exercises
11
Mechanics 1: Linear Kinematics and Calculus
11.1
Overview and Other Expectation-Reducing
Remarks
11.1.1
What is Left Out?
11.1.2
Some Helpful Lies about Our Universe
11.2
Basic Quantities and Units
11.3
Average Velocity
11.4
Instantaneous Velocity and the Derivative
11.4.1
Limit Arguments and the Definition of the Derivative
11.4.2
Examples of Derivatives
11.4.3
Calculating Derivatives from the Definition
11.4.4
Notations for the Derivative
11.4.5
A Few Differentiation Rules and Shortcuts
11.4.6
Derivatives of Some Special Functions
with Taylor Series
11.4.7
The Chain Rule
11.5
Acceleration
11.6
Motion under Constant Acceleration
11.7
The Integral
11.7.1
Examples of Integrals
11.7.2
The Relationship between the Derivative
and the Integral
11.7.3
Summary of Calculus
11.8
Uniform Circular Motion
11.8.1
Uniform Circular Motion in the Plane
11.8.2
Uniform Circular Motion in Three Dimensions
11.9
Exercises
12
Mechanics 2: Linear and Rotational Dynamics
12.1
Newton's Three Laws
12.1.1
Newton's First Two Laws: Force and Mass
12.1.2
Inertial Reference Frames
12.1.3
Newton's Third Law
12.2
Some Simple Force Laws
12.2.1
Gravitational Force
12.2.2
Frictional Forces
12.2.3
Spring Forces
12.3
Momentum
12.3.1
Conservation of Momentum
12.3.2
The Center of Mass
12.4
Impulsive Forces and Collisions
12.4.1
Perfectly Inelastic Collisions
12.4.2
General Collision Response
12.4.3
The Dirac Delta
12.5
Rotational Dynamics
12.5.1
Rotational Kinematics
12.5.2
2D Rotational Dynamics
12.5.3
3D Rotational Dynamics
12.5.4
Collision Response with Rotations
12.6
Real-Time Rigid Body Simulators
12.6.1
Physics Engine State Variables
12.6.2
HighLevel Overview
12.6.3
Euler Integration
12.6.4
Integration of Rotation
12.7
Suggested Reading
12.8
Exercises
13
Curves in 3D
13.1
Parametric Polynomial Curves
13.1.1
Parametric Curves
13.1.2
Polynomial Curves
13.1.3
Matrix Notation
13.1.4
Two Trivial Types of Curves
13.1.5
Endpoints in Monomial Form
13.1.6
Velocities and Tangents
13.2
Polynomial Interpolation
13.2.1
Aitken's Algorithm
13.2.2
Lagrange Basis Polynomials
13.2.3
Polynomial Interpolation Summary
13.3
Hermite Curves
13.4
Bézier Curves
13.4.1
The de Casteljau Algorithm
13.4.2
The Bernstein Basis
13.4.3
Bézier Derivatives and Their Relationship
to the Hermite Form
13.5
Subdivision
13.5.1
Subdividing Curves in Monomial Form
13.5.2
Subdividing Curves in Bézier Form
13.6
Splines
13.6.1
Rules of the Game
13.6.2
Knots
13.7
Hermite and Bézier Splines
13.8
Continuity
13.8.1
Parametric Continuity
13.8.2
Geometric Continuity
13.8.3
How Smooth Can a Curve Be?
13.9
Automatic Tangent Control
13.9.1
Catmull-Rom Splines
13.9.2
TCB Splines
13.9.3
Endpoint Conditions
13.10
Exercises
14
Afterword
14.1
What Next?
14.2
Exercises
A
Geometric Tests
A.1
Closest Point on 2D Implicit Line
A.2
Closest Point on a Parametric Ray
A.3
Closest Point on a Plane
A.4
Closest Point on a Circle or Sphere
A.5
Closest Point in an AABB
A.6
Intersection Tests
A.7
Intersection of Two Implicit Lines in 2D
A.8
Intersection of Two Rays in 3D
A.9
Intersection of a Ray and Plane
A.10
Intersection of an AABB and Plane
A.11
Intersection of Three Planes
A.12
Intersection of Ray and a Circle or Sphere
A.13
Intersection of Two Circles or Spheres
A.14
Intersection of a Sphere and AABB
A.15
Intersection of a Sphere and a Plane
A.16
Intersection of a Ray and a Triangle
A.17
Intersection of Two AABBs
A.18
Intersection of a Ray and an AABB
B
Answers to the Exercises
B.1
Chapter 1
B.2
Chapter 2
B.3
Chapter 3
B.4
Chapter 4
B.5
Chapter 5
B.6
Chapter 6
B.7
Chapter 7
B.8
Chapter 8
B.9
Chapter 9
B.10
Chapter 10
B.11
Chapter 11
B.12
Chapter 12
B.13
Chapter 13
B.14
Chapter 14
So much time, and so little to do!
Strike that, reverse it.
— Willy Wonka