Preface |
|
xiii | |
Acknowledgments |
|
xv | |
About this book |
|
xvii | |
About the author |
|
xxi | |
About the cover illustration |
|
xxii | |
|
|
1 | (13) |
|
1.1 Which parts of programming require geometry? |
|
|
3 | (1) |
|
1.2 What is geometry for programmers? |
|
|
4 | (1) |
|
1.3 Why not let my tools take care of geometry? |
|
|
5 | (1) |
|
1.4 Applied geometry has been around forever; why learn it now? |
|
|
6 | (2) |
|
1.5 You don't have to know much to start |
|
|
8 | (1) |
|
1.6 SymPy will do your math for you |
|
|
9 | (5) |
|
|
14 | (34) |
|
2.1 Numbers, points, and vectors |
|
|
15 | (9) |
|
|
15 | (6) |
|
|
21 | (3) |
|
|
24 | (1) |
|
2.2 Vertices and triangles |
|
|
24 | (5) |
|
Being pedantic about triangles |
|
|
25 | (1) |
|
|
25 | (3) |
|
|
28 | (1) |
|
2.3 Lines, planes, and their equations |
|
|
29 | (5) |
|
|
29 | (2) |
|
The parametric form for 3D lines |
|
|
31 | (3) |
|
|
34 | (1) |
|
2.4 Functions and geometric transformations |
|
|
34 | (7) |
|
|
34 | (4) |
|
Function types most commonly used in geometric modeling |
|
|
38 | (3) |
|
|
41 | (1) |
|
2.5 The shortest possible introduction to matrix algebra |
|
|
41 | (5) |
|
|
41 | (2) |
|
How does matrix algebra work? |
|
|
43 | (2) |
|
|
45 | (1) |
|
|
46 | (1) |
|
2.7 Solutions to exercises |
|
|
46 | (2) |
|
3 The geometry of linear equations |
|
|
48 | (38) |
|
3.1 Linear equations as lines and planes |
|
|
49 | (4) |
|
|
49 | (2) |
|
A solution is where hyperplanes intersect |
|
|
51 | (2) |
|
|
53 | (1) |
|
3.2 Overspecified and underspecified systems |
|
|
53 | (2) |
|
|
53 | (2) |
|
|
55 | (1) |
|
|
55 | (1) |
|
3.3 A visual example of an interactive linear solver |
|
|
55 | (5) |
|
The basic principle of iteration |
|
|
56 | (3) |
|
Starting point and exit conditions 57' Convergence and stability |
|
|
59 | (1) |
|
|
60 | (1) |
|
|
60 | (5) |
|
Turning an iterative solver into a direct one |
|
|
60 | (2) |
|
|
62 | (3) |
|
|
65 | (1) |
|
3.5 Linear equations system as matrix multiplication |
|
|
65 | (4) |
|
|
65 | (1) |
|
What types of matrices we should know about |
|
|
66 | (2) |
|
Things we're allowed to do with equations |
|
|
68 | (1) |
|
|
69 | (1) |
|
3.6 Solving linear systems with Gaussian elimination and LU-decomposition |
|
|
69 | (5) |
|
An example of Gaussian elimination |
|
|
69 | (3) |
|
What do "elimination" and "decomposition" mean? |
|
|
72 | (2) |
|
|
74 | (1) |
|
3.7 Which solver fits my problem best? |
|
|
74 | (3) |
|
When to use an elimination-based one |
|
|
74 | (1) |
|
When to use an iterative one |
|
|
75 | (1) |
|
|
76 | (1) |
|
|
76 | (1) |
|
3.8 Practical example: Does a ray hit a triangle? |
|
|
77 | (6) |
|
The ray-triangle intersection problem |
|
|
77 | (1) |
|
|
78 | (2) |
|
Making the equations into code |
|
|
80 | (2) |
|
|
82 | (1) |
|
|
83 | (1) |
|
3.10 Solutions to exercises |
|
|
84 | (2) |
|
4 Projective geometric transformations |
|
|
86 | (40) |
|
4.1 Some special cases of geometric transformations |
|
|
87 | (7) |
|
|
87 | (1) |
|
|
88 | (2) |
|
|
90 | (4) |
|
|
94 | (1) |
|
|
94 | (9) |
|
Linear transformations in Euclidean space |
|
|
94 | (4) |
|
Bundling rotation, scaling, and translation in a single affine transformation |
|
|
98 | (2) |
|
Generalizing affine transformations to projective transformations |
|
|
100 | (2) |
|
An alternative to projective transformations |
|
|
102 | (1) |
|
|
103 | (1) |
|
4.3 Projective space and homogeneous coordinates |
|
|
103 | (13) |
|
Expanding the whole space with homogeneous coordinates |
|
|
104 | (4) |
|
Making all the transformations a single matrix multiplication: Why? |
|
|
108 | (8) |
|
|
116 | (1) |
|
|
116 | (7) |
|
|
116 | (4) |
|
Does a point belong to a triangle? |
|
|
120 | (2) |
|
|
122 | (1) |
|
|
123 | (1) |
|
4.6 Solutions to exercises |
|
|
124 | (2) |
|
5 The geometry of calculus |
|
|
126 | (31) |
|
5.1 What is a derivative? |
|
|
127 | (9) |
|
|
128 | (1) |
|
|
129 | (5) |
|
|
134 | (1) |
|
Using SymPy to do differentiation |
|
|
135 | (1) |
|
|
136 | (1) |
|
5.2 Smooth piecewise parametric curves |
|
|
136 | (7) |
|
|
137 | (1) |
|
|
138 | (2) |
|
|
140 | (3) |
|
|
143 | (1) |
|
5.3 Practical example: Crafting a curve out of lines and circles |
|
|
143 | (11) |
|
|
143 | (5) |
|
The line segment and arc building block |
|
|
148 | (4) |
|
|
152 | (1) |
|
|
153 | (1) |
|
|
154 | (1) |
|
5.5 Solutions to exercises |
|
|
154 | (3) |
|
6 Polynomial approximation and interpolation |
|
|
157 | (46) |
|
6.1 What are polynomials? |
|
|
158 | (7) |
|
Axis intersections and roots of polynomial equations |
|
|
159 | (3) |
|
|
162 | (3) |
|
|
165 | (1) |
|
6.2 Polynomial approximation |
|
|
165 | (14) |
|
Maclaurin and Taylor series |
|
|
166 | (5) |
|
The method of least squares |
|
|
171 | (4) |
|
Practical example: Showing a trend with approximation |
|
|
175 | (4) |
|
|
179 | (1) |
|
6.3 Polynomial interpolation |
|
|
179 | (16) |
|
Using Vandermonde matrix to get the interpolating polynomial |
|
|
180 | (5) |
|
What limits polynomial interpolation application to small data only? |
|
|
185 | (1) |
|
How to lessen unwanted oscillations |
|
|
186 | (1) |
|
Lagrange interpolation: Simple, genius, unnecessary |
|
|
187 | (4) |
|
Practical example: Showing the trend with interpolation |
|
|
191 | (4) |
|
|
195 | (1) |
|
6.4 Practical example: Showing a trend with both approximation and interpolation |
|
|
195 | (5) |
|
|
195 | (2) |
|
|
197 | (2) |
|
|
199 | (1) |
|
|
200 | (1) |
|
6.6 Solutions to exercises |
|
|
200 | (3) |
|
|
203 | (38) |
|
7.1 Going beyond the interpolation |
|
|
204 | (11) |
|
Making polynomial graphs with tangent constraints |
|
|
204 | (2) |
|
Practical example: Approximating the sine function for a space simulator game |
|
|
206 | (8) |
|
Unexpected fact: Explicit polynomial modeling generalizes power series |
|
|
214 | (1) |
|
|
215 | (1) |
|
7.2 Understanding polynomial splines and Bezier curves |
|
|
215 | (18) |
|
Explicit polynomial parametric curves |
|
|
216 | (5) |
|
Practical example: Crafting a spline for points that aren't there yet |
|
|
221 | (5) |
|
|
226 | (7) |
|
|
233 | (1) |
|
|
233 | (6) |
|
BS stands for "basis spline" |
|
|
233 | (2) |
|
NU stands for "nonuniform" |
|
|
235 | (1) |
|
|
235 | (1) |
|
Not-so-practical example: Building a circle with NURBS |
|
|
236 | (2) |
|
|
238 | (1) |
|
|
239 | (1) |
|
7.5 Solutions to exercises |
|
|
239 | (2) |
|
8 Nonlinear transformations and surfaces |
|
|
241 | (39) |
|
8.1 Polynomial transformations in multidimensional space |
|
|
242 | (13) |
|
The straightforward approach to polynomial transformations |
|
|
242 | (5) |
|
The fast and simple approach to polynomial transformations |
|
|
247 | (4) |
|
Practical example: Adding the "unbending" feature to the scanning app |
|
|
251 | (4) |
|
|
255 | (1) |
|
|
255 | (8) |
|
A surface is just a 3D transformation of a plane |
|
|
255 | (2) |
|
Practical example: Planting polynomial mushrooms |
|
|
257 | (6) |
|
|
263 | (1) |
|
8.3 Using nonpolynomial spatial interpolation in geometry |
|
|
263 | (14) |
|
Inverse distance interpolation |
|
|
264 | (4) |
|
Inverse distance interpolation in space |
|
|
268 | (2) |
|
Practical example: Using localized inverse distance method to make a bitmap continuous and smooth |
|
|
270 | (5) |
|
Practical example: Building a deformation field with multivariable interpolation to generate better mushrooms |
|
|
275 | (2) |
|
|
277 | (1) |
|
|
277 | (1) |
|
8.5 Solutions to exercises |
|
|
278 | (2) |
|
9 The geometry of vector algebra |
|
|
280 | (30) |
|
9.1 Vector addition and scalar multiplication as transformations |
|
|
281 | (1) |
|
9.2 Dot product: Projection and angle |
|
|
282 | (8) |
|
Other names and motivations behind them |
|
|
282 | (3) |
|
Vectors and their dot product in SymPy |
|
|
285 | (1) |
|
Practical example: Using a dot product to light a scene |
|
|
286 | (4) |
|
|
290 | (1) |
|
9.3 Cross product: Normal vector and the parallelogram area |
|
|
290 | (7) |
|
Other names and motivations behind them |
|
|
290 | (3) |
|
The cross product in SymPy |
|
|
293 | (1) |
|
Practical example: Check whether a triangle contains a point in 2D |
|
|
293 | (4) |
|
|
297 | (1) |
|
9.4 Triple product: The parallelepiped volume |
|
|
297 | (5) |
|
The geometric sense of the triple product |
|
|
298 | (1) |
|
The triple product in SymPy |
|
|
299 | (1) |
|
Practical example: Distance to a plane |
|
|
300 | (1) |
|
|
301 | (1) |
|
9.5 Generalization for parallelotopes |
|
|
302 | (6) |
|
|
302 | (1) |
|
|
302 | (3) |
|
|
305 | (2) |
|
|
307 | (1) |
|
|
308 | (1) |
|
9.7 Solutions to exercises |
|
|
308 | (2) |
|
20 Modeling shapes with signed distance junctions and surrogates |
|
|
310 | (31) |
|
|
311 | (10) |
|
Does it have to be an SDF? |
|
|
312 | (1) |
|
|
313 | (3) |
|
Theoretical example: Making an SDF of a triangle mesh |
|
|
316 | (2) |
|
Practical example: Making an SDF of a rectangle in 2D |
|
|
318 | (3) |
|
|
321 | (1) |
|
10.2 How to work with SDFs |
|
|
321 | (7) |
|
How to translate, rotate, or scale an SDF |
|
|
322 | (1) |
|
How to unite, intersect, and subtract SDFs |
|
|
323 | (3) |
|
How to dilate and erode an SDF |
|
|
326 | (1) |
|
|
327 | (1) |
|
|
328 | (1) |
|
10.3 Some techniques of not-really-SDF implicit modeling |
|
|
328 | (13) |
|
Tri-periodic minimal surfaces |
|
|
329 | (2) |
|
Practical example: A gyroid with variable thickness |
|
|
331 | (1) |
|
|
332 | (2) |
|
Practical example: Localizing the metaballs for speed and better governance |
|
|
334 | (2) |
|
|
336 | (1) |
|
Practical example: A play button made of a multifocal lemniscate |
|
|
337 | (2) |
|
|
339 | (1) |
|
|
339 | (1) |
|
10.5 Solutions to exercises |
|
|
339 | (2) |
|
11 Modeling surfaces with boundary representations and triangle meshes |
|
|
341 | (33) |
|
11.1 Smooth curves and surfaces |
|
|
343 | (3) |
|
|
343 | (1) |
|
|
344 | (2) |
|
|
346 | (1) |
|
11.2 Segments and triangles |
|
|
346 | (6) |
|
Vertices and triangles vs. the half-edge representation |
|
|
347 | (2) |
|
Pros and cons of triangle meshes |
|
|
349 | (3) |
|
|
352 | (1) |
|
11.3 Practical example: Contouring with marching cubes and dual contouring algorithms |
|
|
352 | (13) |
|
|
354 | (6) |
|
|
360 | (3) |
|
Is it that simple in practice, too? |
|
|
363 | (1) |
|
|
364 | (1) |
|
11.4 Practical example: Smooth contouring |
|
|
365 | (6) |
|
|
366 | (2) |
|
|
368 | (3) |
|
|
371 | (1) |
|
|
371 | (1) |
|
11.6 Solutions to exercises |
|
|
372 | (2) |
|
12 Modeling bodies with images and voxels |
|
|
374 | (32) |
|
12.1 How does computed tomography work? |
|
|
375 | (3) |
|
12.2 Segmentation by a threshold |
|
|
378 | (2) |
|
12.3 Typical operations on 3D images: Dilation, erosion, cavity fill, and Boolean |
|
|
380 | (8) |
|
|
381 | (2) |
|
|
383 | (1) |
|
Practical example: Denoising |
|
|
384 | (2) |
|
Boolean operations on voxel models |
|
|
386 | (1) |
|
A few other uses of dilation and erosion |
|
|
387 | (1) |
|
|
388 | (1) |
|
12.4 Practical example: Image vectorization |
|
|
388 | (14) |
|
|
389 | (2) |
|
|
391 | (1) |
|
|
392 | (1) |
|
Step 3 Make the contour smooth |
|
|
393 | (2) |
|
|
395 | (6) |
|
|
401 | (1) |
|
12.5 How voxels, triangles, parametric surfaces, and SDFs work together |
|
|
402 | (2) |
|
|
404 | (1) |
|
12.7 Solutions to exercises |
|
|
404 | (2) |
Appendix Sources, references, and further reading |
|
406 | (3) |
Index |
|
409 | |