<<

Glimpses of geometry and graphics

Przemys law Koprowski

Contents

Introduction 5

Part 1. Geometry of space 7

Chapter 1. and affine transforms 9 1. 9 2. Homogeneous coordinates 11 3. Vectors and normals 17 4. Isometries 19 5. Transformation decomposition 23 Implementation notes 25 Exercises 25 Bibliographic notes 25

Chapter 2. Projective space and quaternions 27 1. Projective maps 27 2. Projections and perspective 32 3. Duality and the Pl¨ucker-Grassmann coordinates 41 4. Quaternions and transform interpolation 54 Exercises 62 Bibliographic notes 63

Part 2. Geometry of curves 65

Chapter 3. Cubic curves 67 1. Introduction 67 2. B´eziersplines 71 3. Interpolation with B´ezier curves 75 4. Catmull-Rom splines 79 5. B-splines 85 6. Other cubic representations 89 7. Change of basis 90 8. Curve splitting 93 Implementation notes 95 Exercises 95 Bibliographic notes 96

Chapter 4. Rational parametric curves 103 1. Why rational splines? 103 2. B´eziercurves 106

3 4 CONTENTS

3. Uniform B-splines 112 4. NURBS 118 5. Tangent and curvature 124 6. On-curve alignment 124 7. and geometric continuity 124 8. Arc-length parametrization 124 Exercises 124

Chapter 5. Spherical curves 125 1. Transformation interpolation revisited 125 Chapter 6. Algebraic curves 127 1. Affine algebraic curves 127 2. 128 3. Projective algebraic curves 133 4. Singular points on algebraic curves 138 5. Parametrization of algebraic curves 141 6. Implicitization of parametric curves 147 7. Intersection points 148 8. Hessian and the inflection points 150 9. Cubic curves 154 Implementation notes 163 Exercises 163 Bibliographic notes 163

Part 3. Geometry of solids and surfaces 165 Chapter 7. Polygons and polyhedra 167 1. Triangles 167 2. Convex polytopes 170 3. Convex polygons 171

Chapter 8. Parametric surfaces 173 Bibliography 175 Introduction

“They believe the world is run by geometry. All lines and angles and numbers. That sort of thing [ ... ] can lead to some very unsound ideas.” — T. Pratchett

Part 1

Geometry of space

CHAPTER 1

Homogeneous coordinates and affine transforms

“Space is essentially one” — I. Kant

“We cannot assert with Kant that the propositions of Euclidean geometry possess any universal truth” — A. D’Abro This chapter introduces the notion of homogeneous coordinates, which is one of the fundamental structures in the domain of geometric modeling. To this end we shall define a projective space, which is an extension of an affine space known from the basic linear algebra. We won’t, however, present an in-depth exposition of in this chapter and, after introducing a homogeneous coordi- nate system, we will restrict ourselves to the affine case, returning to the projective space in Chapter 2. In computer graphics, one constantly deals with basic geometric transforma- tions of R3 such as a rotation, scaling and translation. The former two transfor- mations are linear maps, but the last one is not linear. It is well known, that every linear transform can be represented with a use of matrix multiplication. Fix T T T 3 the canonical basis ε1 = (1, 0, 0) , ε2 = (0, 1, 0) and ε3 = (0, 0, 1) of R . Let 3 τ End R be a linear endomorphism and aij be the i-th coordinate of τ(εi), then we∈ have       x a11 a12 a13 x τ y = a21 a22 a23 y · . z a31 a32 a33 z Our aim is to develop an equally convenient and uniform1 representation for all affine endomorphisms. In fact we will eventually be able to represent an even wider class of functions known as projective maps.

1. Projective space

In this section we introduce the notion of a projective space. Let n N be a fixed dimension (in practice we usually need n = 2 or n = 3). Define a relation∈  ∼ on the set Rn+1 (0,..., 0)T by the condition \ _ u v u = cv. ∼ ⇐⇒ c 0 ∈R\{ }

1If all the transforms are represented in the same, standardized, fashion, they can be easily implemented in a hardware (e.g. GPU).

Build: January 28, 2021 10 Homogeneous coordinates and affine transforms

In other words, two non-zero vectors are related if they are linearly dependent (i.e. they belong to the same through the origin). It is clear that is an . ∼

Definition 1.1. The set PnR of equivalence classes of (n + 1)-dimensional vectors with respect to the relation is called the n-dimensional projective space. T ∼ The class of a vector (x0, . . . , xn) is denoted by x0 : ... : xn . J K Of course, in the above definition one can substitute any arbitrary field (e.g. the rationals, the complex numbers,. . . ) in place of the reals and define respectively the rational projective space PnQ, the complex projective space PnC and so on. We won’t need them, however, till Chapter 6. Consider now the subset Ui of the projective space PnR consisting of all the (projective) points having non-zero i-th coordinate:  n Ui := x0 : ... : xn P R xi = 0 . J K ∈ | 6 Defining PnR we have excluded the null vector of Rn+1, consequently every pro- n Sn jective point has at least one non-zero coordinate. It follows that P R = i=0 Ui. n Observe that there is a bijection Ui R defined by the formula ↔ x x x x T x0 : ... : xi : ... : xn ( 0/xi,..., i−1/xi, i+1/xi,..., n/xi) . J K 7→ It allows us to identify Ui (for every 1 i n) with the affine n-dimensional space n n ≤ ≤ n R . The map Ui R is called a dehomogenization of Ui and its inverse R Ui → → is the homogenization of Rn. It is most convenient to use them for either the first or the last coordinate and the choice between these two cases is just a matter of taste. We will stick to the latter convention, where the maps have the forms: T homogenization : (x1, . . . , xn) x1 : ... : xn : 1 , 7→ Jx x K T dehomogenization : x0 : ... : xn 1 : xn ( 0/x1,..., n−1/xn) . J − K 7→ Let us characterize the completion of the affine space Rn in the projective space PnR. n Proposition 1.2. There is a canonical bijection between P R Un and the n 1 \ (n 1)-dimensional projective space P − R. −  Proof. By the very definition Un = x0 : ... : xn xn = 0 , hence its n J K | 6 completion P R Un consists of all the projective points of the form x0 : ... : \ J xn 1 : 0 . Of course some xi = 0 due to the way we have constructed the projective space.− DroppingK the last coordinate,6 which is constantly zero anyway, we arrive n 1 at P − R.  n 0 The set P R Un is called the set of points at infinity. Observe that P R consists \ of a single point by definition. Then, the projective line P1R decomposes into a sum of the affine line R1 and the unique point at infinity. Next, the projective P2R consists of the affine plane R2 and the line at infinity. Further, the projective 3-space P3R is just the affine 3-space R3 together with the plane at infinity, and so on. There are simple geometric models for these low-dimensional projective spaces. n The coordinates of a projective point x0 : ... : xn P R are unique only up to a multiplication by a non-zero factor.J Thus, normalizingK ∈ them, we may assume that x2 + + x2 = 1. Consequently, every projective point is represented by a 0 ··· n point of a n-dimensional unit Sn Rn+1. Unfortunately, there are two such points. These antipodal points P and ⊂P of a sphere map to the same point in − Build: January 28, 2021 Homogeneous coordinates and affine transforms 11

P P P Q P Q − P − Q Q Q − −

Q − P − Figure 1.1. Circle as a model of the projective line the projective space. Consequently, one constructs the projective space by gluing together antipodal points of the unit sphere. In particular, we may easily check that the P1R can be identified with a unit circle. Imagine a rubber loop representing a circle. Twist it into an “eight-shape” and fold it so that the two halves overlap, joining the points that were originally opposing each other (see Fig. 1.1). We get a circle again!

2. Homogeneous coordinates We will return to the projective space in the next chapter, but for the time being, let us concentrate on the affine space Rn, which we identify with the subset n T n Un P R. Every point P = (x1, . . . , xn) R can be assigned its projective co- ⊂ ∈ ordinates x1 : ... : xn : 1 . We call them homogeneous coordinates of P and write J T K [x1, . . . , xn, 1] . In what follows, we always use square brackets when working with homogeneous coordinates and parentheses when dealing with linear/affine coordi- T nates. The distinction between x0 : ... : xn and [x0, . . . , xn] is purely artificial for points, but will become importantJ once weK admit vectors into our discussion. A word of caution: the homogeneous coordinates of a point (x, y)T R2 in the ∈ plane are [xw, yw, w]T for any non-zero w R. Hence all: [x, y, 1]T, [2x, 2y, 2]T, [ 10.7x, 10.7y, 10.7]T,. . . refer to the same∈ point. Similarly, the homogeneous co- − − − T 3 T T ordinates of a point (x, y, z) R are [x, y, z, 1] as well as [x/3, y/3, z/3, 1/3] ,. . . and so on. ∈ The homogeneous coordinates are not unique! Usually, we try to work with “normalized” coordinates [x, y, z, 1]T , but the addi- tional freedom in choice of the weight w is sometimes important (see Chapter 4). As noted above, points have homogeneous coordinates [xw, yw, zw, w]T with weight w = 0. What about vectors? In the affine world, when translating a point P by6 a vector v, we simply add their coordinates component-wisely. This is a nice property, which we want to preserve in a homogeneous case. Take two points P , Q and let v be a vector satisfying Q = P + v. Let P = [x, y, z, 1]T and T Q = [x0, y0, z0, 1] . (i.e. we fix the weights of P and Q to be w = w0 = 1). Write the equation Q = P + v coordinate-wisely:       x0 x x0 x − y0 y y0 y Q =   =   +  −  = P + v. z0 z z0 z 1 1 0− Build: January 28, 2021 12 Homogeneous coordinates and affine transforms

Hence, vectors have coordinates [x, y, z, 0]T . Vectors in homogeneous coordi- nates have weight zero! More generally, we define a point-vector addition by the formula: x a x + aw y b y + bw   +   :=   z  c z + cw      . w 0 w Conversely, the difference of two points is a vector:     x 0 0 x x0 /w x /w y − 0 0 y  y0   /w y /w      = z − 0 0  z  − z0   /w z /w  − . w w0 0 Remark. Note the difference between x : y : z : 0 and [x, y, z, 0]T. The former is a point at infinity in the projectiveJ space P3R andK is the same as, let’s say, 2x : 2y : 2z : 0 . The latter is a vector in R3 and differs from [2x, 2y, 2z, 0]T , whichJ is again a vectorK but twice longer. The notion of homogeneous coordinates allows us to write all the affine endo- morphisms in a matrix form. Begin with a translation. 3 T Observation 2.1. A translation in R by a vector t = [tx, ty, tz, 0] can be expressed in homogeneous coordinates in the following way:       x 1 0 0 tx x y 0 1 0 ty y z 0 0 1 t  z   7→  z  ·  . 1 0 0 0 1 1

3 Observation 2.2. Let τ End R be a linear endomorphism and let aij be the ∈ i-th coordinate (with respect to the canonical basis) of τ(εj), then in homogeneous coordinates we write τ as       x a11 a12 a13 0 x y a21 a22 a23 0 y z a a a 0 z   7→  31 32 33  ·  . 1 0 0 0 1 1 Proposition 2.3. Let τ, σ be two geometric transformations with correspond- ing homogeneous matrices A and B, respectively. Then the composition τ σ is realized by matrix multiplication by a product A B. ◦ · We leave the proof to the reader. Recall that every affine endomorphism can be written as a composition of a translation with some linear map. Both have matrix representations by the previous two observations and it follows from the proposition that their composition is represented by a matrix multiplication, as well. Hence we proved: Corollary 2.4. Every affine map can be expressed as a matrix multiplication in homogeneous coordinates. In fact the class of all the functions defined by a matrix multiplication in homo- geneous coordinates is strictly wider than the class of affine endomorphisms. These are so called projective maps. We will refer to them later. For now, we shall only Build: January 28, 2021 Homogeneous coordinates and affine transforms 13 characterize these matrices that give rise to affine maps. Observe that due to the nature of homogeneous coordinates, we may multiply a matrix by a non-zero scalar without altering the transformation itself. Hence, we may always assume that the bottom-right entry of the matrix is either zero or one. Now, every affine map is a composition of a linear map with a translation. Examining what happens in the last row when multiplying the matrices from Observations 2.1 and 2.2, we arrive at the following conclusion:

Observation 2.5. Let τ : R3 R3 be a geometric transformation expressible → in a matrix notation as τ(P ) = MP for some matrix M = [mij] M4,4(R) with ∈ m44 = 1. Then τ is an affine endomorphism if and only if M has the form   m11 m12 m13 m14 m m m m M =  21 22 23 24 m m m m   31 32 33 34. 0 0 0 1 Below we present matrices of a few basic linear maps. Observation 2.6. The matrix (in homogeneous coordinates) of a non-uni- form scaling (dilatation) by factors s = (sx, sy, sz) in directions respectively OX, OY and OZ has the form   sx 0 0 0  0 sy 0 0 MS = s  0 0 s 0  z . 0 0 0 1 Consider now a rotation by an angle α around a given (directed) axis. By convention a positive angle refers to a rotation in a counter-clockwise direction when looking along the axis of the rotation coherently with its orientation (i.e. “looking from the minus infinity”). Rotations around the principal axes OX, OY , OZ have simple matrices. In what follows, by lin (v) we denote a directed line lin(v) spanned by v and with orientation inherited−→ from v. Proposition 2.7. The matrix of a rotation by an angle α around a principal axis lin (εi) has a form −→ 1 0 0 0  cos α 0 sin α 0 0 cos α sin α 0  0 1 0 0 MO = MO = ε1,α 0 sin α −cos α 0 ε2,α  sin α 0 cos α 0  ,  , 0 0 0 1 − 0 0 0 1 cos α sin α 0 0 sin α −cos α 0 0 MO =   ε3,α  0 0 1 0  . 0 0 0 1

2 Proof. First consider a rotation in the plane R . The basis vectors ε1 = 1 0 0 and ε2 = 1 are mapped to some vectors v1 = Oα(ε1) and v2 = Oα(ε2). Elementary trigonometry (see Figure 1.2) shows that cos α  sin α v = and v = − . 1 sin α 2 cos α Build: January 28, 2021 14 Homogeneous coordinates and affine transforms

v2 1

v1 α

α

1

Figure 1.2. Rotation in the plane R2.

Hence, the matrix of the rotation in linear coordinates equals: cos α sin α . sin α −cos α Switching to three dimensions and further to homogeneous coordinates, we arrive at the last matrix in the assertion. Consider now a rotation around ε . Permuting the basis so that ε ε 1 1 7→ 3 7→ ε2 ε1, rotating around ε3 and permuting back, we reduce the case to the one already7→ considered. In terms of a matrix multiplication we express this permutation as: 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 cos α sin α 0 MO = MO = ε1,α 0 1 0 0 ε3,α 1 0 0 0 0 sin α −cos α 0   · ·    . 0 0 0 1 0 0 0 1 0 0 0 1

One derives the last matrix MOε2,α in the same way, this time taking the permu- tation ε ε ε ε . 1 7→ 2 7→ 3 7→ 1  A rotation around an arbitrary axis id a bit more involving. Proposition 2.8. Let v = [x, y, z, 0]T be a vector of a unit length (i.e. x2 + y2 + z2 = 1). The matrix of a rotation around lin (v) by an angle α has a form −→  c + x2(1 c) xy(1 c) zs xz(1 c) + ys 0 xy(1 c)− + zs c + y−2(1 −c) yz(1 − c) xs 0 MO =   v,α xz(1 − c) ys yz(1 c)− + xs c + z−2(1 −c) 0  , −0− − 0 0− 1 where c = cos α and s = sin α.

Proof. If v lies on one of the principal axes OX, OY or OZ, then v = εi (for some 1 i 3) and the previous proposition yields the assertion. Thus,± without loss of generality,≤ ≤ we may assume that v does not lie on any of the principal axes. 1 We express the rotation O as a composition τ − R τ, where R is a rotation v,α ◦ ◦ around ε1 and τ is an isometry sending v to ε1. To this end consider an orthonormal basis v, u, w defined as follows: { } T T uˆ h z y i uˆ := ε1 v = [0, z, y, 0] , u := = 0, p , p , 0 × − uˆ − y2 + z2 y2 + z2 k k Build: January 28, 2021 Homogeneous coordinates and affine transforms 15 and h iT p 2 2 xy xz w := v u = y + z , p , p , 0 × − y2 + z2 − y2 + z2

Now, let τ map the basis v, u, w to the canonical basis ε1, ε2, ε3 . It follows that 1 { } { } T the matrix Mτ− of the inverse of τ has the columns v, u, w and [0, 0, 0, 1] .

p x 0 y2 + z2 0 z xy y 2 2 2 2 0 M 1 =  −√y +z −√y +z  τ− z y xz 0  √y2+z2 √y2+z2  − . 0 0 0 1

Both bases (v, u, w) and (ε1, ε2, ε3) are orthonormal, therefore τ is an isometry (in 1 T fact it is even a rotation), hence Mτ− = Mτ (we postpone the proof of this last property till Section 4). It follows that the matrix MOv,α of a rotation around v can be expressed as a product MO = M T MO M . Thus v,α τ · ε1,α · τ

 x 0 √y2+z2 0   1 0 0 0   x y z 0  y z xy 0 z 0 y 0 0 cos α sin α 0 2 2 2 2  − √y2+z2 − √y2+z2   −   − √y +z √y +z  MOv,α = y xz     xy xz  z 0 0 sin α cos α 0 √y2+z2 0  √y2+z2 − √y2+z2 · · − √y2+z2 − √y2+z2  0 0 0 1 0 0 0 1 0 0 0 1 .

Computing the product and making use of the assumption x2 + y2 + z2 = 1 one gets the desired formula. 

Another proof of the above proposition is presented in Section 4 of Chapter 2. Now, take a rotation Ov,α around lin (v) by an angle α. Clearly, the inverse of Ov,α is the rotation by α around lin−→(v) or equivalently the rotation by α around lin ( v). Hence, − −→ −→ − 1 T MOv,α− = MOv, α = MO v,α = MOv,α. − − Example. Above we have discussed only rotations around axes passing through the origin. A rotation around a general axis can be expressed as the translation of the axis to the origin, followed by the rotation around the shifted axis, followed finally by the inverse translation. Take for example the line L passing through the points P = [0, 1, 0, 1]T and Q = [1, 0, 1, 1]T , which clearly misses the origin. We wish to find the matrix of a rotation by an angle π/4 in CCW direction when look- ing along L from P towards Q. Denote byv ˆ the difference P Q = [1, 1, 1, 0]T . T − − Normalizing we have v = vˆ/ vˆ = [√3/3, √3/3, √3/3, 0] , hence k k −     0 √3/3 1  √3/3 L =   + lin −  0 √3/3    . 1 0 Build: January 28, 2021 16 Homogeneous coordinates and affine transforms

The translation by u = [0, 1, 0, 0]T shifts P to the origin and so the matrix of the rotation around lin (v) has− the form: −→

MOv,π/4 =       1 0 0 0 √2+1 √6+√2 2 √6 √2+2 1 0 0 0 3 − 6 − − −6 0 0 1 0 1  √6+√2 2 √2+1 √6+√2 2 0 0 1 0 1 =    6 − 3 − 6 −   −  = 0 0 1 0 ·  √6 √2+2 √6+√2 2 √2+1  · 0 0 1 0     −6 6 − 3 0   0 0 0 1 0 0 0 1 0 0 0 1  √2+1 √6+√2 2 √6 √2+2 √6+√2 2  − − − − − − 3 6 6 − 6  √6+√2 2 √2+1 √6+√2 2 1 √2+1  =  6 − 3 − 6 − 3   √6 √2+2 √6+√2 2 √2+1 √−6+√2 2   −6 6 − 3 6 − . 0 0 0− 1

Another important geometric transformation is a reflection with respect to a given plane. Let Π be a plane in R3 containing the origin and given by an equation ax + by + cz = 0. Write this equation using homogeneous coordinates:

a b (2.9) [x, y, z, 1]   = 0. · c 0

The vector v = [a, b, c, 0]T is perpendicular to Π. Without loss of generality, we may assume that it has a unit length (i.e. a2 + b2 + c2 = 1). Take a point T 3 P = [x, y, z, 1] R and let P 0 denote its orthogonal projection onto Π. Then ∈ P 0 = P + tv for some t R. The point P 0 lies on Π, hence its coordinates satisfy the equation (2.9): ∈ a b [x + ta, y + tb, z + tc, 1]   = 0. · c 0

Solve it for t to get:

a a  b  b t = t [a, b, c, 0]   = [x, y, z, 1]   c c · ·   − ·  . 0 0

Thus t is the dot product of −−→P Θ and v, namely t = −−→ΘP v. The reflection through Π maps the point P to P + 2tv. Consequently we− write• the reflection as:

x x a  (1 2a2)x 2aby 2acz  y y b 2abx− + (1 − 2b2)y− 2bcz     + 2t   =   z z c −2acx 2bcy− + (1 −2c2)z   7→      . 1 1 0 − − 1 − Build: January 28, 2021 Homogeneous coordinates and affine transforms 17

Corollary 2.10. Let [a, b, c, 0]T be the unit vector orthogonal to a plane Π ⊂ R3 passing through the origin. The matrix of the reflection through Π is 1 2a2 2ab 2ac 0 − − −  2ab 1 2b2 2bc 0 Mσ = Π  −2ac −2bc 1− 2c2 0  . −0− 0− 0 1 Corollary 2.11. The determinant of a reflection equals 1. − 3. Vectors and normals This section will be reworked In the previous section we learned how to map points, expressed in homoge- neous coordinates, by affine endomorphisms. Now, let’s see what happens if we map vectors rather than points. Observation 3.1. Let P,Q R3 be two points and v := Q P be a vector. ∈ − Further let M M4,4(R) be a matrix. Then Mv = MQ MP . ∈ − The conclusion from the above observation is that vectors are transformed by exactly the same formulas as points. Let us note one special case. Corollary 3.2. If M is a matrix of a translation and v = [x, y, z, 0]T is a vector, then M v = v. · The above corollary can be derived either directly from the preceding obser- vation or by the following simple geometric reasoning: if v = −−→PQ for some points P,Q R3 and T is a translation by a vector u, then T v = (P + u) (Q + u) = v. Geometric∈ objects, except the simplest ones, consist usually of− infinitely (or even uncountably) many points. But to manipulate them effectively, using e.g. computers that have only limited memory, we need to represent them by some finite sets of parameters (we understand the term quite broadly here). Typically, we would use finite sets of points and/or vectors. For example, a polyhedron can be represented by a finite set of its faces, where each face (a polygon) is in turn represented by finitely many vertices (more on polyhedra representations may be found in Chapter 7). Denote by (X) the class of all the subsets of X and by Fin(X) the class of all the finite subsets.P The finite representation of a geometric object can, thus, be treated as a function : Fin(R3) (R3). F → P Definition 3.3. The representation : Fin(R3) (R3) is affinely invariant, 3 F → P if for every finite set P1,...,Pn R and every affine endomorphism T one has { } ⊂ T ( P ,...,P ) = TP ,...,TP . F { 1 n} F { 1 n} The representation is projectively invariant, if the above holds for every projective map T . F In a nutshell, to transform an object represented in affinely (resp. projectively) invariant way, all we need to do is to transform the points that define it. As a simple example, take a triangle represented by its three vertices. In order to find the image of this triangle under an affine map, it suffices to transform the vertices and reconstruct a triangle from their images. Most of the time we will be interested only in these representations of geometric object that are at least affinely invariant. There is however one exception. Build: January 28, 2021 18 Homogeneous coordinates and affine transforms

Figure 1.3. Transformations of a normal and the vector repre- senting it may differ.

A normal 2 is an orthogonal pair of unit vectors (u, v), this means that u v and u = v = 1. A normal N = (u, v) may be represented by the cross product⊥ u v. Itk isk worthk k to emphasize the fact that, while normals are represented by vectors, they× are not vectors themselves. They obey a different set of rules, in particular we will see that the representation of a normal by a vector is not affinely invariant. Normals are used in 3D computer graphics for object shading. Interpolating normals across the edge between two faces of a polyhedron can create an illusion of a smooth shape. Local transformations of normals (so called bump mapping and normal mapping) are used to simulate tiny details or a surface texture. Let N = (u, v) be a normal represented by the cross-product n = u v. × Consider a matrix M = M4,4(R). In general, after applying a transformation, the vector Mn is no longer orthogonal to lin(Mu, Mv) as it can be observed for example in Figure 1.3. This means that normals need to be treated differently than points and vectors. Recall that every affine transformation is a composition of a linear endomorphism with a translation. As we know (see Corollary 3.2) the translation does not alter vectors. Hence, clearly, it should not change the normal. But what about the linear part? Suppose that M is a matrix of a linear endomorphism. By its construction n is orthogonal to both u and v, hence n u = n v = 0. Denote • • u0 := Mu, v0 := Mv. The vector n0 representing the image of the normal N must be orthogonal to both u0 and v0 so that n0 u0 = 0 = n0 v0. We would like to • • express it as n0 = M 0n for some matrix M 0 and so T T T 0 = n0 u0 = (M 0 n) (M u) = n (M 0 M) u, • · · · · · T T T 0 = n0 v0 = (M 0 n) (M v) = n (M 0 M) v. • · · · · · If M is invertible, then u0, v0 are linearly independent, since u, v are orthogonal. Hence, the direction orthogonal to lin(u0, v0) is uniquely determined. It follows from 1 T the above equations that (M − ) n is orthogonal to both u0 and v0. Thus we can take · 1 T M 0 = k (M − ) , · for some scalar k R selected in such a way that n0 = 1. ∈ k k

2In some books, normals are called “normal vectors”. This may suggest that they are vectors of a special kind. But they are not. Hence we use the term “normal”. In the language of Clifford algebras, normals are bivectors.

Build: January 28, 2021 Homogeneous coordinates and affine transforms 19

Corollary 3.4. Let M M4,4(R) be a matrix of a linear (in homogeneous coordinates). If∈ a normal N is represented by a vector n, then (up to a scalar multiplication), the image N 0 of N under this automorphism is represented 1 T by n0 = (M − ) n. · Given a linear automorphism ϕ Aut R3 of the space R3 with the associated ∈ 1 T matrix M, we define its dual automorphism by the formula v (M − ) v. Hence the previous corollary can be rephrased as: 7→

Corollary 3.5. Up to a scalar multiplication, normals are transformed by the automorphism dual to the one used to transform vectors.

4. Isometries Isometry preserves length In this section we discuss a special class of linear maps that preserve lengths and angles. Such functions are called isometries. As we will see, one of the special properties of isometries is that they treat vectors and normals uniformly. We begin with the following basic lemma.

Lemma 4.1. The composition of two reflections in R2 with respect to two non- parallel lines is the rotation around the intersection point of these two lines by the double angle between them.

Proof. Without loss of generality, we may assume that the two lines intersect at the origin. Let u, v be two unit vectors spanning these lines and denote σu (respectively σv) the reflection across lin(u) (resp. lin(v)). A composition σv σu is a linear map. Hence, in order to prove the lemma, it suffices to show that◦ this composition act as a rotation on an arbitrary basis of R2. The natural choice is the basis consisting of u and v. Rotate u and v by π/2 and denote the resulting vectors u0 and v0, respectively. Decompose the vectors u and u0 (see Figure 1.4) into

u = u + u , u0 = u0 + u0 , k ⊥ k ⊥ where u , u0 are parallel to v and u , u0 are orthogonal to v (hence parallel to k k ⊥ ⊥ v0). Similarly, write v, v0 as

v = v + v , v0 = v0 + v0 , k ⊥ k ⊥ with v , v0 parallel to u and v , v0 orthogonal to u (and parallel to u0). Elementary k ⊥ trigonometryk tells us how to express⊥ the parallel and orthogonal parts in terms of the sine and cosine of α:

u = v cos α, u = v0 sin α, u0 = v sin α, u0 = v0 cos α, k ⊥ − k ⊥ v = u cos α, v = u0 sin α, v0 = u sin α, v0 = u0 cos α. k ⊥ k − ⊥ Now the reflection reverses the orthogonal part, leaving the parallel one intact, hence

σu(v) = v v , σu(v0) = v0 v0 , σv(u) = u u , σv(u0) = u0 u0 . k − ⊥ k − ⊥ k − ⊥ k − ⊥ Build: January 28, 2021 20 Homogeneous coordinates and affine transforms

u0 u0 v v

v0 u v k v0 v0 ⊥ ⊥ u0 k α u u0 v ⊥ α u k

u v0 ⊥ k

Figure 1.4. Orthogonal and parallel components of u and v.

Compute the image of the first basis vector under the composition σ σ : v ◦ u

(σv σu)(v) = σv(v v ) = ◦ k − ⊥ = σv(u cos α u0 sin α) = (u u ) cos α (u0 u0 ) sin α = − k − ⊥ − k − ⊥ 2 2 = (v cos α + v0 sin α cos α) (v sin α v0 sin α cos α) = − − = v cos(2α) + v0 sin(2α) = O2α(v). Similarly for the second vector:

(σv σu)(u) = σv(u) = u u = ◦ k − ⊥ = v cos α + v0 sin α = (v + v ) cos α + (v0 + v0 ) sin α = k ⊥ k ⊥ 2 2 = u cos α + u0 sin α cos α u sin α + u0 sin α cos α = − = u cos(2α) + u0 sin(2α) = O2α(u).

Now, since σv σu is linear, it follows that for every vector w = xu + yv one has (σ σ )(w) =◦xO (u) + yO (v) = O (w) as desired. v ◦ u 2α 2α 2α  3 Switching to three dimensions, let Π1, Π2 R be two distinct and non-parallel planes. Translating back and forth, without loss⊂ of generality we may assume that the intersection Π Π contains the origin and is spanned by some vector v (i.e. 1 ∩ 2 lin(v) = Π1 Π2). Let α be the (directed) angle between Π1 and Π2 and σ1, σ2 ∩ 3 be the reflections in R through Π1 and Π2, respectively. Take Π to be the plane ⊥ orthogonal to v and passing through the origin. An arbitrary vector w R2 can ∈ be expressed as a sum w = w + w with w lin(v) and w Π . Neither σ1 k ⊥ k ∈ ⊥ ∈ ⊥ nor σ2 alters the parallel part w of w since it belongs to both Π1 and Π2. On the k other hand, w lies in Π and the restrictions σ1 Π⊥ , σ2 Π⊥ are just the reflections ⊥ ⊥ | | through two lines in a plane. The previous lemma asserts that (σ1 σ2) Π⊥ is a rotation by 2α. It follows that σ σ is a rotation by 2α around v. ◦ | 1 ◦ 2 Corollary 4.2. The composition of two reflections through non-parallel planes gives the rotation around their intersection by the double angle between them. The determinant of a reflection equals 1 by Corollary 2.11. A rotation is a composition of two reflections therefore: − Corollary 4.3. The determinant of a rotation equals 1. Build: January 28, 2021 Homogeneous coordinates and affine transforms 21

Recall that a linear automorphism τ Aut(Rn) is called a linear isometry if ∈ it preserves the dot product in the sense that for every two vectors u, v R one has u v = τ(u) τ(v). In particular a linear isometry preserves norms (lengths)∈ of vectors• as well as• measures of angles, since both these quantities can be expressed in terms of the dot product. An (affine) isometry is a composition of a linear isometry with a translation. An affine isometry preserves distances between points. Theorem 4.4 (Cartan, Dieudonn´e). Every linear isometry (different from identity) of Rn is a composition of n hyperplane reflections. ≤ The proof of this theorem exceeds the scope of this book. An interested reader is referred to [16, Theorem I.7.1]. It follows from the theorem that there are only three types of linear isometries in R3. These are: reflections, rotations (i.e. compositions of two reflections) and compositions of a rotation with a reflection. If we consider a composition of two rotations, then clearly it is an isometry. Its determinant equals 1, hence it must be a composition of an even number of reflections. It follows from the Cartan-Dieudonn´etheorem, that it is a composition of just two reflections, hence a rotation again. Moreover, the inverse of a rotation is also a rotation. Therefore we proved: Theorem 4.5 (Euler). Rotations form a group. Our next goal is to show that every rotation can be expressed as a composition of just three rotations around vectors from an arbitrary orthogonal basis of R3. To this end, fix an orthogonal basis u, v, w . Without loss of generality, we may assume that all these vectors have unit{ lengths.} Let R be an arbitrary rotation by an angle α around some vector ν R3. Denote the images of the basis vectors by ∈ u0 := R(u), v0 := R(v) and w0 := R(w). Assume that u and w0 are not linearly dependent (if they are, just take another pair). Thus, there is a rotation Ou around u that takes w0 into the plane lin(u, w). Next, rotating around v, we map Ou(w0) to w. Denote this rotation by Ov. Now, u0 and v0 are perpendicular to w0, hence their images lie in lin(u, v). Thus one can find a rotation Ow around w, sending 1 them to u and v, respectively. Consequently, we have O O O = R− and so w ◦ v ◦ u 1 1 1 R = O− O− O− , u ◦ v ◦ w as required. Therefore with a fixed orthogonal basis, every rotation can be expressed as an ordered triple of angles. These are known as the Euler’s angles. 3 3 Take a linear isometry τ : R R . The canonical basis ε1, ε2, ε3 is or- thonormal, which means that → { } ( 1, if i = j εi εj = • 0, if i = j. 6 An isometry preserves dot products, hence ( 1, if i = j τ(εi) τ(εj) = • 0, if i = j, 6  Thus, τ(ε1), τ(ε2), τ(ε3) is an orthonormal basis, as well. The matrix M of τ (in linear coordinates) has a form   M = τ(ε1) τ(ε2) τ(ε3) .

Build: January 28, 2021 22 Homogeneous coordinates and affine transforms

Compute the product M T M. The entry in the i’th row and j’th column equals τ(ε )T τ(ε ) = τ(ε ) τ(·ε ). It follows that M T M is the unit matrix. The i · j i • j matrices satisfying the condition M T M = I (or equivalently MM T = I) are called orthogonal. Observe that a geometric transform having an orthogonal matrix treats T T 1 vectors and normals uniformly, since if M M = I, then (M )− = M. In other words: every isometry equals its own dual. The orthogonality is preserved once we switch to homogeneous coordinates as T M 0 M 0 M T 0 M 0 M T M 0 = = · = I. 0 1 · 0 1 0 1 · 0 1 0 1 Observation 4.6. The matrix of a linear isometry is orthogonal Observation 4.7. The determinant of an isometry equals 1. ± The last observation follows either immediately from the Cartan-Dieudonn´e theorem or equivalently from Observation 4.6, since the determinant of an orthog- onal matrix satisfy: 1 = det I = det(M T M) = (det M)2. Hence det M = 1. We may summarize the above results in a convenient criterion testing weather± a given matrix represents a rotation.

Theorem 4.8. A matrix M M3,3(R) represents a rotation if and only if ∈ M T M = I and det M = 1. Usually, after verifying that a given matrix represents a rotation, we wish to find its axis and angle. The axis is fixed by the rotation, hence it is spanned by an eigenvector corresponding to the eigenvalue 1.

Observation 4.9. If M M3,3(R) represents a rotation, then it has an eigen- value 1 and the corresponding∈ eigenvector generates the axis of the rotation. Although it is possible to find the axis using the previous observation, there exists a more direct and far simpler approach. Examining the matrix presented in Proposition 2.8, we arrive at the following conclusion: Observation 4.10. If M is a matrix (in homogeneous coordinates) of a rota- tion by an angle α around a unit vector v = [x, y, z, 0]T , then the trace of M equals Tr M = 2 + 2 cos α and  0 2z sin α 2y sin α 0 −  2z sin α 0 2x sin α 0 M M T =  2y sin α 2x sin α − 0 0 −  . − 0 0 0 0 Thus, the angle of the rotation may be retrieved from the trace. Once we know the angle, we recover the coordinates of the vector spanning the axis of the rotation from the difference M M T . − Example. Consider a matrix M written (in linear coordinates) as 0.78 0.46 0.43 − − M = 0.25 0.85 0.46  . 0.57 0.25− 0.78 Build: January 28, 2021 Homogeneous coordinates and affine transforms 23

A direct computation shows that M T M I and det M 1. Hence, M represents a rotation. The trace Tr M of M equals 2≈.41 and so the≈ angle of rotation is Tr M 1 π α = arccos − 0.79 . 2 ≈ ≈ 4 To find the axis, compute the difference between M and its transpose. We have 0.00 0.71 1.0  − − M M T 0.71 0.00 0.71  . − ≈ 1.00 0.71− 0.00 It follows that 0.5 0.71 1 0.5 1.0 √2 0.5 0.71 1 x · , y · , z · . ≈ sin α ≈ 2 ≈ − sin α ≈ − 2 ≈ sin α ≈ 2 T All in all, M is the matrix of the rotation by π/4 around lin(1/2, √2/2, 1/2) . − 5. Transformation decomposition In the previous sections we encountered the matrices of some commonly used affine maps and we saw how the composition of geometric transformations translates to the multiplication of the associated matrices. In this section we partially revert this operation. Our goal is to decompose a given endomorphism (matrix) to a product of elementary transformations (matrices). The main application is an interpolation of transformations as a function of time, used in computer animation. We discuss this subject in Section 4 of the next chapter and Section 1 of Chapter 5. As we will see, these are the rotations that require a special treatment during the interpolation. Thus, our goal is to split-off the rotation from a given transform. In general, given a composite endomorphism T one can express it as a product Tn T1 of elementary transformations in more than one way. In fact in infinitely many◦· · ·◦ways! Therefore, it is impossible to decompose a product T = T T n ◦ · · · ◦ 1 into its factors T1,...,Tn, knowing only the matrix of T . Nevertheless, it is still possible to find some decomposition of T , which is convenient for an interpolation and somehow coherent with human vision (see the discussion in [22]). Suppose that we are given the matrix of some affine endomorphism expressed in homogeneous coordinates as   m11 m12 m13 m14 m m m m M =  21 22 23 24 m m m m   31 32 33 34. 0 0 0 1 We can write it as a product     1 0 0 m14 m11 m12 m13 0 0 1 0 m m m m 0 M =  24  21 22 23  0 0 1 m  m m m 0  34 ·  31 32 33 . 0 0 0 1 0 0 0 1 Here, the first term is the matrix of a translation, while the second one represents a linear map. Now, after isolating the linear part, we concentrate on splitting-off the rotation. We do it by a polar decomposition. To this end, we first recall the notion of a singular value decomposition (SVD in short), which is well known in the realm of a numerical analysis. Build: January 28, 2021 24 Homogeneous coordinates and affine transforms

Theorem 5.1. If M GLn(R) is an invertible matrix, then there are ortho- gonal matrices U, V and a∈ diagonal matrix D such that M = U D V T . · · We omit the proof, referring the reader to [6]. Take now an invertible matrix T M GL3(R). Using SVD, we write it as a product M = U D V . Denote ∈ T T · · T 1 Q(M) := U V and S := V D V . Now, V is orthogonal, hence V = V − . Further, D is· diagonal, so it is· a matrix· of a non-uniform scaling (with respect to T 1 the canonical basis). Therefore, the composition S = V D V = V D V − represents a stretching, i.e. a non-uniform scaling with respect· to· some orthonormal· · basis (namely the basis consisting of the columns of V ). On the other hand, Q(M) is a product of orthogonal matrices, hence it is orthogonal itself. Consequently, we can write M in the form: M = U D V T = (U V T ) (V D V T ) = Q(M) S. · · · · · · · This is called a polar decomposition of M. Unfortunately, all we know is that Q(M) is orthogonal. It does not have to represent a rotation since it may have a negative determinant. If this is the case we need to alter S (we are lucky, that we are working in an odd-dimensional space R3).

Corollary 5.2. Let M M3,3(R) be a matrix of a linear automorphism of ∈ the space R3. Then M admits a decomposition M = R ( S), · ± where R = Q(M) represents a rotation and S a stretching. ± Robust numerical algorithms for SVD can be found in the literature on numer- ical analysis. Any of them can be used to find the above decomposition. There is however a direct recursive algorithm for the polar decomposition of an invertible matrix. In order to present it, we need to introduce a norm in the space of matrices, giving a meaning to the notion of the limit of a sequence of matrices.

Definition 5.3. The Frobenius norm of a matrix A = [aij] Mn,n(R) is defined by the formula ∈ s X A := a2 . k k ij 1 i,j n ≤ ≤

Take now an invertible matrix M M3,3(R) and define a sequence (Qi i N0) ∈ | ∈ of matrices in a recursive manner, starting from Q0 := M and setting

1 1 T  Q := Q + (Q− ) . i+1 2 i i Readers familiar with numerical methods will easily recognize that it is a matrix analog of an algorithm, due to Heron of Alexandria, for finding a square root.

Theorem 5.4. The sequence (Qi i N0) is well defined (providing that M is | ∈ invertible) and converges to Q(M) = lim Qi. i →∞ Example. Consider the following matrix 2.34 0.48 0.36 − − M := 0.75 1.69 0.94 1.72 0.10− 0.87 Build: January 28, 2021 Homogeneous coordinates and affine transforms 25

Compute the limit of the sequence (Qi i N0) defined above to get | ∈ 0.78 0.46 0.43 − − Q(M) = lim Qi = 0.25 0.85 0.46 i − . →∞ 0.57 0.25 0.78 As we remember from the previous section, Q(M) represents a rotation. Find S writing 2.25 0.21 0.93 S = M Q 1 = M QT = 0.21 2.06 0.12 −  . · · 0.93 0.12 1.69 Implementation notes

Missing

Exercises (1) Prove Corollary 4.2 using the matrix forms of a rotation and a reflection. (2) Give a direct proof of Corollary 4.3. (3) Check that the set of orthogonal 3 3 matrices forms a group under multiplication. Show that this group× is isomorphic to the group of linear isometries (with composition). (4) Does Observation 4.6 remain true for affine isometries? (5) Let M GL3(R) be the matrix of a rotation. By Observation 4.9 it has an eigenvalue∈ 1. Show that it has no other real eigenvalues. Show that it has exactly two complex eigenvalues. Give a geometric interpretation of these eigenvalues. Bibliographic notes Projective spaces sometimes appear in more advanced courses of linear alge- bra and geometry. For example [15] gives a smooth introduction to projective geometry. Computer graphics uses the homogeneous coordinates from its very be- ginning. Matrix representation of affine transforms is discussed in classical sources like [8]. More rigorous (from mathematical viewpoint) treatise can be found in the unpublished book [7]. There is also an alternative approach to introducing homogeneous coordinates to computer graphics, which uses Grassmann spaces. We refer the reader to [10] for details. On the other hand, a reader interested in a more-in-depth discussion of isometries is full-heartedly encouraged to look into the literature on bilinear algebra like [16, 26]. In particular, [16] contains a detailed proof of Cartan-Dieudonn´etheorem. Matrix decomposition is a classical subject of numerical analysis. The singular value decomposition is discussed for example in [6], where the reader can find a complete proof of Theorem 5.1. The idea to use polar decomposition in this context and Theorem 5.4 comes from [22].

Build: January 28, 2021

CHAPTER 2

Projective space and quaternions

“Positing infinity, the rest is easy.” — R. Zelazny

“Infinity itself looks flat and uninteresting.” — D. Adams In this chapter we discuss a few more advanced subjects. The first three sections provide the reader with a glimpse of projective geometry. In Section 1 we show how to construct a projective transformation that sends a set of n+2 points in a general position1 to another n + 2 points in a general position. We use this construction in the following section to define a perspective projection. Next, in Section 3 we show how to uniformly assign coordinates to points, lines and planes in the three- dimensional space and how to use these coordinates to check a relative position of two objects (e.g. line-line or line-triangle intersections). In the previous chapter we saw that all the affine transformations may be repre- sented by matrix multiplication. However, for rotations there is a more convenient representation, which is better suited for an interpolation (animation). This is the subject of the last section.

1. Projective maps Recall that on the beginning of the first chapter, we defined a projective space and the projective/homogeneous coordinates. In this section we show how to define a map on a projective space preserving its structure and how to design a projective map with desired properties. First, however, we need to introduce projective sub- spaces. As we know, the projective coordinates of a point in PnR are not unique. Two (n+1)-tuples correspond to the same point when they differ by a non-zero mul- tiplicative factor. Hence, the only linear equations that make sense in a projective space are of the form:

a x + a x + + a x = 0, 0 0 1 1 ··· n n since they are not fragile to multiplication by non-zero scalars. They are called homogeneous (linear) equations. A projective subspace is just the set of zeros of a system of homogeneous linear equations. Strictly speaking:

1A “general position” is an euphemism that geometers use to mean “the points satisfy what- ever assumptions we need, but we don’t want to spend time on them here”.

Build: January 28, 2021 28 Projective space and quaternions

Definition 1.1. Let M = [mij] be a matrix with n + 1 columns and d linearly independent rows. The set n n T o V = x0 : ... : xn P R M x0 : ... : xn = Θ J K ∈ | · J K is a (n d) dimensional projective subspace of PnR defined by M. − By convention a 1-dimensional projective subspace is called a (projective) line and a 2-dimensional subspace is a (projective) plane. Thus a line in the P2R is the set of projective points x : y : w satisfying an equation ax + by + cw = 0 for some a, b, c not all equal zero.J The coefficientsK a, b, c defining the line are unique only up to a multiplication by a non-zero scalar exactly like the coordinates of a projective point. We will investigate this analogy in Section 3. Likewise an equation ax + by + cz + dw = 0 defines a plane in the projective space P3R, while a line in P3R is given by a system of two simultaneous linear equations: ( a1x + b1y + c1z + d1w = 0,

a2x + b2y + c2z + d2w = 0. Every affine subspace of Rn extends uniquely to a projective subspace of PnR by adjoining the point(s) at infinity corresponding to all the directions of the lines contained in this subspace. Take for example an affine line l R2 defined by the equation ax + by + c = 0. Homogenizing2 the equation we get⊂ ax + by + cw = 0. This defines a projective line L. One checks that L l consists of a single point at infinity, namely b : a : 0 . Observe that this point\ does not depend on c, hence it is the same forJ− every translationK of l. The projective subspaces have one striking property. Take two affine lines in the plane R2. If they are not parallel, then they intersect already in the affine plane, hence also in the projective plane. But if they are parallel, they do not intersect in R2. Nevertheless, when extending to the projective lines, we adjoin to both of them the same point at infinity, since being parallel they have the same direction. Consequently, they do intersect in the projective plane P2R. Observation 1.2. Every two lines in the projective plane intersect. After the above apparent digression we can concentrate on the main subject of this section: projective maps. Recall that in Chapter 1 we defined an equivalence relation on Rn+1 saying that two vectors are related when they are linearly dependent.∼ n+1 Lemma 1.3. Let M Mn+1,n+1(R) be a matrix and u, v R two vectors. If u v, then Mu Mv∈. ∈ ∼ ∼ Proof. If u and v are related, then there is a non-zero scalar c R satisfying ∈ u = cv, hence Mu = c(Mv).  In a fancier language, the above lemma says that every linear endomorphism of Rn+1 factors through . ∼ n Definition 1.4. Let M GLn+1(R) be an invertible matrix. The map P R ∈ → PnR defined as P M P is called the projective automorphism of PnR associated with M. 7→ ·

2In this case, by “homogenization” we mean the multiplication of the constant term by the new variable w. For a general notion of a homogenization, refer to Chapter 6.

Build: January 28, 2021 Projective space and quaternions 29

Thus, the projective are just the linear automorphisms (in one more dimension) factored through the relation . The reason we begin with au- tomorphisms is that a non-invertible (linear) endomorphism∼ have the non-trivial kernel. Therefore, if M Mn+1,n+1(R) is a non-invertible matrix, then there are vectors mapped to the origin∈ when multiplied by M. But the origin was explicitly excluded in the definition of a projective space. There are no projective points with all-zero coordinates! This brings us back to the projective subspaces intro- duced above—the points where the multiplication by M fails to give a proper results form a subspace which we need to omit, when defining a general projective map.

Definition 1.5. Let M Mn+1,n+1(R) be a non-zero matrix and V be the ∈ associated subspace. The map PnR V PnR defined by the formula P M P \ → 7→ · is called the projective endomorphism of PnR associated with M. It follows that the projective automorphisms are distinguished among projective endomorphisms not only by the fact that they are invertible but also that they are the only endomorphisms defined on the entire projective space PnR. Example. Consider the projective automorphisms τ : P2R P2R associated with a matrix → u4 0 0} 0 8 0 . v0 1 4~ Take the following four points: A = 2 : 0 : 1 ,B = 2 : 4 : 1 ,C = 2 : 0 : 1 ,D = 2 : 4 : 1 . J− K J− K J K J K The line passing through A and B is parallel to the line passing through C and D. Compute their images under τ:

A0 := τ(A) = 2 : 0 : 1 = A, B0 := τ(B) = 1 : 4 : 1 , J− K J− K C0 := τ(C) = 2 : 0 : 1 = C,D0 := τ(D) = 1 : 4 : 1 . J K J K Now, the lines passing through A0 and B0, respectively C0 and D0, are no longer parallel (see Figure 2.1). Thus τ is definitely not affine (this can also be observed by just looking at the last row of the matrix). In fact the two lines intersect at the point E = 0 : 8 : 1 , while the original lines, being parallel, intersect at the point at infinity J0 : 1 : 0K . Thus τ maps a point at infinity to the point E at a finite distance etJ vice versa—theK point 0 : 4 : 1 is sent to infinity. J − K An important lesson from the above example is that, although projective mor- phisms preserve co-linearity, they do not need to preserve parallelism. Now, we should learn how to to design a projective map bending a space to our wish. To this end we need the following definition. n Definition 1.6. Points P1,P2,...,Pn+2 P R are in a general position, if no proper projective subspace contains n + 1 of them.∈ n Take two sets of projective points P1,...,Pn+2 P R and Q1,...,Qn+2 ∈ ∈ PnR both in general positions. Our goal is to construct a projective isomor- n n phism τ : P R P R sending Pi to Qi for every 1 i n + 2. Fix vectors → n+1 ≤ ≤ u1, . . . , un+2, v1, . . . , vn+2 R in the (n + 1)-dimensional space in such a way that the ∈ of u (with respect to the relation defined in Chap- i ∼ ter 1) is Pi and the class of vi equals Qi. Points P1,...,Pn+2 are in general position, Build: January 28, 2021 30 Projective space and quaternions

B D B D 0 0

A C A0 C0

Figure 2.1. A projective map may fail to preserve parallelism.

hence vectors u1, . . . , un+1 are linearly independent. Thus, they form a basis of the space Rn+1. Consequently the matrix  A = u1, . . . , un+1 1 is invertible (as usually, vectors are written as columns). Its inverse A− sends n+1 u1, . . . , un+1 onto the canonical basis ε1, . . . , εn+1 R . Similarly, the vectors { } ⊂ v1, . . . , vn+1 form another basis; writing them side-by-side we construct another matrix  B = v1, . . . , vn+1 1 which again is invertible. The product B A− maps the basis u1, . . . , un+1 · n { } to v1, . . . , vn+1 . Therefore, in the projective space P R the multiplication by { 1 } B A− transforms P ,...,P to Q ,...,Q . But this still leaves us with the · 1 n+1 1 n+1 unmatched pair Pn+2 and Qn+2! Fortunately, we have one more degree of freedom introduced by the relation . Write the vector u as the linear combination of ∼ n+2 its peers u1, . . . , un+1: n+1 X un+2 = αiui. i=1

Do the same with vn+2: n+1 X vn+2 = βivi. i=1

Now, observe that the assumption that the points P1,...,Pn+2 are in a general po- sition implies that all αi’s are non-zero. Indeed, if some αi = 0, then un+2 belongs to the hyperplane lin(u1, . . . , ui 1, ui+1, . . . , un+1) spanned by all the vectors ex- − cept ui. Consequently P1,...,Pi 1,Pi+1,...,Pn+1,Pn+2 lies in a common proper − β subspace—contrary to the assumption. Define γi = i/αi for every 1 i n+1 and ≤ ≤ 1 let Γ denote the diagonal matrix with entries γ1, . . . , γn+1. Take M := B Γ A− , then for every 1 i n + 1 we have · · ≤ ≤ Mu = B Γ (Av ) = B (Γε ) = γ (Bε ) = γ v v i · · i · i i · i i i ∼ i and for the last vector: n+1 ! n+1  1 X X Mu = BΓA− α u = α γ v = v . n+2 · i i i i i n+1 i=1 i=1 Build: January 28, 2021 Projective space and quaternions 31

n It follows that the multiplication by M is an automorphism of P R sending every Pi to the corresponding point Qi. Therefore we have proved the following important theorem:

Theorem 1.7. If P ,...,P and Q ,...,Q are two sets of points in { 1 n+2} { 1 n+2} the projective space PnR, both in general positions, then there is such an automor- n phism τ of P R that τ(Pi) = Qi for every 1 i n + 2. ≤ ≤ The class of projective maps is quite broad, if we consider affine maps, instead, which are not so generic, we are free to choose only n + 1 points in general position (in affine world, this term means that they don’t all belong to a common proper subspace, or in the other words that they span the whole space). Moreover, if we consider linear maps only, we need to drop yet one more degree of freedom.

Proposition 1.8. Let P1,...,Pn+1 and Q1,...,Qn+1 be two sets of points n+1 { } { } in the affine space R and assume that P1,...,Pn+1 do not belong to any common n n proper affine subspace. Then there is an affine map τ : R R satisfying τ(Pi) = Q for every 1 i n + 1. → i ≤ ≤ If, in addition, Q1,...,Qn+1 do not belong to any common proper subspace of Rn, either, then τ is an affine automorphism.

Proposition 1.9. Let u1, . . . , un and v1, . . . , vn be two sets of vectors in n { } { } the linear space R and assume that u1, . . . , un are linearly independent. Then there n n is a linear map τ : R R satisfying τ(ui) = vi for every 1 i n. → ≤ ≤ If in addition, v1, . . . , vn are linearly independent, too, then τ is a linear auto- morphism.

The latter of these two propositions is a standard result taught at every ele- mentary course of linear algebra. We recalled it only to emphasize the connection with Theorem 1.7. The proof of the theorem can be easily adapted to show any of these two propositions. We leave the details to the reader.

Remark. General projective maps of the plane are often used in photo-editing software for a perspective correction. The interface is usually designed in such a way that a user may freely move the four corners of an image distorting the picture accordingly. This is just a straightforward implementation of Theorem 1.7.

Example. Suppose we are given a photo, taken with a camera tilted upward (see Figure 2.10). It exhibits an undesirable perspective distortion. Assume that the picture coordinates were normalized so that it occupies the unit square [0, 1] [0, 1]. Pick two line segment in the photo, that are vertical in reality and denote× their endpoints by P1,...,P4. Say

0.092 0.162 0.722 0.771 P = ,P = ,P = ,P = . 1 0.049 2 0.54 3 0.54 4 0.049

In order to correct the distortion, we are going to map the above points to

0.092 0.092 0.771 0.7771 Q = ,Q = ,Q = ,Q = . 1 0.029 2 0.45 3 0.45 4 0.029 Build: January 28, 2021 32 Projective space and quaternions

To this end, we build the three matrices A, B and Γ as explained above. We have

u0.092 0.162 0.722} u0.092 0.092 0.771} A = 0.049 0.54 0.54 B = 0.029 0.45 0.45 , , v 1.0 1.0 1.0 ~ v 1.0 1.0 1.0 ~ u1.0 0.0 0.0 } Γ = 0.0 0.825 0.0 . v0.0 0.0 0.825~

Thus, the matrix of the sought projective map is

u1.0 0.175 0.009 } u0.983 0.172 0.008 } − − M = B Γ A 1 = 0.0 0.697 0.005 0.0 0.685 0.005 − . · · v0.0 0.357− 1.017 ~ ∼ v 0.0 0.351− 1.0 ~ − − The bottom of Figure 2.10 illustrates the effect of applying this transformation to the original picture.

2. Projections and perspective In computer graphics, the ultimate result of one’s work is (most of the time) a flat picture—even though it may have been designed using three dimensional tools. This is, of course, caused by the presentation technology—an image printed on a paper or displayed on computer screen is as flat as the medium used. Nevertheless, it still should make an impression of having depth. Over centuries, artists, mostly painters, developed a number of tricks used to simulate depth of a scene. These include: making distant objects smaller with one-point, two-point or three-point perspective projection, blurring a background to simulate an out-of-focus image and painting distant objects dimmed and hazed. In this section we concentrate on the first of these techniques (i.e. perspective projection) as it is a strictly geometric subject. The simplest way to project a three-dimensional scene onto a flat viewport is just to drop one coordinate. Assume that we look at a scene in R3 along the OZ axis. The orthogonal projection R3 R3 sends (x, y, z)T (x, y)T . Observe that in this case only the direction of→ the projection matters,7→ the distance from the observer is unimportant. Later we will see that the orthogonal projection is a limit case of a perspective projections, when the focal length approaches infinity. In practice, the size of the viewport is limited by the medium used for the presentation (e.g. a computer screen). Without loss of generality we may assume the viewport to be a square [ 1, 1] [ 1, 1] R2. Thus in order to correctly display a scene not − × − ⊂ contained inside [ 1, 1] [ 1, 1] R or viewed from a direction other than OZ, we must first transform− it appropriately.× − ×

Example. Consider a scene contained in a rectangular box [ 10, 50] [0, 20] [10, 30] with the observer standing at P = (120, 60, 0)T and looking− at× a point× Q = (20, 10, 50)T with the “up” direction preserved (in other words the camera is yawed and pitched but not rolled). The idea is to translate the scene so that P is shifted to the origin, then align the viewing direction with OZ and finally scale the scene uniformly to fit the projection into the given viewport. The first part is Build: January 28, 2021 Projective space and quaternions 33 trivial. The matrix of the translation in homogeneous coordinates is 1 0 0 120 0 1 0 − 60 T =   0 0 1− 0   . 0 0 0 1 For the second step, form an orthogonal basis u, v, w , with w given by the viewing direction, and then map it to the canonical basis{ ε ,} ε , ε . The viewing direction { 1 2 3} is −−→PQ = ( 100, 50, 50)T , so after normalization: − −  0.82 Q P − w = −  0.41 Q P ≈ − . k − k 0.41 Next, find the vector u. The camera was not rolled and so u is orthogonal to w and ε2 at the same time. Forming the cross product we have:  0.45 w ε2 − u = ×  0  w ε ≈ . k × 2k 0.89 − The last vector must span the orthogonal completion of both u and w, hence  0.36 − v = u w 0.91  . × ≈ 0.18 We do not need to normalize it, as the cross product of two orthogonal unit vectors has always a unit length. The matrix (in linear coordinates) of an automorphism sending the canonical basis ε , ε , ε to u, v, w equals: { 1 2 3} { }  0.45 0.36 0.82   − − − A = u, v, w 0 0.91 0.41  . ≈ 0.89 0.18− 0.41 − 1 Thus, its inverse A− defines a map sending u, v, w to ε1, ε2, ε3 . Now, the 1 T{ } { } basis u, v, w is orthonormal, hence A− = A as observed in Section 4 of Chap- ter 1.{ Switching} to homogeneous coordinates and combining the result with the translation matrix computed earlier we get the desired transformation: T  u 0   0.45 0 0.89 54  T − −  v 0   0.37 0.91 0.18 11 M =  T  T − −   w 0  · ≈  0.82 0.41 0.41 122  − − . 0 0 0 1 0 0 0 1 Multiply the vertices of the bounding box of the scene by the above matrix to see that the transformed scene ranges in X direction from about 4.5 to about 49, in Y direction from about 27 to about 16 and in Z direction from 78 to 143. Consequently the scene must− be uniformly scaled by a factor of roughly 1/145 0.007 to keep its projection inside the viewport [ 1, 1] [ 1, 1]. ≈ − × − The orthogonal projection is not very persuasive when it comes to represent depth. It is used mostly for technical drawings since it preserves information about length ratios of parallel line segments. A slight modification of the orthogonal Build: January 28, 2021 34 Projective space and quaternions

Figure 2.2. Oblique projection of a unit box. projection, known as the oblique projection is defined by the following formula (in linear coordinates): x x + d z cos α y · · , 7→ y + d z sin α z · · for some parameters d (0, 1) and α (0, 2π). The typical values are d = √2/2 ∈ ∈ and α = π/4. The oblique projection leaves the OX and OY axes intact and maps the OZ axis to the line inclined to OX at an angle α, scaling it by the factor d, at the same time. Figure 2.2 shows the result of this map. The oblique projection can be obtained by a non-uniform scaling, composed with a shear transform followed by an orthogonal projection. The following matrix can be applied to transform the scene in such a way that the subsequent orthogonal projection will result in the oblique one: 1 0 d cos α 0 0 1 d sin α 0 0 0 d 0  . 0 0 0 1 Quite like the orthogonal projection, the oblique one is mostly used for technical illustrations. The oblique projection is better in convincing depth than the orthogonal one, yet still it does not stand up to our expectations based on everyday experience. Since at least the Renaissance, painters have been using a geometric perspective to simulate depth. The simplest one is the 1pt-perspective projection. The idea of a perspective projection is to simulate depth by adjusting relative sizes of ob- jects depending on their distance from the observer. Projections of objects farther aways should be relatively smaller than projections of objects that are closer to the observer. To this end, we emit rays (i.e. semi-lines) from the observer’s position toward all objects in the scene. A point in the scene is then mapped to the inter- section point of the corresponding ray with the viewport as depicted in Figure 2.3. Figure 2.4 shows a 1pt-perspective projection of a cube [ 1, 1]3. Observe how the lines parallel to the viewing direction converge towards a− single vanishing point. In order to derive an analytic formula for the perspective projection, first we restrict ourselves to just two dimensions. The field of view (FOV) is an isosceles Build: January 28, 2021 Projective space and quaternions 35

Figure 2.3. One-point perspective projection—objects posi- tioned farther away are visually smaller. trapezoid defined by two rays symmetrically3 emitted from the origin (see Fig- ure 2.5) and bounded by the near and far clipping lines z = z and z = z . { 0} { 1} Let y0 denote the ordinate of its near-top corner. The viewport is a line segment of length 2 perpendicular to the viewing direction (hence parallel to OY ). Using the similarity of triangles we compute the distance zp of the viewport from the origin: zp z0 zp = = . 1 y0 Now, take a point P = (y, z) lying inside the trapezoid. The perspective projection P 0 = (y0, zp) of P is obtained by intersecting the viewport with the line through P and the origin. Use the similarity of triangles again to compute y0. We have 0 y (yz ) y /zp = /z, thus y0 = 0 /(zy0). It follows that the perspective projection is defined by the formula y yz 0 . z 7→ zy0 Switching to the three-dimensional space, the viewing frustum becomes a truncated pyramid and the perspective projection takes a form:    xz0  x zx  0  y  yz  z 7→ 0 . zy0 Earlier we observed that the oblique projection can be expressed as a compo- sition of an appropriate space transformation followed by the canonical orthogonal projection (i.e. dropping the last coordinate). The same holds for the perspective projection. The perspective makes line parallel to the viewing direction converge at some distance e. Using the projective geometry language, introduced in the pre- vious section, we say that the point at infinity 0 : 0 : 1 : 0 , which is the common point of all the lines parallel to OZ, is mappedJ to someK point 0 : 0 : e : 1 at a finite distance e, yet still lying on the OZ axis. On the otherJ hand, the originK 0 : 0 : 0 : 1 and the points at infinity corresponding to the two remaining principal axesJ (i.e. 1K : 0 : 0 : 0 and 0 : 1 : 0 : 0 ) should stay intact. This way, we have fixed our mapJ at fourK points.J But, in orderK to apply the methods of the previous section, we need to have five points in a general position. Take the last point to

3This assumption is not really necessary, see Exercise 2.

Build: January 28, 2021 36 Projective space and quaternions

Figure 2.4. A cube in 1pt-perspective.

y0 1 P

zp z0 z1 1 −

Figure 2.5. One-point perspective projection in two dimensions. be the corner 1 : 1 : 1 : 1 of the viewing frustum and assume that it stays fixed under theJ− perspective− − map.K Hence, the map we are looking for must satisfy the following constrains: 1 : 0 : 0 : 0 1 : 0 : 0 : 0 , J K 7→ J K 0 : 1 : 0 : 0 0 : 1 : 0 : 0 , J K 7→ J K 0 : 0 : 1 : 0 0 : 0 : e : 1 , J K 7→ J K 0 : 0 : 0 : 1 0 : 0 : 0 : 1 , J K 7→ J K 1 : 1 : 1 : 1 1 : 1 : 1 : 1 . J− − − K 7→ J− − − K Theorem 1.7 asserts that there is a projective automorphism fulfilling the above requirements. The matrix of this automorphism is computed as a product BΓA where 1 u1 0 0 0}− u1 0 0 0} u1 0 0 0} 0 1 0 0 0 1 0 0 0 1 0 0 A = w  = w  B = w  w0 0 1 0 w0 0 1 0 w0 0 e 0 , , v0 0 0 1~ v0 0 0 1~ v0 0 1 1~ β u 1/α1 0 0 0 } β 0 1/α1 0 0 Γ = w β  w 0 0 1/α1 0  v β ~. 0 0 0 1/α1

Build: January 28, 2021 Projective space and quaternions 37

The coefficients αi and βi are obtained from the equations: u 1} u1} u0} u0} u0} −1 0 1 0 0 w−  = α1 w  + α2 w  + α3 w  + α4 w  w 1 w0 w0 w1 w0 , v−1 ~ v0~ v0~ v0~ v1~ u 1} u1} u0} u0} u0} −1 0 1 0 0 w−  = β1 w  + β2 w  + β3 w  + β4 w  w 1 w0 w0 we w0 . v−1 ~ v0~ v0~ v1~ v1~

1 It follows that α1 = α2 = α3 = 1 = β1 = β2, while α4 = 1, β3 = − /e and 1 − β4 = 1 + /e. Multiplying the matrices we get the desired result. Proposition 2.1. The 1pt-perspective transformation is defined by the formula (in the homogeneous coordinates): x 1 0 0 0  x y 0 1 0 0  y z 0 0 1 0  z   7→    . 1 0 0 1/e 1 + 1/e 1 It maps the truncated pyramid with the front-face having vertices [ 1, 1, 1, 1]T e+1 e+1 e+1 T ± ± 3− 3 and the back-face with vertices [ e 1 , e 1 , e 1 , 1] onto the cube [ 1, 1] R . ± − ± − − − ⊂ In the situation described in the above proposition, the observer sits at the apex of the pyramid, which is the point [0, 0, (1 + e), 1]T . Thus, the longer the focal length e is, the farther away is the observer.− This comes as no surprise since the long focal length corresponds to a narrow angle of view, hence the scene must be watched from a considerable distance in order to fit into the viewport. Compute the limit of the above expression as the focal length e approaches the infinity: 1 0 0 0  1 0 0 0 0 1 0 0  0 1 0 0 lim   =   e 0 0 1 0  0 0 1 0 →∞ . 0 0 1/e 1 + 1/e 0 0 0 1 It is the identity matrix. Therefore, there is only the orthogonal projection (that followed the perspective transformation) left. This is why we said earlier that the orthogonal projection is a limit case of a perspective projection. Figure 2.6 shows how the perspective changes with the focal length. In real-life applications (e.g. in computer graphics), we want the observer to stay at the origin and the viewing frustum to be defined, as in the earlier discussion, by the two cutting planes: near z = z0 and far z = z1 . This can be achieved by a translation followed by a non-uniform{ } scale—we{ leave} the details to the reader, showing only the resulting matrix. Observation 2.2. The following map    z0 0 0 0    x x0 x z y  0 0 0 0  y    y0    z 7→  0 0 z0+z1 2z0z1  z − z0 z1 z0 z1 . 1 0 0 1− − 0 1 Build: January 28, 2021 38 Projective space and quaternions

Figure 2.6. Three perspective projections of the same cube but with increasing focal lengths.

transforms the truncated pyramid with the near clipping plane z = z0 , far clip- ping plane z = z and the corner of the front-face [x , y , z ,{1]T onto} the cube { 1} 0 0 0 [ 1, 1]3 R3. − ⊂ Of course, if the position of the observer and its line of view does not coincide with the origin together with the OZ axis, then the scene must be aligned first by the appropriate isometry as shown in the example earlier in this section. Beside the 1pt-perspective, painters and illustrators often use 2pt- and 3pt- perspective projections, where two (respectively three) points at infinity, corre- sponding to the given system of orthogonal directions, are brought to finite dis- tances. Figure 2.7 shows how these two maps work. The matrix forms of these transformations are once again derived using the technique developed in Section 1. Here we present the procedure for the 2pt-perspective, the other one is similar. Without loss of generality we may assume that the fixed orthogonal directions mentioned above are just the principal axes—if not, combine the map with an isometry. Suppose that the lines parallel to OY should remain parallel, while the ones parallel to OX and OZ should converge at (finite) distances, respectively e and g. Again, let the origin and the point 1 : 1 : 1 : 1 stay fixed. Thus the map is uniquely determined by the set of constrains:J− − − K 1 : 0 : 0 : 0 e : 0 : 0 : 1 , J K 7→ J K 0 : 1 : 0 : 0 0 : 1 : 0 : 0 , J K 7→ J K 0 : 0 : 1 : 0 0 : 0 : g : 1 , J K 7→ J K 0 : 0 : 0 : 1 0 : 0 : 0 : 1 , J K 7→ J K 1 : 1 : 1 : 1 1 : 1 : 1 : 1 . J− − − K 7→ J− − − K Constructing the matrices A, B, Γ and multiplying them together (like for the 1pt-perspective) we have: Observation 2.3. The 2pt-perspective transformation is obtained by the for- mula x 1 0 0 0  x y 0 1 0 0  y       z 7→ 0 0 1 0  z 1 1 1 1 , 1 e 0 g 1+ e + g 1 Build: January 28, 2021 Projective space and quaternions 39

Figure 2.7. Comparison of the 2pt-perspective (left) and 3pt- perspective (right). where the lines parallel to OX converge at [e, 0, 0, 1]T , parallel to OZ at [0, 0, g, 1]T and parallel to OY remain parallel. Likewise for the 3pt-perspective we have: Observation 2.4. The 3pt-perspective transformation is obtained by the for- mula x 1 0 0 0  x y 0 1 0 0  y       z 7→ 0 0 1 0  z 1 1 1 1 1 1 , 1 e f g 1+ e + f + g 1 where the lines parallel to OX converge at [e, 0, 0, 1]T , parallel to OY at [0, f, 0, 1]T and parallel to OZ at [0, 0, g, 1]T . All three ways of representing perspective, namely 1pt-, 2pt- and 3pt-perspec- tive projections are used by artists with the choice of method dictated by the actual situation. An inside view of a big hall could be depicted in the 1pt-perspective with edges of the floor and ceiling converging at some distant point; a building seen from the outside with one corner facing a viewer would likely be drawn in either the 2pt- perspective (if the horizon is roughly at half of the building’s height) or in the 3pt- perspective (when the observer is near the basement of the structure). All three projections correspond to our natural way of perceiving the reality surrounding us. Thus it should not come as a big surprise that they are actually equivalent in the sense that any one of them is conjugated with any other by some rotation and (uniform) scaling. In other words, by just yawing/pitching/rolling the camera and possibly adjusting the scale of the scene we can change the projection from 1pt-perspective to 2pt-perspective to 3pt-perspective et vice versa. Indeed, it is an easy observation that two parallel lines stay parallel after per- forming a 1pt-perspective transformation if and only if they are contained in a plane orthogonal to the viewing direction. Therefore, a projective map which is a 1pt-perspective with respect to the principal system of coordinates, becomes a 2pt-perspective transformation, when regarded with respect to a coordinate sys- 3 tem determined by an orthonormal basis α, ε2, γ of U3 = R , where α and γ are { } ∼ contained in the OX plane but are not parallel to ε1, ε3. This is so because all the points at infinity corresponding to the directions of lines contained in OXZ are brought to finite distances, except the single point corresponding to the direction of the OZ axis. More rigorously, we can formalize the above discussion as follows: Build: January 28, 2021 40 Projective space and quaternions

3 3 Proposition 2.5. If π2 : P R P R is a 2pt-perspective transformation, then → 3 3 there is a 1pt-perspective transformation π1 : P R P R together with a rotation ρ and a uniform scaling σ such that →

1 π2 = (ρσ)− π1(ρσ).

Proof. Our first step is to find the focal length h in the direction OZ for the 1pt-perspective transformation π1. Let e, g be the convergence distances of π2 in directions OX and OZ, respectively. Thus we have a matrix equation

1 (2.6) B = (RS)− A(RS), where A is the matrix of the sought 1pt-perspective (c.f. Proposition 2.1), B is the matrix of the 2pt-perspective given in Observation 2.3, R is the matrix of a rotation (see Proposition 2.8) and finally S is the matrix of a uniform scaling (c.f. Observation 2.6). Comparing the bottom-rightmost entries we have 1 + 1/e + 1/g = 1 + 1/h. It follows that the focal distance h is given by the formula

eg h = . e + g

Consider three points at infinity P = e : 0 : g : 0 , Q = 0 : 1 : 0 : 0 and R = g : 0 : e : 0 together with the originJ O = 0 : 0K : 0 : 1 .J Clearly theK lines throughJ− O and P , KO and Q and O and R are pairwiseJ orthogonal.K Compute the images of P , Q, R under the 1pt-perspective π1. First, it sends P to P 0 = e : 0 : e + g 2 eg J g : /e = e /e + g : 0 : /e + g : 1 . Further, the point Q remains fixed under π1, 2 K J g e K+ g eg e + g while R is mapped to R0 = − / : 0 : / : 1 . Observe that P 0 belongs to the line through O and P , likewiseJ R0 lies on the line throughK O and R. In the linear 3 space R ∼= U3 we fix an orthogonal basis consisting of the following three vectors: e g T p 2 2 T g e T u = ( /e + g, 0, /e + g) , v = (0, e + g /e + g, 0) and w = ( − /e + g, 0, /e + g) . The lines parallel to u converge under π1 to eu and the lines parallel to w converge to gw, while the ones parallel to v stay parallel. Therefore π1 in the coordinate system (u, v, w) behaves like the 2pt-perspective. Consequently, by switching from canonical coordinate system given by ε1, ε2 and ε3 to the new one, transforming the space by π1 and switching back, we obtain exactly the same result as using the 2pt-perspective. The vectors u, v, w are not normalized, but they have the p common length e2 + g2/e + g. Since they are pairwise orthogonal it follows that the map sending ε1 u, ε2 v and ε3 w is a composition of a uniform scaling σ by e + g p7→2 2 7→ 7→ g the factor / e + g followed by a rotation ρ around ε2 by an angle arctan( /e) with . Thus

1 π2 = (ρσ)− π1(ρσ).  Build: January 28, 2021 Projective space and quaternions 41

1 In matrix notation (see Eq. (2.6)) we write it as B = (RS)− A(RS), where: 1 0 0 0  1 0 0 0  0 1 0 0  0 1 0 0  A =   B =   0 0 1 0  0 0 1 0  e+g e+g , 1 1 1 1 , 0 0 eg 1 + eg e 0 g 1 + e + g

 2 2  e g √e +g  0 − 0 0 0 0 √e2+g2 √e2+g2  e+g  √e2+g2  0 1 0 0  0 0 0 R =  g e  S =  e+g   0 0  2 2   2 2 2 2   √e +g  √e +g √e +g  0 0 0 , e+g . 0 0 0 1 0 0 0 1 A fully analogous result can be proved for a 3pt-perspective. We let the reader fill up the missing details. 3 3 Proposition 2.7. If π3 : P R P R is a 3pt-perspective transformation, then → 3 3 there is a 1pt-perspective transformation π1 : P R P R together with a rotation ρ and a uniform scaling σ such that → 1 π3 = (ρσ)− π1(ρσ).

3. Duality and the Pl¨ucker-Grassmann coordinates So far we have been using the notion of homogeneous/projective coordinates of points. In this section we show how to assign coordinates to any projective subspace. Not only points, but also lines and planes in P3R have consistently defined coordinates, hence may be treated in a unified manner. Moreover, as we will see, points and lines in the projective plane P2R (respectively points and planes in the projective space P3R) behave in a dual fashion. Every operation performed on one of them has its dual acting on the other. In order to motivate our farther studies and build some basic intuition, consider first an equation (3.1) ax + by + cw = 0. If the parameters a, b, c (not all equal zero) are considered fixed, then the equation describes all the points x : y : w lying on a line L in the projective plane P2R. The numbers a, b, c R Jare the coefficientsK (“coordinates”) of this line L. But we ∈ can reverse the situation, assuming that it is the point P = x : y : w P2R which is fixed. Then, the equation Eq. (3.1) describes all the projectiveJ K lines∈ passing through P . Observe that we may scale the coefficients (“coordinates”) a, b, c of a line by a non-zero factor, without altering the line itself, exactly as we scale the projective coordinates of a point. We shall see soon that a, b, c are actually the Pl¨ucker-Grassmann coordinates of a line and like the projective coordinates of a point they are unique only up to the multiplication by a non-zero scalar. Take now three points P1 = x1 : y1 : w1 , P2 = x2 : y2 : w2 and P3 = x3 : 2J K J K J y3 : w3 in the projective plane P R. They are co-linear (i.e. they lie on a common line) ifK and only if there are a, b, c R, not all equal zero, satisfying ∈  ax + by + cw = 0  1 1 1 ax2 + by2 + cw2 = 0  ax3 + by3 + cw3 = 0. Build: January 28, 2021 42 Projective space and quaternions

This is equivalent to saying that the determinant of the matrix constructed from the coordinates of P1, P2 and P3 is non-zero:

ux1 y1 w1} det x y w = 0. v 2 2 2~ 6 x3 y3 w3

2 On the other hand, if we take three lines L1, L2, L3 in the projective plane P R, where the Pl¨ucker-Grassmann coordinates of Li are ai, bi and ci, then these lines intersect at a single point if and only if there are x, y, z R, not all equal zero, such that ∈  a x + b y + c w = 0  1 1 1 a2x + b2y + c2w = 0  a3x + b3y + c3w = 0 if and only if

ua1 b1 c1} det a b c = 0. v 2 2 2~ 6 a3 b3 c3 As we see, in order to check whether three point lie on a common line, one needs to perform exactly the same operations as when checking if three lines pass through a common point. This is so because points and lines in the projective plane are dual to each other. Every statement true about one kind of objects has its dual con- structed by exchanging the words “point(s)” and “line(s)” and the phrases “lie(s) on” and “pass(es) through”. The mother of all the examples is the following pair of sentences: Every two distinct projective points lie on a common line. Every two distinct projective lines pass through a common point. Now, it is time to define Pl¨ucker-Grassmann coordinates in their full generality. Take a subspace V of a projective space PnR of dimension d < n given by a matrix equation

ux0 } u0} . . (3.2) M w .  = w. · v ~ v ~, xn 0 where the rank of M is rank M = n d (see Section 1). Consider the equation − Eq. (3.2) on the linear space Rn+1 and let Vˆ denote the subspace of the solutions:       x0 x0 0   ˆ  .  n+1  .  . V =  .  R M  .  = . .  ∈ ·   xn xn 0  Clearly, the projective subspace V PnR is the set of the equivalence classes of ⊂ vectors from Vˆ with respect to the relation defined in Chapter 1. We say that Vˆ ˆ ˆ ∼ ˆ n is the lift of V . Choose a basis P0,..., Pd of V and let P0,...,Pd P R be the corresponding points in the projective{ space.} They span V in the following∈ sense:

Observation 3.3. V is the smallest projective subspace containing P0,...,Pd. Build: January 28, 2021 Projective space and quaternions 43

Suppose that Pj has the projective coordinates xj,0 : ... : xj,n . Take a (d+1)- J K tuple ˆı = (i0, . . . , id) where 0 ik n. Let Aˆı Md+1,d+1(R) be a matrix with ≤ ≤ ∈ rows (xj,i0 , . . . , xj,id ): x x  0,i0 ··· 0,id  . .  Aˆı =  . .  x x 0,i0 ··· d,id and let Vˆı := det Aˆı. In other words, to build Aˆı we write all the coordinates of P0,...,Pd as rows of a (d + 1) (n + 1) matrix, denote it A, and then we select the columns corresponding to the× entries of ˆı. The rank of A equals d + 1 since Pˆ0,..., Pˆd where linearly independent as a basis of V . Therefore, for at least one (d + 1)-tuple ˆı, the corresponding matrix Aˆı is invertible, hence its determinant Vˆı is non-zero. n+1 Definition 3.4. The d+1 -tuple ... : Vˆı : ... , where ˆı ranges over all the combinations of d + 1 elements from theJ set 0, . . . , nK is called the Pl¨ucker-Grass- mann coordinates of the subspace V . { } Recall that the projective coordinates of a point are unique only up to a mul- tiplication by a non-zero scalar. Such a multiplication scales all the determinants in the above definition by a constant factor. It follows that the Pl¨ucker-Grass- mann coordinates of a subspace are also defined only up to a multiplication by a common factor. Before we present any examples we still need to show that the definition of Pl¨ucker-Grassmann coordinates does not depend on the choice of the basis Pˆ0,..., Pˆd . {ˆ ˆ } ˆ ˆ If P00,..., Pd0 is another basis of V , then every Pi0 can be written (uniquely) as the linear combination Pˆ0 = b Pˆ + + b Pˆ . i i0 0 ··· id d In a matrix form:  ˆ T   ˆT  (P00) P0  .  = B  .   .  ·  .  ˆ T ˆT , (Pd0 ) Pd where B = (b ) is a (d + 1) (d + 1) matrix. Clearly B is invertible since both ij × sets Pˆ ,..., Pˆ and Pˆ0,..., Pˆ0 are bases of V . Define P 0,...,P 0 and A0 , V 0 { 0 d} { 0 d} 0 d ˆı ˆı analogously as P ,...,P and A , V . We have A0 = B A consequently 0 d ˆı ˆı ˆı · ˆı ... : Vˆı0 : ... = det B ... : Vˆı : ... = ... : Vˆı : ... . J K · J K J K This shows that the definition is correct—the Pl¨ucker-Grassmann coordinates de- pend solely on V not on the choice of a set of points spanning V . Observe that straight from the definition, the full space PnR has just one coor- n+1 dinate, since n+1 = 1. The coordinate is the determinant of the matrix obtained from a basis of Rn+1, hence it is not zero. The Pl¨ucker-Grassmann coordinates are defined only up to a multiplicative factor, hence we can take the unique coordinate of PnR to be 1. For completeness we assign also the Pl¨ucker-Grassmann coordi- n+1 nates to the empty set. Again it must be just one coordinate as 0 = 1. We simply define the unique coordinate of the empty set to be 0. For a point P the order in which we write its coordinates is in fact arbitrary. It is only a matter of tradition and a common convention that we first write x, then y and then z. For Pl¨ucker-Grassmann coordinates there is no such widely-spread Build: January 28, 2021 44 Projective space and quaternions convention. Thus, to avoid confusion we shall always explicitly write the order of ˆı’s. What’s more, since every ˆı is a finite sequence of indexes, a permutation of these indexes influences the resulting Pl¨ucker-Grassmann coordinates. To explain this correspondence we need to recall the notion of the sign of a permutation. Let σ be a permutation of the set 0, . . . , n . It is well known (see e.g. [14, Chapter I, § 4]) that σ can be written as a{ product} of transpositions (a transposition is a permutation that exchanges exactly two elements of the domain leaving the rest intact). The decomposition of the permutation into a product of transpositions is not unique, nevertheless the parity of a number of transpositions is constant for the given permutation σ. We define sgn σ to be ( 1)k where k is a number of transpositions in some decomposition of σ. The permutation− σ is called even if sgn σ = 1 otherwise it is odd. After this short digression, we can explain how a permutation of indexes in ˆı influences the Pl¨ucker-Grassmann coordinates. As we know, every transposition of columns of a matrix changes the sign of its determinant. Thus we have: Observation 3.5. If σ S(d + 1) is a permutation, then V = sgn σ V . ∈ ˆı · σ(ˆı) Let us see how to compute the Pl¨ucker-Grassmann coordinates of some basic subspaces like: points, lines and planes. Start from a point P = x0 : ... : xn n n+1 J K ∈ P R which form a 0-dimensional subspace. It has 1 = n+1 Pl¨ucker-Grassmann coordinates

P0 : ... : Pn = det(x0): ... : det(xn) = x0 : ... : xn . J K J K J K Observation 3.6. The Pl¨ucker-Grassmann coordinates of a point equal its projective coordinates. Thus the notion of the Pl¨ucker-Grassmann coordinates generalizes the notion of the projective coordinates. Now, take a line L through two points P , Q in the projective plane P2R. The line in the projective plane has three Pl¨ucker-Grassmann 2+1 coordinates as 1+1 = 3. These are:

L12 : L20 : L01 =

J K yP wP wP xP xP yP = qdet ( yQ wQ ) : det ( wQ xQ ) : det ( xQ yQ )y =

= yP wQ yQwP : xQwP xP wQ : xP yQ xQyP . J − − − K Observe that these are just the coordinates of a cross product p q, where p, q R3 × ∈ are lifts of P and Q. Abusing the notation, we write shortly L12 : L20 : L01 = p q . At least one of the determinants is non-zero. SupposeJ that the equationK definingJ × K L is L : ax + by + cw = 0. It is satisfied by both P and Q, hence we have a system of two simultaneous linear equations: ( axP + byP + cwP = 0

axQ + byQ + cwQ = 0.

Suppose, for example, that it is L01 which is not zero. Solve the system using the Cramer’s rule to get L L L L a = c 21 = c 12 and b = c 02 = c 20 . − L01 L01 − L01 L01 Build: January 28, 2021 Projective space and quaternions 45

Observation 3.7. The Pl¨ucker-Grassmann coordinates of a line L defined by the equation ax + by + cw = 0 are L12 : L20 : L01 = a : b : c . J K J K Switch now to subspaces of the projective space P3R. Beside the points, covered by Observation 3.6, there are lines and planes that we should consider. Planes in the projective space behave quite like lines in the projective plane. Namely we have:

Observation 3.8. The Pl¨ucker-Grassmann coordinates of a plane V P3R defined by the equation ax + by + cz + dw = 0 are ⊂

V132 : V230 : V310 : V012 = a : b : c : d . J K J K The reader may easily supply the details. Now, consider a line L P3R through ⊂ two points P = xP : yP : zP : wP and Q = xQ : yQ : zQ : wQ . According to J K J K the definition, the Pl¨ucker-Grassmann coordinates of L are L12 : L20 : L01 : L03 : J L13 : L23 , where K yP zP , yP zP , yP zP , L12 = det ( yQ zQ ) L20 = det ( yQ zQ ) L01 = det ( yQ zQ )

yP zP , yP zP , yP zP . L03 = det ( yQ zQ ) L13 = det ( yQ zQ ) L23 = det ( yQ zQ )

3 Let p, q R be two vectors with coordinates respectively p = (xP , yP , zP ) and ∈ q = (xQ, yQ, zQ). The first three Pl¨ucker-Grassmann coordinates of L are equal p q, while the next three are pwQ qwP . We may rewrite the above formula in a× short, informal but easy to remember− form

L12 : L20 : L01 : L03 : L13 : L23 = p q : p wQ q wP . J K J × · − · K If we assume that neither P nor Q lies at infinity, we may always take wP = wQ = 1 and so the coordinates of L are p q : p q . Summarizing we have the following result: J × − K Observation 3.9. The Pl¨ucker-Grassmann coordinates of a line L through two affine points P,Q R3 are ∈ L12 : L20 : L01 : L03 : L13 : L23 = x : y : z : x0 : y0 : z0 , J K J K T T where (x, y, z) = −−→ΘP −−→ΘQ and (x0, y0, z0) = −−→QP . × Example. Take two points P = (1, 0, 1)T and Q = (0, 2, 0)T . The cross product is then (1, 0, 1)T (0, 2, 0)T = ( 2, 0, 2)T and their difference is (1, 0, 1)T (0, 2, 0)T = (1, 2, 1)T . Therefore× the Pl¨ucker-Grassmann− coordinates of the line− L containing these− points are

L12 : L20 : L01 : L03 : L13 : L23 = 2 : 0 : 2 : 1 : 2 : 1 . J K J− − K Beside being determined by two points on it, a line L in the projective space P3R can be also given as an intersection of two planes. One can derive the Pl¨uc- ker-Grassmann coordinates of L from the coordinates of the two planes defining it.

Proposition 3.10. Let V,W P3R be two projective planes with the Pl¨ucker- ⊂ Grassmann coordinates respectively: V132 : V230 : V310 : V012 and W132 : W230 : J K J W310 : W012 . Further let L := V W be the line where the two planes intersect. K ∩ Build: January 28, 2021 46 Projective space and quaternions

The Pl¨ucker-Grassmann coordinates of L are L12 : L20 : L01 : L03 : L13 : L23 = x0 : y0 : z0 : x : y : z , where J K J   K          x0 V132 W132 x V132 W132 y0 = W012 V230 V012 W230 and y = V230 W230 − × z0 V310 W310 z V310 W310

T T Write v := (V132,V230,V310) and w = (W132,W230,W310) . If neither V nor W is the plane at infinity, then the vectors v and w are orthogonal to V and W , respectively. The Pl¨ucker-Grassmann coordinates of L can be written in a short form (dual to the formula for the coordinates of a line through two points):

L12 : L20 : L01 : L03 : L13 : L23 = v W012 w V012 : v w . J K J · − · × K If neither of these two planes pass through the origin, we may take W012 = V012 = 1, simplifying the formula even farther to v w : v w . J − × K Proof. In the projective space P3R we have four principal planes, namely: x = 0 , y = 0 , z = 0 and the plane at infinity w = 0 . Since we are dealing{ } here{ with} only{ two planes} V and W , hence changing{ possibly} the order of coordinates, without loss of generality we may assume that neither V nor W is the plane at infinity. Take the vectors v and w as in the above comment, so that they are orthogonal respectively to V and W . It follows that their cross-product u := v w, being perpendicular to both of them, determines the direction of L. × Fix a point P = xP : yP : zP : 1 on L and let Q be the translation of P along L: J K Q := P + u. Let p := −−→ΘP and q := −−→ΘQ. In order to apply Observation 3.9, we need to compute the cross product p q = p u. We have × × V (yW + zW ) W (yV + zV ) 132 · 230 310 − 132 · 230 310 (3.11) p u = V (xW + zW ) W (xV + zV )  230 132 310 230 132 310 . × V · (xW + yW ) − W · (xV + yV ) 310 · 132 230 − 310 · 132 230 The coordinates xP , yP , zP of P satisfy the equations for V and W simultaneously. Therefore we can write ( p v + V = 0 • 012 p w + W = 0. • 012 This let us substitute the formulas in the parenthesis in Eq. (3.11), to get  V W + W V  − 132 012 132 012 p u =  V230W012 + W230V012 = V012 w W012 v. × −V W + W V · − · − 310 012 310 012 Observation 3.9 asserts that the Pl¨ucker-Grassmann coordinates L12 : L20 : L01 : J L03 : L13 : L23 of L are given by the formula p q : p q , but this equals K J × − K w V012 v W012 : v w , as desired.  J · − · × K Observe that the co-dimension 1 subspaces of PnR (e.g. planes in P3R and 2 n+1 lines in P R) have n = n + 1 Pl¨ucker-Grassmann coordinates—exactly like points. Consider the set of all the co-dimension 1 subspaces of PnR. It has a natural structure of a projective space. This space is called the dual space to PnR n and denoted PnR. As the co-dimension one subspaces of P R become points in Build: January 28, 2021 Projective space and quaternions 47

n PnR, the co-dimension 2 subspaces of P R correspond to lines in PnR, the co- n dimension 3 subspaces of P R turn into planes in PnR and so on till the points of PnR become the co-dimension 1 subspaces of the dual space. We omit the details of this correspondence in an arbitrary dimension, referring the reader to [15, Part 3, §7]. Instead we concentrate on the low dimensional cases. The duality in the projective plane was discussed at the beginning of this sec- tion. We restate the main points using the terminology introduced in the meantime. The projective plane P2R consists of points and the co-dimension one subspaces are lines. A line with the Pl¨ucker-Grassmann coordinates a : b : c consists of all the points x : y : w P2R satisfying the equation ax + byJ + cw K= 0. On the other J K ∈ 2 4 hand, the dual space P2R consists of lines of P R. So a point in P2R is a line in 2 P R. Now P2R is clearly a plane, hence a line in the dual space is the set of points L∗ = a : b : c of P2R satisfying the equation xa + yb + cw = 0. Such a line P ∗ J K has the Pl¨ucker-Grassmann coordinates P12∗ : P20∗ : P01∗ = x : y : w in P2R and clearly corresponds to a point P = x : yJ : w in the originalK J plane PK2R. A point P = x : y : w P2R lies on a lineJ L = a K: b : c P2R if and only if the line J K ∈ J K ⊂ P ∗ = x : y : w P2R passes through the point L∗ = a : b : c P2R. ⊂ ∈ SimilarJ correspondenceK occurs in three dimensions.J A planeK V in P3R with the Pl¨ucker-Grassmann coordinates V132 : V230 : V310 : V012 = a : b : c : d becomes J K J K a point V ∗ = a : b : c : d in the dual space P3R.A plane P ∗ in P3R with the J K Pl¨ucker-Grassmann coordinates P132∗ : P230∗ : P310∗ : P012∗ = x : y : z : w clearly corresponds to a point P = x :Jy : z : w in P3R. ThisK stillJ leaves us withK lines, which have the dimension oneJ and the co-dimensionK two. It should not come with a 3 big surprise that lines in P R corresponds to lines in the dual space P3R. Let us take a closer look at their Pl¨ucker-Grassmann coordinates in both spaces. Fix a line L in 3 P R spanned by the points P = xP : yP : zP : wP and Q = xQ : yQ : zQ : wQ . J T K J T K As before take two vectors p = (xP , yP , zP ) and q = (xQ, yQ, zQ) . The Pl¨ucker- Grassmann coordinates of L are p q : pwQ qwP . The points P , Q correspond J × − K to two planes P ∗ and Q∗ in the dual space P3R. Hence the line L through P , Q turns into the line L∗ defined as the intersection L∗ = P ∗ Q∗. Proposition 3.10 ∩ asserts that the Pl¨ucker-Grassmann coordinates of L∗ are pwQ qwP : p q . Thus we have proved: J − × K

3 Corollary 3.12. The dual L∗ to a projective line L P R is again a line with the Pl¨ucker-Grassmann coordinates ⊂

L12∗ : L20∗ : L01∗ : L03∗ : L13∗ : L23∗ = L03 : L13 : L23 : L12 : L20 : L01 . J K J K In a nutshell: to write the coordinates of the dual line we swap the two triples making up the coordinates of the original line. The following theorem provides a generalization of the above corollary to an arbitrary dimension.

n Theorem 3.13. The dual V ∗ PnR to a projective subspace V P R of dimension d is a projective subspace⊂ of dimension n d 1 with the Pl¨ucker-Grass-⊂ − − mann coordinates ... : Vˆ∗ : ... satisfying the condition J K V ∗ = ε V , ˆ · ˆı

4For clarity, we use italics to distinguish objects in a dual space from objects in a “normal” projective space.

Build: January 28, 2021 48 Projective space and quaternions

providing that the support of the concatenation (ˆı, ˆ) = (i0, . . . , id, j0, . . . , jn d 1) is the whole set 0, . . . , n and ε is the sign of the permutation − − { }  0 1 d d + 1 n  ··· ··· . i0 i1 id j0 jn d 1 ··· ··· − − We omit the proof here, referring an interested reader to [12, Chapter VII, §3, Theorem I]. Take a projective automorphism T : PnR PnR. It induces a function → T ∗ : PnR PnR on the dual space, defined by a condition →  T ∗(V ∗) = T (V ) ∗. n In other words, if V ∗ is a point of PnR, then V is a hyperplane of P R. Suppose that V is spanned by some points P, ...,Pn 1 and denote Q0 := T (P0),...,Qn 1 := − − T (Pn 1). Since T is an automorphism, the smallest projective subspace containing − Q0,...,Qn 1 is again a hyperplane. Denote it W , then T ∗(V ∗) is just the point − W ∗ dual to W . It is easy to observe that T ∗ is also a projective automorphism. We say that it is a dual projective automorphism to T . The following result provides an analytic formula bounding T ∗ with T . Proposition 3.14. If M is a matrix associated to a projective automorphism n n T 1 T : P R P R, then (M )− is a matrix associated to its dual T ∗ : PnR PnR. → → Proof. Take a point V ∗ of PnR with coordinates y∗ : ... : y∗ . Let V 0 n ⊂ PnR be the corresponding hyperplane. It follows fromJ the discussionK preceding Theorem 3.13 that the Pl¨ucker-Grassmann coordinates of V are

y1,2,...,n : y0,2,...,n : ... : y0,1,...,n 1 = y0∗ : y1∗ : ... : yn∗ . J − K J K Suppose that V is spanned by points P0,...,Pn 1 with coordinates − Pi = xi,0 : ... : xi,n . J K It follows from a reasoning similar to the one that led us to Observation 3.7 and 3.8, that

y1,2,...,n xi,0 + + y0,1,...,n 1 xi,n = 0 · ··· − · for every i 0, . . . , n 1 . In a matrix form we can write this condition as ∈ { − } uxi,0 } . y1,2,...,n : ... : y0,1,...,n 1 w .  = 0 J − K · v ~ xi,n (or in even shorter form as V P = 0). Introducing M into this equation, we write · i uxi,0 } 1 . y1,2,...,n : ... : y0,1,...,n 1 M − M w .  = 0. J − K · · · v ~ xi,n Rearranging the terms we have  T   u y1,2,...,n } uxi,0 }  T 1 .   .  (M )− w .  M w .  = 0. · v ~ · · v ~ y0,1,...,n 1 xi,n − Build: January 28, 2021 Projective space and quaternions 49

Now, M P is the image of T (P ) of P and it follows from the above formula that · i i i the Pl¨ucker-Grassmann coordinates of T (V ) are z1,2,...,n : ... : z0,1,...,n 1 , where J − K u z1,2,...,n } u y1,2,...,n } . T 1 . w .  = (M )− w .  v ~ · v ~. z0,1,...,n 1 y0,1,...,n 1 − −

Consequently the coordinates of V ∗ are z0∗ : ... : zn∗ with zj∗ = z0,...,j 1,j+1,...,n. J K − This proves the thesis.  Example. As in the example on page 31, suppose we are given a photo, that was shot with a tilted camera. Our aim is again to correct the perspective distortion. This time however, instead of four points, we operate on two pairs of lines: A, B and C, D. The first pair represents directions in the picture that should be horizontal and the second vertical. Say

A = A12 : A20 : A01 = 0.491 : 0.07 : 0.042 J K J− K B = B12 : B20 : B01 = 0.491 : 0.049 : 0.381 J K J− − K C = C12 : C20 : C01 = 0.0 : 0.679 : 0.033 J K J − K D = D12 : D20 : D01 = 0.0, 0.56, 0.302 . J K J − K Passing to the dual space, we consider four points:

A∗ = 0.491 : 0.07 : 0.042 B∗ = 0.491 : 0.049 : 0.381 J− − K J− K C∗ = 0.0 : 0.679 : 0.033 D∗ = 0.0 : 0.56 : 0.302 . J − − K J − − K We need to construct a map T ∗ : P2R P2R specified by the following conditions → T ∗(A∗) = 0.421 : 0.0 : 0.039 T ∗(B∗) = 0.421 : 0.0 : 0.325 J− K J− K T ∗(C∗) = 0.0 : 0.679 : 0.02 T ∗(D∗) = 0.0 : 0.679 : 0.306 . J − K J − K Using methods described in Section 1, we build a matrix N of T ∗: u 1.040 0.0 0.0 } N = 0.258 1.496 0.525 . v 0.007 0.008 1.024~ − Proposition 3.14 asserts that u0.962 0.169 0.008 } u0.983 0.172 0.008 } T 1 − − M = (N )− = 0.0 0.67 0.005 0.0 0.685 0.005 v 0.0 0.343− 0.979 ~ ∼ v 0.0 0.351− 1.0 ~ − − defines the desired projective transformation of the picture. If V , W are two disjoint projective subspaces, then the smallest projective subspace U containing both of them is called the join of V and W . We are now in the position to present the main theorem of this section, which not only allow us to compute the Pl¨ucker-Grassmann coordinates of the join of V , W , knowing only their Pl¨ucker-Grassmann coordinates, but also to test whether the two intersect.

Theorem 3.15. Let V , W be two projective subspaces of PnR with the Pl¨uc- ker-Grassmann coordinates ... : Vˆı : ... and ... : Wˆ : ... , respectively. Take J K J K Build: January 28, 2021 50 Projective space and quaternions

m := dim V , r := dim W and d := m + r + 1. For any kˆ = (k0, . . . , kd) let X Ukˆ := sˆı,,ˆ kˆVˆıWˆ, ˆı ˆ=kˆ ∪ kˆ  where sˆı,,ˆ kˆ is the sign of the permutation ˆı,ˆ :

k k k k k  s := sgn 0 1 m m+1 d . ˆı,,ˆ kˆ i i ··· i j ··· j 0 1 ··· m 0 ··· r

If V and W are disjoint, then ... : Ukˆ : ... are the Pl¨ucker-Grassmann coordinates J K of the join U of V and W . If V and W intersect, then all Ukˆ are zero.

Proof. Suppose that V is spanned by P0,...,Pm V and W is spanned ∈ n by Q0,...,Qr W . Consequently U is the smallest subspace of P R containing ∈ P0,...,Pm,Q0,...,Qr. Denote the coordinates of Pi by pi0 : ... : pin and the J K coordinates of Qj by qj0 : ... : qjn . Construct a matrix J K  p p  00 ··· 0n  . .   . .    pm0 pmn A =  ···   q00 q0n   ···   . .   . .  . q q r0 ··· rn As in the definition of Pl¨ucker-Grassmann coordinates, for a (d + 1)-tuple kˆ =

(k0, . . . , kd), let Akˆ be the submatrix of A obtained by selecting only the columns with indexes k0, . . . , kd:

 p p  0k0 ··· 0kd  . .   . .    pmk0 pmkd  Akˆ =  ···   q0k0 q0kd   ···   . .   . .  . q q rk0 ··· rkd

Compute the determinant of Akˆ expanding it into the determinants of (m + 1) (m + 1) minors from the first m + 1 rows and (r + 1) (r + 1) minors from the× remaining r + 1 rows. It follows from the basic properties× of a determinant that X det Akˆ = sˆı,,ˆ kˆVˆıWˆ = Ukˆ. ˆı ˆ=kˆ ∪ The rows of A are linearly independent if and only if V W = and then at least ˆ ∩ ∅ one Ukˆ is not zero. Otherwise, Ukˆ = 0 for every k. 

Example. Take a point P = 1 : 1 : 1 : 1 and a line L with the Pl¨ucker- J K Grassmann coordinates L12 : L20 : L01 : L03 : L13 : L23 = 1 : 1 : 1 : 0 : 1 : 1 . J K J− − K Build: January 28, 2021 Projective space and quaternions 51

Use the above theorem to compute U = sgn ( 1 3 2 ) L P + sgn ( 1 3 2 ) L P + sgn ( 1 3 2 ) L P = 1, 132 1 2 3 12 3 1 3 2 13 2 2 3 1 23 1 − 2 3 0 2 3 0 2 3 0 U230 = sgn ( 2 0 3 ) L20P3 + sgn ( 0 3 2 ) L03P2 + sgn ( 2 3 0 ) L23P0 = 0, 3 1 0 3 1 0 3 1 0 U310 = sgn ( 0 1 3 ) L01P3 + sgn ( 0 3 1 ) L03P1 + sgn ( 1 3 0 ) L13P0 = 0, 0 1 2 0 1 2 0 1 2 U012 = sgn ( 0 1 2 ) L01P2 + sgn ( 2 0 1 ) L20P1 + sgn ( 1 2 0 ) L12P0 = 1.

Not all Ukˆ are zero, hence P does not lie on L and the Pl¨ucker-Grassmann coor- 3 dinates of the plane U P R containing both P and L are U132 : U230 : U310 : ⊂ J U012 = 1 : 0 : 0 : 1 . K J− K An immediate application of the above theorem is the following criterion for intersection of two lines in the projective space P3R. Corollary 3.16. The two distinct lines L, M P3R with the Pl¨ucker-Grass- ⊂ mann coordinates L12 : L20 : L01 : L03 : L13 : L23 and M12 : M20 : M01 : M03 : J K J M13 : M23 intersect if and only if K L12M03 + L20M13 + L01M23 + L03M12 + L13M20 + L23M01 = 0. Proof. The join of two non-intersecting lines in the 3-dimensional space, is the whole space P3R. As we know, P3R has just one Pl¨ucker-Grassmann coordinate U0123. Theorem 3.15 asserts that it is not zero if the two lines are disjoint and then 3 they span the entire space P R. Otherwise U0123 is null.  Recall that the Pl¨ucker-Grassmann coordinates of a line through two points P,Q R3 are shortly written as p q : p q , where p = −−→ΘP , q = −−→ΘQ. Thus the corollary∈ asserts that the lines: LJ through× −P ,KQ and M through R, S intersect if and only if (p q) (r s) + (p q) (r s) = 0. × • − − • × Example. Take the four points: P = 0 : 2 : 0 : 1 ,Q = 2 : 0 : 0 : 1 ,R = 1 : 1 : 0 : 1 ,S = 2 : 2 : 2 : 1 . J K J K J K J − K Let L be the line through P , Q and M through R, S. The Pl¨ucker-Grassmann coordinates of L are p q : p q = 0 : 0 : 4 : 2 : 2 : 0 and the coordinates of M are r s : r s J=× 2 : 2− : 0K : 1J : 1 :− 2 . We− have K J × − K J− − − K (p q) (r s) + (p q) (r s) = 8 + 8 = 0. × • − − • × − It follows from the corollary that these two lines intersect. There is more to the above corollary. Restrict ourselves to the affine space R3, for a while. An affine line L R3 can be assigned an orientation. The two possible orientation may be encoded⊂ into line’s coordinates providing that the Pl¨ucker- Grassmann coordinates of an oriented line are unique only up to a multiplication by a strictly positive factor. The coordinates of the oriented line through P , Q (in that order) are then defined (using the previous notational convention) as p q : p q . Reversing the orientation of a line one changes the signs of the coordinates,J × − asK p q = q p and p q = (q p). This construction fails in the projective space,× but− is× correct in− the affine− world− (for further details as well as the proof of the next proposition we refer the reader to [23]). An oriented line L, that does not intersect another oriented line M, can go around it either in the clockwise or counterclockwise direction (see Figure 2.8). It turns out that the formula from Corollary 3.16 can be used to distinguish these two cases. Build: January 28, 2021 52 Projective space and quaternions

Figure 2.8. Oriented line L going around another oriented line M in the clockwise (left) and counterclockwise direction (right).

Proposition 3.17. Let L, M R3 be to distinct oriented lines with the Pl¨uc- ⊂ ker-Grassmann coordinates respectively: L12 : L20 : L01 : L03 : L13 : L23 and J K M12 : M20 : M01 : M03 : M13 : M23 . Define J K ∆(L, M) := L12M03 + L20M13 + L01M23 + L03M12 + L13M20 + L23M01. Then: (1) L goes around M in the clockwise direction if ∆(L, M) > 0; (2) L intersects M if ∆(L, M) = 0; (3) L goes around M in the counterclockwise direction if ∆(L, M) < 0. In 3D computer rendering it is often important to know whether a ray (resp. an oriented line) intersects a given triangle. Proposition 3.17 give rise to an effective line-triangle intersection test. Let C be a convex polygon contained in R3 and L a given (oriented) line. Orient all the edges of C in a consistent way. It is clear that L intersects the interior of C if and only if it goes either clockwise around all the edges or it goes counterclockwise around all the edges of C. Thus we have proved:

Corollary 3.18. If C is a convex polygon with edges E1,...,En oriented coherently, then a line L intersects the interior of C if and only if the sign of ∆(L, E ) is the same for every 1 i n. i ≤ ≤ Example. Consider a triangle T with vertices A = (2, 0, 2)T , B = (0, 4, 3)T , C = ( 2, 1, 2)T and take a line L through P = (0, 0, 0)T and Q = (0, 1, 1)T . Then the Pl¨ucker-Grassmann− − coordinates of the edges of T are

AB12 : AB20 : AB01 : AB03 : AB13 : AB23 = 8 : 6 : 8 : 2 : 4 : 1 J K J− − − − K BC12 : BC20 : BC01 : BC03 : BC13 : BC23 = 11 : 6 : 8 : 2 : 5 : 1 J K J − K CA12 : CA20 : CA01 : CA03 : CA13 : CA23 = 2 : 8 : 2 : 4 : 1 : 0 J K J− − − K and that of L are

L12 : L20 : L01 : L03 : L13 : L23 = 0 : 0 : 0 : 0 : 1 : 1 J K J − − K We compute: ∆(L, AB) = 2, ∆(L, BC) = 2, ∆(L, CA) = 10. − − − It follows from the corollary that L intersects T . Build: January 28, 2021 Projective space and quaternions 53

In practice, once we spot an intersection, we often need to find the coordinates of the intersection point. If we deal with a triangle, rather than an arbitrary convex polygon, the previous corollary can be strengthen to give this extra bit of information as follows:

Observation 3.19. Let L be an oriented affine line in R3 and T be a triangle not parallel to L with vertices A, B, C, then the barycentric coordinates (with respect to A, B, C) of the point P , where L intersects the plane containing T , are: ∆(L, BC) , ∆(L, AB) + ∆(L, BC) + ∆(L, CA) ∆(L, CA) , ∆(L, AB) + ∆(L, BC) + ∆(L, CA) ∆(L, AB) . ∆(L, AB) + ∆(L, BC) + ∆(L, CA) In particular P lies in the convex hull of A,B,C (i.e. the line intersects the triangle), when sgn ∆(L, AB) = sgn ∆(L, BC) = sgn ∆(L, CA). The proof is left as an exercise for the reader. In the previous example, the intersection point of L and T is 2 0  2  0  2 10 2 − − 0 + − 4 + −  1 = 19/7 2 2 10 2 2 10 2 2 10 − . − − − 2 − − − 3 − − − 2 19/7 Remark. In some cases Theorem 3.15 together with Theorem 3.13 leads to another method for computing the Pl¨ucker-Grassmann coordinates of an intersec- tion of two subspaces. Indeed, suppose that U = V W . Switching to the dual ∩ space we have that U ∗ is the join of V ∗ and W ∗, where the Pl¨ucker-Grassmann coordinates of the dual V ∗ (respectively W ∗) of V (resp. W ) are computed by the means of Theorem 3.13. Now, Theorem 3.15 let us compute the coordinates of U ∗ and Theorem 3.13 converts them back to the Pl¨ucker-Grassmann coordinates of U.

Example. Let the points A, B, C, P, Q R3 be the same as in the previous example. We want to compute the intersection∈ point of the line L through P and Q with the plane V containing A, B, C using the above remark. The Pl¨ucker- Grassmann coordinates of L are 0 : 0 : 0 : 0 : 1 : 1 thus its dual L∗ has the coordinates J − − K

L12∗ : L20∗ : L01∗ : L03∗ : L13∗ : L23∗ = 0 : 1 : 1 : 0 : 0 : 0 . J K J − − K On the other hand, the Pl¨ucker-Grassmann coordinates of V are

V132 : V230 : V310 : V012 = 1 : 4 : 18 : 38 . J K J− − K and so are the coordinates V ∗ : V ∗ : V ∗ : V ∗ of the point V ∗ P3R dual to the 0 1 2 3 ∈ plane V . Compute the coordinatesJ of the join PK ∗ of L∗ and V ∗ using Theorem 3.15: 1 3 2 1 3 2 1 3 2 P132∗ = sgn ( 1 2 3 ) L12∗ V3∗ + sgn ( 1 3 2 ) L13∗ V2∗ + sgn ( 2 3 1 ) L23∗ V1∗ = 0, 2 3 0 2 3 0 2 3 0 P230∗ = sgn ( 2 0 3 ) L20∗ V3∗ + sgn ( 0 3 2 ) L03∗ V2∗ + sgn ( 2 3 0 ) L23∗ V0∗ = 38, 3 1 0 3 1 0 3 1 0 P310∗ = sgn ( 0 1 3 ) L01∗ V3∗ + sgn ( 0 3 1 ) L03∗ V1∗ + sgn ( 1 3 0 ) L13∗ V0∗ = 38, 0 1 2 0 1 2 0 1 2 P012∗ = sgn ( 0 1 2 ) L01∗ V2∗ + sgn ( 2 0 1 ) L20∗ V1∗ + sgn ( 1 2 0 ) L12∗ V0∗ = 14.

Build: January 28, 2021 54 Projective space and quaternions

The intersection point P is dual to the plane P ∗, hence

P0 : P1 : P2 : P3 = P132∗ : P230∗ : P310∗ : P012∗ = 0 : 38 : 38 : 14 . J T K J K J K Thus P = (0, 19/7, 19/7) . The exercises at the end of this chapter present some more interesting applica- tions of the Pl¨ucker-Grassmann coordinates.

4. Quaternions and transform interpolation Transform interpolation is a basic but widely used method of animating com- puter-generated objects. Suppose that we are given a finite sequence of pairs (t0,T0),..., (tn,Tn), where the first entry is time and the second is a transfor- mation, assume that the ti’s form a strictly ascending sequence. We are looking for such a map Φ : R M4,4(R) that Φ(ti) = Ti for every 0 i n. In other → ≤ ≤ words, we want to smoothly pass from a transformation T0 at the moment t0, to T1 at time t1 and so on till Tn at time tn. In this section we deal with the simplest case, when we interpolate between two transforms only. The generalization to an arbitrary number of key-frames will be discussed in Chapter 5. 5 Let A0, A1 be two elements of some linear or affine space over R. We define a linear interpolation operator by the formula: lerp(A ,A ; t) := (1 t)A + tA , for t [0, 1]. 0 1 − 0 1 ∈ It is clear that lerp(A0,A1; 0) = A0 and lerp(A0,A1; 1) = A1.

Observation 4.1. Let T0, T1 be two translations by vectors v0, v1 and let MT0, MT1 be the corresponding matrices in homogeneous coordinates, then the matrix M(t) := lerp(MT ,MT ; t), for t [0, 1] 0 1 ∈ represents a translation by an intermediate vector v(t) = lerp(v0, v1; t).

Observation 4.2. Let S1, S2 be the dilatations by si = (si,x, si,y, si,z)(for i 0, 1 ) and let MS1, MS2 be the corresponding matrices in homogeneous coor- dinates.∈ { } Then the matrix M(t) := lerp(MS ,MS ; t), for t [0, 1] 0 1 ∈ corresponds to an intermediate scaling by s(t) = lerp(s0, s1; t). As simple as the above two observations are, they say that both a translation and a dilatation are handled by a direct linear interpolation of the corresponding matrices (see Figure 2.9). Let us look now at a rotation. This case is not so simple any longer. It is obvious that a weighted average of two rotation matrices does not have to represent a rotation at all, not to mention an intermediate rotation. If the axes of the two interpolated rotations coincide, the task is still quite easy. All one needs to do, is to linearly interpolate the angle of the rotation α(t) := lerp(α0, α1; t), where α0 is the angle of the first rotation and α1 denotes the angle of the second one. A problem arises when the two axes differ. A naive approach is to interpolate the Euler angles of the rotations. This can lead to quite an unexpected behavior. As we will see, the space of rotations in R3 is homeomorphic to the projective space P3R. On the other hand, the Euler angles are the triples (αX , αY , αZ ) hence the space of all the Euler angles form a cube. These two spaces are not homeomorphic. An

5The only axiom we actually need is the existence of weighted averages of every two elements.

Build: January 28, 2021 Projective space and quaternions 55

Figure 2.9. Interpolation of a translation (left) and a dilatation (right). artifact, known as a gimbal lock, occurs every time an interpolation passes through a point of discontinuity of the correspondence between Euler angles and rotations.

We explain it using a simplified example where the space of rotations is sub- stituted by an ordinary unit sphere S2 R3. Consider a function Φ : [ π, π] 2 ⊂ − × [ π/2, π/2] S that maps a latitude u and the longitude v to the point on the sphere− → sin(u) cos(v) u Φ = cos(u) cos(v) v . sin(v) An observer on the sphere has two degrees of freedom: he can move either in the east-west direction (i.e. changing u) or in the north-south direction (i.e. changing v), unless. . . he stays at one of the two poles. At the north pole every direction leads south (analogously, at the south pole every direction leads north). A gimbal lock occurred, we lost one degree of freedom. The correct way to interpolate rotations in 3D is to represent them using quaternions. First, however, we analyze the situation in two dimensions. The intuition we develop, will subsequently be applied in three dimensions. Take a x point P = R2. Rotation around the origin can be written as a map y ∈ cos α sin α x x cos α y sin α P − = − . 7→ sin α cos α · y x sin α + y cos α

x Identify the plane R2 with the field of the complex numbers C. The point R2 y ∈ corresponds to the number x + iy C. The above formula can be rephrased as ∈ P (x cos α y sin α) + i(y cos α + x sin α) = (cos α + i sin α) P. 7→ − · 2 Denote q := cos(α/2) + i sin(α/2), then q = cos α + i sin α and the formula can be written as P qP q. In other words, the rotation by an angle α around the origin can be identified7→ with multiplication on both sides by a complex number with the phase α/2. α α Now, consider two angles α0 and α1. Let q0 := cos( 0/2) + i sin( 0/2) and α α q1 := cos( 1/2) + i sin( 1/2) be two complex numbers corresponding to these angles. As noted earlier, the most natural way to interpolate between two rotations in the Build: January 28, 2021 56 Projective space and quaternions plane is to linearly interpolate their angles: α(t) α(t) (4.3) α(t) := lerp(α , α ; t), q(t) := cos + i sin 0 1 2 2 We identified C with the plane R2, hence we can treat the complex numbers q0, q1, q(t) as two-dimensional unit vectors. The vectors q0 and q1 are linearly dependent only in two cases—when their are either equal or opposite. The first case is obvious, the second means that α0/2 = α1/2 π and so α = α 2π. Thus ± 0 1 ± in both cases, the numbers q0, q1 describe exactly the same rotation and the in- terpolation is consequently void. Hence, without loss of generality, we may assume that q0, q1 are linearly independent. Therefore, they form a basis of C over the reals. Write their coordinates as columns of a matrix   cos(α0/2) cos(α1/2) M = . sin(α0/2) sin(α1/2)

The determinant of M equals det M = cos(α0/2) sin(α1/2) cos(α1/2) sin(α0/2) = α1 α0  − sin −2 . In order to convert the coordinates from the canonical basis 1, i to our basis q , q we need the inverse of M: { } { 0 1}  α α  1 1 sin( 1/2) cos( 1/2) M − =  α − α . sin (α1 α0)/2 sin( 0/2) cos( 0/2) − − (α1 α0) Denote ϕ := − /2, it is the measure of the angle between the two vectors q0 and q1. We want to express the number q(t), representing the intermediate rotation, as a linear combination of q0 and q1. To this end we write:

 α α   1  1 1 sin( 1/2) cos( 1/2) cos /2 lerp(α0, α1; t) M − q(t) = α − α  = · sin ϕ sin( 0/2) cos( 0/2) · sin 1/2 lerp(α , α ; t) − 0 1 α1 α0 α1  α1 α0 α1  1  sin( ) cos (1 t) + t cos( ) sin (1 t) + t  = 2 − 2 2 − 2 − 2 2 = sin ϕ sin( α0 ) cos(1 t) α0 + t α1  + cos( α1 ) sin(1 t) α0 + t α1  − 2 − 2 2 2 − 2 2  α0 α1  1 sin (t 1) − = − 2 . α1 α0  sin ϕ sin t −2 All in all, we have sin (1 t)ϕ) sin(tϕ) q(t) = q − + q . 0 sin ϕ 1 sin ϕ Observe that the sign of ϕ does not alter the result, since ϕ occurs in both the numerator and the denominator. Thus we may use ϕ in place of ϕ in the above formula. The absolute value ϕ can be easily computed| | from the dot product as q q = cos ϕ . Define a spherical| | analog of lerp by the formula 0 • 1 | | sin(1 t) ϕ ) sint ϕ ) slerp(A ,A ; t) := A − | | + A | | , 0 1 0 sin ϕ 1 sin ϕ | | | | where cos ϕ = A0 A1. The intermediate rotation is q(t) = slerp(q0, q1; t). Observe that this last| | formula• for q(t) uses only the trigonometry, not the complex arith- metic. Hence one can use it in every 2-dimensional real space with the dot-product. An alternative formula for slerp, this time using the complex multiplication, is pro- vided by the following proposition.

Proposition 4.4. Let q0, q1 C be two complex numbers and let t R, then ∈ ∈ 1t slerp(q , q ; t) = q q− q . 0 1 1 0 · 0 Build: January 28, 2021 Projective space and quaternions 57

α α α α Proof. Let q0 = cos( 0/2) + i sin( 0/2) and q1 = cos( 1/2) + i sin( 1/2). Using Eq. (4.3) we write slerp(q , q ; t) = cos(1 t) α0 + t α1  + i sin(1 t) α0 + t α1  = 0 1 − 2 2 − 2 2 = cos(1 t) α0  cost α1  sin(1 t) α0  sint α1 + − 2 2 − − 2 2 α0  α1  α0  α1  + i sin (1 t) 2 cos t 2 + i cos (1 t) 2 sin t 2 =  −  −  = cos(1 t) α0  + i sin(1 t) α0  cost α1  + i sint α1  . − 2 − 2 2 2 1 t t Use the de Moivre’s formula to rewrite the last line as q0− q1. Rearranging the 1t terms we get q q− q . 1 0 · 0  In the above discussion both rotations where limited to the same plane. They had the same axis. If, however, the two axes differ, we need to substitute a higher dimensional algebra in place of the complex numbers. For rotations in three di- mensional space we need quaternions. Definition 4.5. The quaternion algebra is a 4-dimensional algebra H over the reals generated by elements 1, i, j, k satisfying the following conditions: 1i = i1 = i, 1j = j1 = j, 1k = k1 = k; • i2 = j2 = k2 = 1; • ij = ji = k. − • − Notice that the last axiom forces the multiplication of quaternions to be non- commutative! The quaternion algebra may seem a bit weird at first glance but we shall see soon that it is in fact very natural. We still need to show that the above definition is not void. To do this we construct an explicit model of H.

Observation 4.6. Consider the 4-dimensional matrix algebra M2,2(C) over the complex numbers consisting of all the 2 2 matrices with complex coefficients. It can be treated as an 8-dimensional algebra× over the reals. The matrices: 1 0  0 i 0 1  i 0 1 = , i = , j = , k = 0 1 i −0 1− 0 −0 i − satisfy the axioms of the above definition. Consequently, the subalgebra lin(1, i, j, k) of M2,2(C) is a model for H. An element of H is called a quaternion. It is uniquely written as a linear combination of 1, i, j and k.

Definition 4.7. Let q = q0 + q1i + q2j + q3k H be an arbitrary quaternion. ∈ the conjugate of q is q := q0 q1i q2j q3k; • the norm of q is N(q) := q2 +− q2 +−q2 +−q2 = qq. • 0 1 p2 3 the euclidean norm of q is q := N(q). • k k Observe that there is a canonical embedding R , H of the reals6 into the quaternion algebra sending the x to the quaternion→ x 1 + 0i + 0j + 0k. · In the rest of this section we will identify the reals with the subalgebra R 1 of H. · This way we may write the quaternion algebra as a direct sum H = R lin(i, j, k). ⊕ Denote the completion lin(i, j, k) of R by V. It is a 3-dimensional

6 There are also three obvious embeddings of C into H defined by x + iy 7→ x1 + yi + 0j + 0k, x + iy 7→ x1 + 0i + yj + 0k and x + iy 7→ x1 + 0i + 0j + yk.

Build: January 28, 2021 58 Projective space and quaternions over the reals and so it is isomorphic with R3. Elements of V are called pure quaternions. A quaternion q = q01 + q1i + q2j + q3k may be expressed as a pair (q0, v) consisting of a “real part” q0 and a “pure part” q1i + q2j + q3k, represented T 3 by a vector v = (q1, q2, q3) . Our aim is to describe a rotation in R ∼= V in terms of quaternion multiplication. The first step is to express the multiplication using the dot- and cross-products7.

Observation 4.8. If q = (a, u), r = (b, v) R V are two quaternions, then ∈ ⊕ qr = (ab u v, u v + av + bu). − • × Corollary 4.9. If u, v V are two pure quaternions, then ∈ uv = ( u v, u v). − • × The quaternion algebra is not commutative, but beside this single glitch it strongly reassembles a field. In particular H is a division algebra, which means that every non-zero element is invertible in H. Proposition 4.10. Let q H be a quaternion, then ∈ N(q) = 0 if and only if q = 0; • if q = 0, then q is invertible and its inverse equals 1/N(q) q. • 6 · Proof. A sum of squares of real numbers is zero if and only if all these numbers are zero. This proves the first point. To prove the second one, observe that qq = N(q). It follows that q 1 q = 1. · N(q)  Proposition 4.11. Let q H be a quaternion. Then qr = rq for every quater- ∈ nion r H if and only if q R. ∈ ∈ In a fancy language, the above proposition says that H is a central algebra.

Proof. If q R, then q = q01 + 0i + 0j + 0k and for every quaternion r = ∈ r01 + r1i + r2j + r3k we have

qr = (q0r0)1 + (q0r1)i + (q0r2)j + (q0r3)k = rq.

Conversely, assume that q = (q0, u) R V commutes with every quaternion ∈ ⊕ r = (r0, v) R V. This means that u v = v u for every vector v V. But the cross-product∈ ⊕ is anti-symmetric and× so u v×= v u Thus v u =∈ v u for every v. This means that v u vanishes for× every−v.× This is possible× only− × if u × is a zero-vector. Consequently q = q01 R. ∈  With every non-zero quaternion q H 0 we associate a map Rq : H H ∈ \{1 } → defined by the formula Rq(r) := q r q− . Observe that Rq is a linear map. · · Indeed take any two quaternions p, r H and two scalars a, b R, then using Proposition 4.11 we write ∈ ∈ 1 1 1 Rq(ap + br) = q(ap + br)q− = aqpq− + bqrq− = aRq(p) + bRq(r). Our first task is to show that V is an invariant subspace of this map (i.e. V is mapped to itself).

Lemma 4.12. If q H 0 and v V, then Rq(v) V. ∈ \{ } ∈ ∈ 7Do not confuse the quaternion multiplication qr with the dot product q • r.

Build: January 28, 2021 Projective space and quaternions 59

Proof. Take a non-zero quaternion q = (a, u) R V and a pure quaternion v = (0, v). It follows from Proposition 4.10 that ∈ ⊕

1 1 q v q− = (a, u) (0, v) (a, u). · · N(q) · · · − We may omit the scalar factor 1/N(q) as it cannot move a vector outside V. Using Observation 4.8 we write the first product as (a, u) (0, v) = ( u v, u v + av). · − • × Multiply the result by (a, u) and examine the real part. Observation 4.8 asserts that the real part of ( u −v, u v + av) (a, u) equals au v + (u v + av) u = − • × · − − • × • 1 (u v) u, but u is orthogonal to u v hence (u v) u = 0. Consequently q v q− × • × × • · · is pure. 

It follows from the lemma that the restriction Rq V is a linear endomorphism of V. Observe that the map is invariant under the multiplication of q by scalars. Lemma 4.13. If q is a non-zero quaternion and a R is a non-zero scalar, ∈ then Rq = Raq. Proof. Use Proposition 4.11 to write 1 1 1 Raq = (aq)v(aq)− = (aa− )(qvq− ) = Rq(v)  Quaternions, like the complex numbers, may be expressed in a polar form. Indeed, take a quaternion q = (a, v) R V. Write it as ∈ ⊕  a v v  q = q , k k . k k q q · v k k k k k k The squares of a/ q and v / q sum up to the unity: k k k k k k  a 2  v 2 1 1 + k k = a2 + v v = N(q) = 1. q q N(q) • N(q) k k k k Therefore, one can find such an angle ϕ [0, 2π) that ∈ a v = cos ϕ and k k = sin ϕ. q q k k k k Normalize v, takingv ˆ := v/ v and express the quaternion q in a polar form k k q = q cos ϕ, vˆ sin ϕ. k k Now, having the above representation at our disposal, we may present a geometric interpolation of the map Rq.

Theorem 4.14. For any quaternion q H, q = q (cos ϕ, v sin ϕ), the map ∈ k k Rq : V V is the rotation around v by an angle 2ϕ. → Proof. Lemma 4.13 asserts that one may scale q without altering the map Rq. Hence, without loss of generality, we may assume that q is a unit quaternion 1 and so its inverse q− is just its conjugate q = (cos ϕ, v sin ϕ). Every vector u V can be uniquely decomposed into a sum u = u + u ,− with u parallel to v and∈u k ⊥ k ⊥ orthogonal to v. Thus, since Rq is a linear map, it suffices to prove the assertion for v and any vector w perpendicular to v. Build: January 28, 2021 60 Projective space and quaternions

Focus first on v. The image of v under Rq can be computed using Observa- tion 4.8 as follows: 2 2  Rq(v) = (cos ϕ, v sin ϕ)(0, v)(cos ϕ, v sin ϕ) = 0, v(sin ϕ + cos ϕ) = (0, v). − Thus v, and consequently the whole line lin(v) spanned by it, is fixed by Rq. Take now a vector w perpendicular to v. Without loss of generality we may assume that w is a unit vector. Let u := v w be the cross-product of v and w. It is again a unit vector, since both v and w×are. Consequently the basis v, w, u is orthonormal. Thus, both the dot products u v and w v vanish. Compute{ the} • • image of w under the map Rq:

Rq(w) = (cos ϕ, v sin ϕ) (0, w) (cos ϕ, v sin ϕ) = · · − = (0, u sin ϕ + w cos ϕ) (cos ϕ, v sin ϕ) = · − = (u v) sin2 ϕ + (w v) sin ϕ cos ϕ, • • (u v) sin2 ϕ (w v) sin ϕ cos ϕ + u sin ϕ cos ϕ + w cos2 ϕ = − × − × = (0, w sin2 ϕ + 2u sin ϕ cos ϕ + w cos2 ϕ) = − = (0, w cos(2ϕ) + u sin(2ϕ)).

Therefore Rq restricted to the plane orthogonal to v is a rotation by the angle 2ϕ. It follows from the linearity that Rq : V V is a rotation around v, as claimed. →  Take now two unit quaternions q, r H, say q = (cos ϕ, v sin ϕ) and r = ∈ (cos ψ, u sin ψ). Then Rq is the rotation around v by 2ϕ and Rr is the rotation around u by 2ψ. The composition of the two rotations is   1 1 Rr Rq (w) = rq w q− r− = Rrq(w). ◦ Therefore, the composition of rotations corresponds to multiplication of (unit) quaternions. A unit sphere S3 = q H : N(q) = 1 in H forms a multiplica- tive group as the product of unit quaternions{ ∈ and the inverse} of a unit quaternion are again unit quaternions. It follows that we have proved:

3 Theorem 4.15. The map q Rq from the unit sphere S H to the group of rotations is a group epimorphism.7→ ⊂

Observe that the inverse image of a rotation by an angle ϕ around some unit vector v consists of exactly two quaternions: (cos(ϕ/2), v sin(ϕ/2)) and (cos(ϕ/2 + π), v sin(ϕ/2 + π)) = (cos(ϕ/2), v sin(ϕ/2)). They form antipodal points on the sphere and we know from− the first chapter what we get when all antipodal points are glued together. Corollary 4.16. The set of rotations has a structure of the real projective space P3R. In previous sections every geometric transformation was written in a matrix form. We should rephrase in a matrix notation, what we did with quaternions. The left quaternion multiplication u qu, as well as the right quaternion multiplication u uq are both linear maps. Hence,7→ they can both be expressed in a matrix form 7→ T  using homogeneous coordinates. Let q = q0 + q1i + q2j + q3k = q0, (q1, q2, q3) be a fixed unit quaternion. The left multiplication 0, (x, y, z)T  q 0, (x, y, z)T  7→ · Build: January 28, 2021 Projective space and quaternions 61 can be expressed as: x  q q q q  x 0 − 3 2 1 y  q3 q0 q1 q2 y z  q q −q q  z   7→  2 1 0 3 ·  . 0 −q q q q 0 − 1 − 2 − 3 0 L R Denote the above matrix by Mq . In the same way, define the matrix Mq of the right multiplication 0, (x, y, z)T  0, (x, y, z)T  q: 7→ · x  q q q q  x 0 3 − 2 1 y  q3 q0 q1 q2 y z −q q q q  z   7→  2 1 0 3 ·  . 0 q −q q q 0 − 1 − 2 − 3 0 The map Rq : V V is the composition of the right multiplication by q with the left multiplication→ by q. Consequently, in the matrix notation, it can be written R L as v Mqv, where Mq = Mq Mq . (The multiplication in H is associative, hence 7→ R L L R the matrices Mq and Mq commute and so we could also write Mq = Mq Mq .) It follows that  2 2 2 2  q0 + q1 q2 q3 2q1q2 2q0q3 2q1q3 + 2q0q2 0 − − 2 2 − 2 2  2q1q2 + 2q0q3 q q + q q 2q2q3 2q0q1 0 (4.17) M = 0 1 2 3 q  2q q 2q q 2−q q + 2q −q q2 q2 − q2 + q2 0  1 3 0 2 2 3 0 1 0 1 2 3 . −0 0− − 0 1

Write q in the polar form q = (cos ϕ, v sin ϕ) with cos ϕ = q0 and v sin ϕ = T T (q , q , q ) . For 1 i 3 denoteq ˆ := qi/sin ϕ. Then v = [ˆq , qˆ , qˆ , 0] and 1 2 3 ≤ ≤ i 1 2 3 clearly v = 1. Rewrite the elements on the main diagonal of Mq using the sine and cosine.k k For example the first element can be expressed as q2 + q2 q2 q2 = 2q2 + 2q2 1 = 0 1 − 2 − 3 0 1 − 2 2 q1 2 = (2q0 1) + 2 2 2q0 = − 1 q0 − − 2 2 q1 2 = (2 cos ϕ 1) + 2 2 2 (2 2 cos ϕ) = − q1 + q2 + q3 − = cos(2ϕ) +q ˆ21 cos(2ϕ). 1 − Analogously one rewrites the other entries. The elements off the main diagonal are even simpler to deal with. Take for example 2q q 2q q : 1 2 − 0 3 q1q2 2 q3 2q1q2 2q0q3 = 2 (2 2q0) 2q0 v = − 1 q0 − − v k k q− q k k q = 1 2 (2 2 cos ϕ) 3 2 cos ϕ sin ϕ = v v − − v k k k k k k =q ˆ qˆ 1 cos(2ϕ) qˆ sin(2ϕ) 1 2 − − 3 and so on. All in all, the matrix Mq takes the form  2  c +q ˆ1(1 c)q ˆ1qˆ2(1 c) qˆ3s qˆ1qˆ3(1 c) +q ˆ2s 0 − −2 − − qˆ1qˆ2(1 c) +q ˆ3s c +q ˆ2(1 c)q ˆ2qˆ3(1 c) qˆ1s 0 qˆ qˆ (1 − c) qˆ s qˆ qˆ (1 c)− +q ˆ s c +q ˆ−2(1 −c) 0  1 3 2 2 3 1 3 , −0− − 0 0− 1 Build: January 28, 2021 62 Projective space and quaternions where c = cos(2ϕ) and s = sin(2ϕ). This is just the matrix of a rotation by an T angle 2ϕ around [ˆq1, qˆ2, qˆ3, 0] from Proposition 2.8. Observe that Eq. (4.17) provides us with a direct method for converting a rotation from a quaternion form to a matrix form. Conversely, in order to convert a rotation matrix to a quaternion, one needs to find the axis and the angle of the rotation. Observation 4.10 explains how to do this. Our original motivation for introducing quaternions was to find a way to in- terpolate rotations. Now, we can finally achieve this goal. Let q0 and q1 be two unit quaternions representing rotations at time t = 0 and t = 1, respectively. We need to find the quaternion of an intermediate rotation at some t (0, 1). Consider ∈ a plane lin(q0, q1) spanned by these two quaternions. The intersection of the unit sphere S3 V with this plane is a unit circle. Select a quaternion q(t) lying on ⊂ the arc connecting q0 and q1 and dividing the arc into two subarcs with lengths proportional respectively to t and 1 t. Since we have reduced the problem to a plane, thus we may apply the trigonometric− methods derived earlier in this section. Consequently q(t) := slerp(q0, q1; t) and we have proved the following result.

Theorem 4.18. Let R0, R1 be two rotations at time t = 0 and t = 1, respec- tively. Further let q0 = cos ϕ0+v0 sin ϕ0 and q1 = cos ϕ1+v1 sin ϕ1 be the associated quaternions. The intermediate rotation at time r (0, 1) is then represented by a quaternion ∈

q(t) := slerp(q0, q1; t).

π Example. Consider two rotations: first at time t0 = 0 rotate by α0 = /4 T T around ε = (0, 1, 0) , then at t = 1 rotate by α = π/4 around ε = (1, 0, 0) . 2 1 1 − 1 Our goal is to find the intermediate rotation at t = 1/2. Write our border conditions as quaternions: √2 √2 √2 √2 q = + j, q = i. 0 2 2 1 2 − 2 The angle between the two quaternions (treated as 4-dimensional vectors) is ϕ = | | arccos(q q ) = π/3. Hence the intermediate rotation (still in a quaternionic form) 0 • 1 is q(1/2) = slerp(q , q ; 1/2) = √6/3 √6/6 i + √6/6 j. It follows that the angle of 0 1 − · · the intermediate rotation equals arccos(√6/3) 0.615 and the axis of the rotation is spanned by (1, 1, 0)T . ≈ − Exercises (1) Check that the projective automorphism of Example 1 is affine in the 2 plane V0 ∼= R . (2) Shift lenses are used in photography to compensate perspective correction by shifting the viewport. Construct a perspective transformation where the center of the viewport is shifted away from the viewing direction. (3) Prove Observation 3.19. 3 (4) Show that two projective lines L1,L2 P R intersect if and only if they ⊂ duals L1∗ and L2∗ intersect. (5) Explain why remark on page 53 cannot be used to find the intersection of two lines in the 3-dimensional projective space. (6) Let L be a line with the Pl¨ucker-Grassmann coordinates p : q . Show p that P = p q : q q is the point of L closest to the origin andJ Kp p/q q • • is the distanceJ × from• LK to the origin. Build: January 28, 2021 Projective space and quaternions 63

(7) Use Theorem 3.15 to express the Pl¨ucker-Grassmann coordinates of the plane containing a given line and a point not on that line in terms of the cross product and vector difference in the spirit of Observation 3.9 and Proposition 3.10. Bibliographic notes TO DO

Build: January 28, 2021 64 Projective space and quaternions

Figure 2.10. A photo taken with a camera tilted upward (top) and the same photo but with perspective correction applied (bot- tom).

Build: January 28, 2021 Part 2

Geometry of curves

CHAPTER 3

Cubic curves

1. Introduction This chapter introduces the notion of parametric curves. Here we concentrate on the simplest, but at the same time most popular type, that is the polynomial cubic curves, postponing the discussion on arbitrary degree curves to the next chapter. In full generality, a parametric curve is a mapping from a given interval n [t0, t1] to a subset of an affine space R . The class of curves defined this way is, however, to broad to be useful in practice, especially when keeping graphical applications in mind. Thus, we need to narrow the definition. In order to simplify T the wording, let us notice that a N-tuple of real polynomials (f1, . . . , fN ) with N fi R[t] can be treated as a polynomial with coefficients in R . Therefore, a vector consisting∈ of polynomials will again be called a polynomial.

Definition 1.1. A parametric polynomial curve is a pair (f, C) consisting of a polynomial f RN [t] together with the image C = f([0, 1]) of the unit interval. ∈

Take any proper interval [t0, t1] R, there is an affine invertible transformation ⊂ τ : R R sending [t0, t1] onto [0, 1]. Composing f with τ one can define a → parametric curve with any given domain [t0, t1] for some t0 < t1. A curve (f, C) has a proper parametrization, when f : R RN is injective everywhere but in a finite number of points. That is, the parametrization→ is proper if and only if the set t R f(t) = f(s) for some s R, s = t is finite. In other words, a properly{ parametrized∈ | curve may possibly∈ cross6 itself} but not overlap. Take care to notice that we consider f here on the whole line R, not just on the unit interval. In what follows all the parametric curves will be silently assumed to be properly parametrized. A polynomial of degree n is uniquely determined by its values in n + 1 distinct points. Therefore, in order to model a complex shape using a single polynomial curve, one would have to confine himself to polynomials of very high degrees. Unfor- tunately this is not very convenient since high-degree polynomials tend to oscillate wildly between the interpolation points (see Figure 3.1). Consequently, high-degree curves are generally not very intuitive for a direct on-screen manipulation. Another reason to limit the degree is the time complexity of computations. It rises with the degree of the curve. One can avoid the above obstacles using piecewise polynomial curves, instead.

Definition 1.2. A pair (f, C) consisting of a function f : [0, 1] RN and the image C = f([0, 1]) of the unit interval is called a polynomial spline →(or a piecewise polynomial curve) if there are numbers 0 = t < t < . . . < t = 1 such that for 0 1 n every 1 i n the restriction f is a polynomial function. ≤ ≤ [ti−1,ti] Build: January 28, 2021 68 Cubic curves

Figure 3.1. Lagrange curve of degree 7 and a Catmull-Rom cubic spline interpolating the same set of points.

It follows that a spline (f, C) consists of a finite number of segments (fi,Ci) :=  f [ti−1,ti], f([ti 1, ti]) and each of them is a polynomial curve. Every segment has two obvious parametrizations.− One is the global parametrization inherited from the spline, where T runs through [ti 1, ti]. And the other is the local parametrization (T − t ) defined by the formula t := i−1 /(ti ti−1). The parameter t varies from 0 − − to 1. The (global) parametrization of the spline (f, C) is called uniform if all the intervals [ti 1, ti] have the same length. Otherwise the parametrization is said to be non-uniform− . In the rest of this chapter we shall simplify the notation, denoting a curve (f, C) by a single letter C. Moreover, in order to make the exposition easier to digest, we concentrate entirely on curves in the 3-dimensional space R3. This restriction is introduced for the readers convenience only, as all the discussion could be raised to an arbitrary dimension N. We let the reader work-up the details of the general case. T Take a curve C = x(t), y(t), z(t) and let d N be a common bound for the ∈ degrees of the polynomials x, y, z R[t]. The linear space R[t]d of polynomials of ∈ degree not exceeding d has dimension d + 1. Let B = b0, . . . , bd be a fixed basis T { } of R[t]d. A point P = C(t) = x(t), y(t), z(t) on the curve C corresponding to some parameter t [0, 1] can be written as ∈ x b (t) + + x b (t) x  x  x  0 0 ··· d d 0 1 d P = y0b0(t) + + ydbd(t) = y0 b0(t) + y1 b1(t) + + yd bd(t), z b (t) + ··· + z b (t) z z ··· z 0 0 ··· d d 0 1 d where xi, yi, zi are the coordinates of the polynomials x, y, z with respect to the T 3 basis B. Denoting Pi := (xi, yi, zi) R we can abbreviate the above formula to ∈ d X P (t) = P b (t). i · i i=0

The points P0,...,Pd (i.e. the coordinates of C with respect to the given basis) are called the control points of C. Connecting them with line segments one builds the control polyline of C. Subsequently we shall write C(P0,...,Pd) to denote a curve C with control points P0,...,Pd. The basis B can be selected in many ways each resulting in a different repre- sentation of curves. Nevertheless, the are some common restriction that we wish to impose on all the representations. First of all, we want every representation to Build: January 28, 2021 Cubic curves 69 be affinely invariant (see Definition 1.3.3). Moreover, we would like the shape of the curve to depend “intuitively” on the positions of its control points. The first requirement is of course simpler.

Proposition 1.3. Let d N be a fixed integer. The basis B = b0, . . . , bd ∈ { } of the space R[t]d of polynomials of degree d give rise to the affinely invariant ≤ representation of curves if and only if the elements of B sum up to the unity (i.e. b + + b 1). 0 ··· d ≡ Proof. Assume that the elements of B sum to 1. Fix a parameter t [0, 1] ∈ and take an affine transformation T : R3 R3. We know that d → d X X C(t) = Pibi(t) and bi(t) = 1. i=0 i=0

It follows that P = C(t) is the barycenter of P0,...,Pd with weights b0(t), . . . , bd(t). An affine transformation preserves the barycenters, hence d X T (P ) = T (Pi)bi(t), i=0 as desired. Conversely, suppose that the representation is affinely invariant but the sum of the polynomials b0, . . . , bd is not 1. Take a parameter t0 [0, 1] for which Pd 3 3 ∈ bi(t0) = c = 1. Let T : R R be a translation of the 3-dimensional space i=0 6 → R3 by some non-zero vector v. Fix a point P R3 and consider a curve C(P,...,P ) with all the control points equal P . The representation∈ is affinely invariant, thus d  X T C(t0) = T (P )bi(t0). i=0

The left-hand-side of the above equation is just C(t0) + v while the right-hand-side equals d X (P + v)bi(t0) = C(t0) + cv. i=0 But c = 1 and so C(t ) + v = C(t ) + cv which contradicts our assumption that 6 0 6 0 the representation is affinely invariant.  Once we are done with the affine invariance, we can look into the “intuitiveness” of a representation. It cannot be strictly defined but one aspect is provided by the following property which we will require for most (but not all) representations discussed in this chapter. Definition 1.4. We say that a curve representation has the convex hull prop- erty if every curve is contained in the convex hull of its control points: 3 C(P0,...,Pd) conv(P0,...,Pd) for every P0,...,Pd R . ⊂ ∈ Figure 3.2 shows two curve representations, the first one has the convex hull property while the second does not.

Proposition 1.5. Let B = b0, . . . , bd be a basis of R[t]d defining an affinely invariant curve representation. The{ representation} has the convex hull property if and only if all the polynomials bi are non-negative on the unit interval [0, 1]. Build: January 28, 2021 70 Cubic curves

Figure 3.2. Curve representations: with (left) and without (right) the convex hull property

Proof. Fix a curve C = C(P0,...,Pd). The representation is affinely invari- ant, hence for every value of the parameter t [0, 1] the point C(t) on the curve is ∈ the weighted average of the control points P0,...,Pd with weights b0(t), . . . , bd(t) summing up to 1. All the weights are non-negative by the assumption, therefore C(t) is a convex combination of the control points. Thus the representation has the convex hull property. Conversely suppose that the representation has the convex hull property but b (t ) = c < 0 for some 0 i d and some parameter t [0, 1]. Take a curve i 0 ≤ ≤ 0 ∈ C = C(P0,...,Pd) with control points defined in the following manner: 0 1 P0 = = Pi 1 = Pi+1 = = Pd = 0 and Pi = 1 . ··· − ··· 0 1

T It follows that C(t0) = (c, c, c) has all negative coordinates and so it does not belong to the convex hull of the control points which is a line segment with endpoints T T (0, 0, 0) and (1, 1, 1) .  Interpolation is another term that comes under the keyword “intuitiveness”. We say that a representation has the interpolation property, if there is an index 0 i d and a (fixed) value t [0, 1] such that for every possible choice of the ≤ ≤ 0 ∈ control points P0,...,Pd the curve C = C(P0,...,Pd) satisfies C(t0) = Pi. It is clear that this is equivalent to the condition bi(t0) = 1. As it has been already mentioned above, this chapter is fully devoted to curves of degree three, which are most often used in practice. The reasons for their pop- ularity are numerous. On one hand, degree three is low enough to avoid the in- conveniences of high degrees described earlier. On the other hand, the degree of the spline cannot be too low either. Splines of degree one, are just polylines and as such cannot be used to model smooth shapes. Degree two may still be too low for many real-life application, since two conic segments cannot be connected with C2-continuity unless they already form two arcs of one common conic curve. Degree three turns out to be a convenient compromise. The set R[t]3 of all the real polynomials of degree not exceeding three forms a 4-dimensional vector space over the field R of the reals. This space is spanned by the power basis t3, t2, t, 1 . { } A polynomial cubic curve C = C(Q0,Q1,Q2,Q3) can be written in the form t3 t2 C(t) = (Q0,Q1,Q2,Q3)   . ·  t  1 Build: January 28, 2021 Cubic curves 71

Unfortunately the curve representation induced by the power basis is not affinely invariant (we encourage the reader to check this on some explicit examples). What’s more, the placement of the control points determines the shape of the curve in hardly intuitive way. Thus, we have to look for other bases of R[t]3 better suited for our needs. Let B = b , b , b , b be such a basis, write the coefficients of b ’s { 0 1 2 3} i as the rows of a matrix MB. The curve C can be written in the matrix form as t3 t2 C(t) = (P0,P1,P2,P3) M   , · B ·  t  1 where P0,P1,P2,P3 are the control points of C in the representation induced by the basis B. As we see from the above discussion, a single segment is fully described by its four control points P0, P1, P2, P3 and a fixed matrix MB GL4(R). Thus, in general, a spline consisting of a certain number of segment could∈ be described by a sequence of independent quadruples of control points, one for each segment. (i) (i) (i) (i) Say P0 , P1 , P2 , P3 might be the control points of the i-th segment. In practice, however, it is more convenient when two consecutive segments have some of their control points in common (for example the last control point of the previous segment can be the first control point of the next segment). If there is a number (i) (i+1) c 1, 2, 3 such that P4 c+j = Pj for every i, j, then we say that, in the ∈ { } − curve representation induced by the basis B, c control points are shared. One obvious advantage of sharing control points is that the memory consumption in a computer implementation is reduced. Instead of using 4 (number of segments) control points, we need only (4 c) (number of segments)× + c of them. Another advantage, which we shall soon− discover,× is the easier control of continuity of the spline. For some bases, sharing the control points ensures that two consecutive segments join smoothly with a desired continuity. In some cases we want the spline to form a closed loop with the endpoints joining smoothly (e.g. a circle). This can be done by sharing the control points not only between the neighboring segments but between the initial and terminal ones, too. Splines in which the first segment shares some control points with the last one are called periodic. A periodic spline C can be (improperly) parametrized by a parameter t varying throughout the whole R with C(t) = C(t t ). In order to represent a periodic spline consisting of n segments sharing c control− b pointsc between consecutive segments one needs only (4 c) n control points. The matrix representation of cubic− curves× leads to one more striking observa- tion. Proposition 1.6. The curve representation given by a basis B is affinely in- variant if and only if the sums of columns of MB are: 0, 0, 0, 1.

Proof. Observe that the sums of columns of MB are the coefficients of the sum b0 + b1 + b2 + b3 and use Proposition 1.3.  2. B´eziersplines First representation of parametric cubics we discuss is the B´ezierone. This is the type of curves that is most often used in real-life applications. Recall that, a single segment C of a parametric cubic is controlled by the position of its four Build: January 28, 2021 72 Cubic curves

P1

P0 P2 P3

Figure 3.3. Control points of a B´eziercubic curve. control points. In the B´ezierrepresentation, the shape of the segment is determined as follows: P0 is the initial point of the segment corresponding to the parameter t = 0, while P3 is the terminal point corresponding to t = 1. The two remaining control points describe the tangents to the curve at the two endpoints, so that −−−→P0P1 equals one third of the derivative of C at P0 and −−−→P2P3 is one third of the derivative 3 3 2 at P3 (see Figure 3.3). Let C R [t] be a cubic polynomial C = at + bt + ct + d ∈ with the coefficients a, b, c, d R3. The above conditions can be written as a system of simultaneous equations: ∈  P0 = C(0) = d  3(P P ) = C0(0) = c 1 − 0 3(P P ) = C (1) = 3a + 2b + c  3 2 0  − P3 = C(1) = a + b + c + d. Solve it for a, b, c, d to get a  1 3 3 1 P  − − 0 b  3 6 3 0 P1   =  −    c  3 3 0 0 · P2 − . d 1 0 0 0 P3 The resulting matrix is symmetric. Transposing the above equation we arrive at the desired formula:  1 3 3 1 t3 − −  3 6 3 0 t2 C(t) = (P ,P ,P ,P ) 0 1 2 3  3− 3 0 0  t  ·   ·  . −1 0 0 0 1

Definition 2.1. The B´ezierrepresentation of parametric cubics is given by the matrix  1 3 3 1 −3 6− 3 0 M :=   BE´  3− 3 0 0  . −1 0 0 0 An immediate consequence of Proposition 1.6 is the following observation: Observation 2.2. B´ezierrepresentation is affinely invariant. Build: January 28, 2021 Cubic curves 73

1 1 1 1

0 1 0 1 0 1 0 1

Figure 3.4. Graphs of polynomials from the B´ezierbasis.

The B´ezier basis BBE´ consists of the following polynomials: b (t) = (1 t)3, b (t) = 3(1 t)2t, 0 − 1 − b (t) = 3(1 t)t2, b (t) = t3. 2 − 3 3 i 3 i In a short form we write bi(t) = i t (1 t) − . Figure 3.4 shows the graphs of all − i 3 i four polynomials. Observe that for t [0, 1] both t and (1 t) − are non-negative. ∈ − It follows that bi(t) 0 for every 0 i 3 and every t [0, 1]. Thus we conclude from Proposition 1.5:≥ ≤ ≤ ∈ Corollary 2.3. B´ezierrepresentation has the convex hull property. Consider now a B´ezierspline consisting of a number of cubic segments. We (i) (i) (i) already know that 3 (P1 P0 ) is the derivative of the segment Ci at P0 with respect to the local ·parameter− t. Consider now a global parametrization of the whole spline C and suppose that i-th segment corresponds to the global parameter T ti−1 T running through the interval [ti 1, ti]. Then t = − and the chain rule for − ti ti−1 the derivative says that −

dCi 3 −−−−−→(i) (i) (2.4) = P0 P1 . dT T =ti−1 ti ti 1 − − Analogously for the other endpoint

dCi 3 −−−−−→(i) (i) (2.5) = P2 P3 . dT T =ti ti ti 1 − − Every single segment, being defined by a polynomial, is C∞-smooth. Hence the smoothness of the whole spline depends entirely on how the consecutive segments join together. To ensure continuity (i.e. C0 class), the beginning of the successive (i) (i+1) segment must meet the end of the preceding one. Therefore we have P3 = P0 for every i (see Figure 3.5). In particular, in B´ezierrepresentation two consec- utive segments share one control point. It is also quite easy to give a necessary and sufficient condition for two segments to join with C1-continuity. The deriva- (i) (i+1) tives of the two segments at their common point P3 = P0 equal respectively 3 (P (i) P (i)) and 3 (P (i+1) P (i+1)). The two segments join with C1- ti ti−1 3 − 2 ti+1 ti 1 − 0 continuity− if and only if these− two vectors agree. In particular for uniform splines we have:

1The same control points as in Figure 3.5 are used for splines in figures 3.13, 3.16 and 3.21– 3.25 so that the reader can easily compare the different representations of cubics.

Build: January 28, 2021 74 Cubic curves

Figure 3.5. C1-smooth B´ezierspline consisting of two segments1.

P (i+1) (i) 2 P0

(i+1) (i) P1 P1 (i) (i+1) P3 = P0 P (i) 2 (i+1) P3

Figure 3.6. C2-smooth B´ezierspline.

(1) (n) Observation 2.6. Let C(P0 ,...,P3 ) be a (uniform) B´ezierspline. The spline is C1-smooth if and only if the following hondition holds for every 1 i n 1: ≤ ≤ − P (i) P (i) = P (i+1) P (i+1). 3 − 2 1 − 0 Second order smoothness is slightly more involving as the following proposition shows. Figure 3.6 shows the geometric interpretation of the condition Eq. (2.8).

(1) (n) 1 Proposition 2.7. Let C(P0 ,...,P3 ) be a (uniform) B´ezierspline of class C . The spline is C2-smooth if and only if for every 1 i n 1 ≤ ≤ − −−−−−→(i) (i) −−−−−→(i) (i) −−−−−−−−−→(i+1) (i+1) −−−−−−−−−→(i+1) (i+1) (2.8) P2 P1 + P2 P3 = P1 P2 + P1 P0 . Proof. By the assumption the spline is C1-continuous and hence the previous observation asserts that for every 1 i n 1 we have ≤ ≤ − P (i) = P (i+1) and P (i) P (i) = P (i+1) P (i+1). 3 0 3 − 2 1 − 0 The i-th segment of the spline can be written as

C (t) = P (i) + t 3P (i) + 3P (i)+ i 0 − 0 1 + t23P (i) 6P (i) + 3P (i) + t3 P (i) + 3P (i) 3P (i) + P (i). 0 − 1 2 − 0 1 − 2 3 Compute the second derivative: (i) (i) (i) (i) (i) (i) (i) C00(t) = 2 3P 6P + 3P + 6t P + 3P 3P + P . i 0 − 1 2 − 0 1 − 2 3 Build: January 28, 2021 Cubic curves 75

The second order derivatives of two consecutive segments must agree at their com- mon point, hence Ci00(1) = Ci00+1(0). Substituting to the above formula, we arrive at the following equation

23P (i) 6P (i) + 3P (i) + 6 P (i) + 3P (i) 3P (i) + P (i) = 0 − 1 2 − 0 1 − 2 3 = 23P (i+1) 6P (i+1) + 3P (i+1). 0 − 1 2 Rearranging the terms we arrive at the formula in the assertion. 

3. Interpolation with B´eziercurves In this section we concentrate on the following frequently encountered task: given a finite sequence of points Q0,...,Qk find a B´ezierspline C passing through all these points. Below we present two solutions of this problem. We need the following lemma of rather technical nature.

2 Lemma 3.1. Let P, Q, R R be three points and t0, t1, t2 R be pairwise distinct values of a parameter∈t. The parabola U(t) = at2 + bt ∈+ c satisfies the conditions

U(t0) = P,U(t1) = Q, U(t2) = R if and only if (R Q)t + (P R)t + (Q P )t a = − 0 − 1 − 2 , (t t )(t t )(t t ) 0 − 1 0 − 2 1 − 2 (Q R)t2 + (R P )t2 + (P Q)t2 b = − 0 − 1 − 2 , (t t )(t t )(t t ) 0 − 1 0 − 2 1 − 2 P t t (t t ) + Qt t (t t ) + Rt t (t t ) c = 1 2 1 − 2 2 0 2 − 0 0 1 0 − 1 . (t t )(t t )(t t ) 0 − 1 0 − 2 1 − 2 In order to prove the above lemma, it suffices to solve the system of linear equations  P = at2 + bt + c  0 0 2 Q = at1 + bt1 + c  2 R = at2 + bt2 + c for a, b and c. We let the reader fill up the details. We are now ready to present Bessel’s interpolation algorithm. Suppose that 3 we are given a set of points Q0,...Qk R and prescribed parameters 0 = t0 < ∈ 1 t1 < . . . < tn = 1. We are looking for a B´ezierspline C of class C such that C(ti) = Qi for every 0 i k. It is natural to let Q0,...,Qk be the endpoints of the successive segments≤ of≤ the spline we are building. Hence roughly one third of all the control points are already fixed:

(1) (1) (2) (k 1) (k) (k) Q0 = P0 ,P3 = Q1 = P0 ,...,P3 − = Qk 1 = P0 ,P3 = Qk. − Le us compute the positions of the remaining control points. Those control points will determine the tangents of the spline at the points Q , 0 i k. The idea is i ≤ ≤ to fit a parabola Ui through every three consecutive points Qi 1, Qi, Qi+1 so that − Ui(ti 1) = Qi 1,Ui(ti) = Qi,Ui(ti+1) = Qi+1. − − Build: January 28, 2021 76 Cubic curves

Then let the tangent to the spline C at Qi be the same as the tangent to the parabola. Using Lemma 3.1 we compute the derivative si := Ui0(ti) of Ui at ti

si = 2ati + b =

ti 1 ti ti ti+1 = − − (Qi Qi+1) + − (Qi 1 Qi). (ti 1 ti+1)(ti ti+1) − (ti 1 ti)(ti 1 ti+1) − − − − − − − − − The above formula is correct for the “internal” points Q1,...,Qk 1 but fails for the − first and the last point, since there do not exist Q 1 and Qk+1 that we could use − to build appropriate parabolas. Thus, we use the existing parabolas: U1 through Q0,Q1,Q2 and Uk through Qk 2,Qk 1,Qk respectively, to get: − − 2 2 s0 := (Q1 Q0) s1 and sk := (Qk Qk 1) sk 1. t1 − − 1 tk 1 − − − − − − Now let the remaining points be chosen in such a manner that the derivatives agree. Using Eq. (2.4) and (2.5) we have

(i) 1 (i) 1 P1 = Qi 1 + (ti ti 1)si 1 and P2 = Qi (ti ti 1)si. − 3 − − − − 3 − − In a special case, when the resulting spline is expected to be uniform, we have i k ti = /k. The above formula for si simplifies then to si = /2 (Qi+1 Qi 1). The 3 k · 3 − − two special cases are s0 = /2 kQ0 + 2kQ1 /2 Q2 and sk = /2 kQk 2kQk 1 + k − − − − /2 Qk 2. Substituting to the formula for the off-curve control points we have − (i) 1 (i) 1 P1 = Qi 1 + −−−−−→Qi 2Qi and P2 = Qi −−−−−−→Qi 1Qi+1 − 6 · − − 6 · − (1) (k) except for P1 and P2 , where the formulas become (1) 1 2 1 (k) 1 2 1 P1 = Q0 + Q1 Q2 and P2 = Qk + Qk 1 Qk 2. 2 3 − 6 2 3 − − 6 − The formulas are correct since the weights sum up to 1. We encourage the reader to compare the above algorithm with the construction of the Catmull-Rom curve presented in the next section. Notice that the curve obtained by the Bessel’s method depends on the positions of the interpolated points only locally. Point Qi influences the shape of at most four segments of the curve: the one ending at Qi, the one starting at Qi and their two neighbors. Example. Take the four points 0 2 3 5 Q = ,Q = ,Q = ,Q = . 0 0 1 2 2 1 3 1 We build a uniform B´ezierspline passing through all these points. As explained above the spline consists of three segments with the endpoints 0 2 3 5 = P (1),P (1) = = P (2),P (2) = = P (3),P (3) = . 0 0 3 2 0 3 1 0 3 1 Compute the remaining control points to get: 15 1 9  115 P (1) = ,P (1) = ,P (2) = , 1 6 7 2 6 11 1 6 13 115 121 125 P (2) = ,P (3) = ,P (3) = . 2 6 7 1 6 5 2 6 5

Build: January 28, 2021 Cubic curves 77

Q1

Q3 Q2

Q0

Figure 3.7. The B´ezierspline interpolating points Q0,Q1,Q2,Q3 using the Bessel’s algorithm. Dashed lines show the parabolas used to build the spline.

Figure 3.8. Comparison of the different parametrization schemes in the Bessel’s algorithm. Left to right: uniform, chord-length and centripetal parametrizations.

Figure 3.7 shows the resulting B´ezierspline.

The freedom of choice for the parameter values t1, . . . , tn 1 is an often under- estimated advantage of the Bessel’s method. Beside the uniform− subdivision of the parameter space, used in the above example, the two other most popular schemes are the chord-length parametrization and centripetal parametrization. In the chord- length scheme the length of an interval [ti 1, ti] is proportional to the euclidean − distance Qi Qi 1 between the corresponding points. Strictly speaking, let k − − k i X di := Qj Qj 1 , k − − k j=1

d then t0 := 0 and ti := i/dk for i > 0. The centripetal parametrization is quite sim- ilar, except that we take the square roots of the distances between the consecutive points, that is: i X q di := Qj Qj 1 k − − k j=1 d and as before, t0 := 0, ti := i/dk for i > 0. Figure 3.8 let the reader visually compare the results of the three schemes on the same set of points. Build: January 28, 2021 78 Cubic curves

βi Qi vi αi

Qi+1

Qi 1 −

Figure 3.9. Construction of the tangent direction in the Hobby’s algorithm.

Let us now present another interpolation scheme. The algorithm discussed below, due to J. Hobby, is often claimed to give a visually more pleasing results. The price we pay is that the influence of the interpolated points is no longer local. Moving a single point one alters the shape of the whole curve. Fortunately, the effect of changes vanishes exponentially as we move further and further away from the displaced point. The version of the algorithm presented here is simplified with respect to the original one in the sense that we do not include the tension and curl parameters. Let again Q0,...,Qk be the given points. This time we assume that no three successive points are co-linear. As in the Bessel’s method, these are the endpoints of the individual segments for the spline we build, thus (1) (1) (2) (k 1) (k) (k) Q0 = P0 ,P3 = Q1 = P0 ,...,P3 − = Qk 1 = P0 ,P3 = Qk. − We need to construct the remaining control points. Fix an index 0 < i < k and take three consecutive points Qi 1, Qi, Qi+1. They are not co-linear by the assumption, hence there is a unique plane− containing all three of them2. Thus, locally, we reduce the problem to a planar one. Our aim is to build a unit vector vi (contained in that plane), that we will subsequently use to determine the tangent of the spline at Qi.

Let αi denote the angle between −−−−−→QiQi+1 and vi and let βi be the angle between vi and −−−−−→Qi 1Qi (see Figure 3.9). It is clear that the sum of αi and βi is the angle − between the vectors −−−−−→QiQi+1 and −−−−−→Qi 1Qi connecting the successive interpolated points: −

αi + βi = ](−−−−−→QiQi+1, −−−−−→Qi 1Qi). − (α 2β ) Q Q We want the ratio i−1 i /(βi+1 2αi) to equal the ratio i i−1 / Qi+1 Qi − − k − k k − k of the distances between the points, therefore

(αi 1 2βi) Qi+1 Qi = (βi+1 2αi) Qi Qi 1 . − − · k − k − · k − − k This condition is a first order approximation of the continuity of the curvature of the resulting spline at Qi. Writing these two conditions for every 0 < i < k, one builds a system of 2k 2 linear equations in variables α0, . . . , αk 1 and β1, . . . , βk. The system is underdetermined.− To fix it we append two boundary− conditions

2The limitation, that no three consecutive points are co-linear, can easily be overcome, taking here the plane spanned by Qi−1,...,Qi+k for the smallest possible k, for which such a plane exists. We let the reader adjust the successive calculations appropriately.

Build: January 28, 2021 Cubic curves 79

Figure 3.10. An interpolation spline obtained by the Hobby’s algorithm.

α0 = β1 and αk 1 = βk. Therefore we have the following set of simultaneous linear equations: −  α0 β1 = 0  −  α + β = (−−−→Q Q2, −−−→Q Q )  1 1 ] 1 0 1  (α0 2β1) Q2 Q1 + (2α1 β2) Q1 Q0 = 0  − · k − k − · k − k ......  α + β = (−−−−−→Q Q , −−−−−−−→Q Q )  k 1 k 1 ] k 1 k k 2 k 1  − − − − − (αk 2 2βk 1) Qk Qk 1 + (2αk 1 βk) Qk 1 Qk 2 = 0  − − − · k − − k − − · k − − − k  αk 1 βk = 0. − − Solve it to get the angles α0, . . . , αk 1 and β1, . . . , βk that determine the directions − for the unit vectors v0, . . . , vk, we have been looking for. The off-curve control (i) (i) points P1 and P2 are then (i) (i) P1 := P0 + vi 1 Qi Qi 1 ρ(αi 1, βi), − k − − k − (i) (i) P2 := P3 vi Qi Qi 1 ρ(βi, αi 1). − k − − k − Here ρ is a fine-tuned, nevertheless quite intimidating, function given by the for- mula: 2 + √2(sin α 1/16 sin β)(sin β 1/16 sin α)(cos α cos β) ρ(α, β) := − − − . 3 1 + 1/2(√5 1) cos α + 1/2(3 √5) cos β − − We do not have enough space here to explain how this function was originally derived (we refer the reader to [11] for this explanation). Let us just mention that it lets the resulting spline approximate the curve of the least total curvature passing through Q0,...,Qk. Figure 3.10 shows a spline interpolating the same set of points as in Figure 3.8 but using the Hobby’s algorithm this time.

4. Catmull-Rom splines A B´ezierspline passes through every third of its control points. Splines studied in this section interpolate all their control points but the first and the last ones. We are looking for a parametric polynomial curve C = C(P0,P1,P2,P3), which starts at C(0) = P1 and goes to C(1) = P2. Moreover, as illustrated in Figure 3.11, Build: January 28, 2021 80 Cubic curves

P1 P3

P2

P0

Figure 3.11. Control points of a Catmull-Rom cubic curve. the derivative of C at each of its endpoint is half of the vector connecting the 1 two neighboring control points (i.e. at P the derivative C0(0) = /2 −−−→P P and 1 · 0 2 1 at P2 it is C0(1) = /2 −−−→P1P3). As before, C is a cubic polynomial of the form C(t) = at3 + bt2 + ct + d·. Write the above conditions as a system of simultaneous equations P = C(0) = d  1 1  /2(P P ) = C0(0) = c 2 − 0 P = C(1) = a + b + c + d  2 1 /2(P P ) = C0(1) = 3a + 2b + c. 3 − 1 Solve it for a, b, c, d to get a  1 3 3 1  P  − − 0 b 1  2 5 4 1 P1   =  − −    c 2  1 0 1 0  · P2 − , d 0 2 0 0 P3 Definition 4.1. The Catmull-Rom representation of parametric cubics is given by the formula t3  1 2 1 0 − − t2 1  3 5 0 2 C(t) = (P0,P1,P2,P3) MCR   MCR =  −  t 2 3 4 1 0 · ·  ,  . 1 −1 1 0 0 − The basis BCR R[t]3 of the Catmull-Rom representation consist of the fol- lowing four polynomials:⊂ 1 3 2 1 3 3 5 2 b0(t) = /2 t + t /2 t, b1(t) = /2 t /2 t + 1, − 3 2− 3 − 2 b (t) = 3/2 t + 2t + 1/2 t, b (t) = 1/2 t 1/2 t . 2 − 3 − Figure 3.12 shows the graphs of these polynomials on the unit interval [0, 1]. Just looking at the matrix MCR we make the following immediate observation (see Proposition 1.6): Observation 4.2. The Catmull-Rom representation of parametric cubics is affinely invariant. (1) (k) Consider a Catmull-Rom spline C(P0 ,...,P4 ) consisting of k segments (see (i) Figure 3.13). The i-th segment ends at P2 and so, for the spline to be continuous, Build: January 28, 2021 Cubic curves 81

1 1 1 1

0 1 0 1 0 1 0 1

Figure 3.12. Graphs of polynomials from the Catmull-Rom basis: b3, b2, b1, b0 (the order of polynomials is intentionally reversed).

Figure 3.13. Catmull-Rom spline consisting of 4 segments.

(i+1) (i) this must be the initial point of the successive segment. Hence P1 = P2 and it follows that two consecutive segments of a Catmull-Rom spline share three control points: (i) (i+1) (i) (i+1) (i) (i+1) P1 = P0 ,P2 = P1 ,P3 = P2 . An immediate consequence is:

(1) (n) Observation 4.3. A Catmull-Rom spline C(P0 ,...,P3 ) passes through all (1) (n) the control points except possibly P0 and P3 . (i) (i+1) The derivative of C at the point where two segments join (i.e. P2 = P1 ) equals half of the vector connecting the two neighboring control points. But these points are shared between the two segments, thus the curve is intrinsically smooth. Observation 4.4. Every Catmull-Rom spline is always C1-continuous. The price we pay for the smoothness and the interpolation property is that the Catmull-Rom representation fails to have the convex hull property. To see this explicitly consider a spline with control points  1  2 0 2 1 − , − , , , 0 2 3 2 0 depicted in Figure 3.14. It is clear that the curve is not contained in the convex hull of its control polygon. To better see where the problem lies, we encourage the reader to try to fit any smooth spline interpolating the three middle points into the convex hull. Build: January 28, 2021 82 Cubic curves

Figure 3.14. The Catmull-Rom representation does not have the convex hull property

It follows from its very definition that a Catmull-Rom spline can be easily converted into a B´ezierform. Later in Section 7 we present a general method for converting a cubic from one representation to another. The disadvantage of the general method is that it does not have such a clear geometric interpolation as the one presented below. Take first a single segment of a polynomial Catmull-Rom curve C with control points P0,P1,P2,P3. Our task is to find the control points Q0,Q1,Q2,Q3 of its B´ezierrepresentation. We know that the initial point C(0) of the curve is its control point P1 in the Catmull-Rom representation and Q0 in the B´ezierrepresentation. Hence Q0 = P1. Similarly Q3 = C(1) = P2. The derivative 1 C0(0) equals half of −−−→P P and three times −−−→Q Q . Analogously /2 −−−→P P = C0(1) = 0 2 0 1 · 1 3 3 −−−→Q Q . This leads us to the following system of equations: · 2 3  Q0 = P1  Q3 = P2 1 3(Q1 Q0) = /2 (P2 P0)  − · − 3(Q Q ) = 1/2 (P P ). 3 − 2 · 3 − 1 Solving it for Q0,Q1,Q2,Q3 we get the control points of the B´eziersegment  Q0 = P1  Q = 1/6 P + P + 1/6 P (4.5) 1 − 0 1 2 Q = 1/6 P + P 1/6 P  2 1 2 3  − Q3 = P2. This procedure must be repeated for every segment. We summarize the above discussion in form of Algorithm 1. It is worth to point out how the Catmull-Rom construction parallels the Bessel’s interpolation algorithm. To this end consider a Catmull-Rom spline C1 with control points Q0,...,Qk as well as a uniform B´eziercurve C2 obtained from these points by the means of the Bessel’s algorithm. Recall that the algorithm constructs the (i) control points Pj in such a way that

−−−−−→(i) (i) 1 −−−−−→ −−−−−→(i) (i) 1 −−−−−−→ P0 P1 = /6 Qi 2Qi and P2 P3 = /6 Qi 1Qi+1. · − · − Now, in a B´ezierspline these two vectors equals just one third of the derivative at the segment joints. It follows that each segment of C2 (except the first and the last) has the same endpoints and the same derivatives at the endpoints as the respective segment of C1. Thus the Catmull-Rom spline C1 is an arc of C2 obtained by dropping the first and the last segment. Build: January 28, 2021 Cubic curves 83

Algorithm 1: Catmull-Rom to B´ezierconversion

Input: P0,...,Pn — control points of a Catmull-Roma spline Output: Q0,...,Qm — control points of the B´ezierspline // compute the number of segments N n 2; ← − // first control point Q P ; 0 ← 1 // convert each segment separately for i 0 to N 1 do //← Use Eq. −(4.5) Q 1/6P + P + 1/6P ; 3i+1 ← − i i+1 i+2 Q 1/6P + P 1/6P ; 3i+2 ← i+1 i+2 − i+3 Q P ; 3i+3 ← i+2 return (Q0,...,Q3N );

Our next task is to present a geometric construction due to A. Overhauser of 3 a Catmull-Rom curve. Fix four control points P0,P1,P2,P3 R and find two parabolas U, V satisfying the conditions: ∈ U( 1) = P ,U(0) = P ,U(1) = P and V (0) = P ,V (1) = P ,V (2) = P . − 0 1 2 1 2 3 It follows from Lemma 3.1 that 1  U(t) = P t P (t + 1)(t 1) + P t P (t 1)(t + 1) , 2 0 − 1 − 2 − 1 − 1  V (t) = P (t 1) P (t 2)t + P (t 1) P t(t 2) . 2 3 − − 2 − 1 − − 2 − Construct a cubic curve C by linear interpolation of the two parabolas C(t) := lerpU(t),V (t); t. After rearranging the terms we have P ( t3 + 2t2 t) P (3t3 5t2 + 2) P ( 3t3 + 4t2 + t) P (t3 t2) C(t) = 0 − − + 1 − + 2 − + 3 − . 2 2 2 2 Clearly this is a Catmull-Rom curve. The most straightforward method to compute the position of a point C(t) on a parametric curve C, is to directly substitute the value of the parameter t to the formula describing C. Nevertheless, for some types of curves, there exist recursive algorithms that compute C(t) subdividing the segments of the control polygons. These are called corner-cutting algorithms. Such methods are known for B´ezierspline, Catmull-Rom splines and B-splines. Here we present an algorithm due to Ph. Barry and R. Goldman computing a point on a Catmull-Rom curve3. The idea is to start from the four control points of a Catmull-Rom cubic, denote 0 0 0 0 1 0 o 1 them P0 ,P1 ,P2 ,P3 . Compute the weighted averages Pj := lerp(Pj ,Pj+1, αj (t)) 1 1 1 of every two consecutive point to get three points P0 ,P1 ,P2 . Again compute the 2 2 weighted averages to get two points P0 ,P1 . Repeat the process one more time and 3 i get one point P0 = C(t). The weights αj(t) in every iteration of the algorithm are

3We present a simplified version that works only with cubic curves. The algorithm described in [4] is suitable for Catmull-Rom splines of an arbitrary degree.

Build: January 28, 2021 84 Cubic curves computed from the formula ( 1 (i + j 1 t), for i 2 αi (t) = i − − ≤ j 1 t, for i = 3. − The following diagram explains the successive steps of the algorithm. 0 0 0 0 P0 P1 P2 P3

α - α α - α α - α    1 − 1 − 1 − 1 1 1 P0 P1 P2

α - α α - α   1 − 1 − 2 2 P0 P1

α - α  1 − 3 P0 In the next chapter we will encounter de Casteljau’s and de Boor’s algorithms which will repeat the same scheme of computation: starting from the control points and computing the weighted averages till there is only one point left, which turns out to be the desired point on the curve. The pseudo-code of the Barry-Goldman’s method is presented in Algorithm 2. We shall now prove the correctness of this algorithm. Let δi(j) denote the Kronecker’s delta (i.e. δi(j) = 1 when i = j and δ (j) = 0 when i = j). All we need to do is to show that for the input i 6 P0 = δi(0),P1 = δi(1),P2 = δi(2),P3 = δi(3) the algorithm returns the i-th element of the Catmull-Rom basis. We provide details of one case, namely i = 0. The other cases are fully analogous. We have 0 0 0 0 1 P0 = 1 and P1 = P2 = P3 = 0. Consequently P0 = ( t) 1 + (t + 1) 0 = t and 1 1 − · · − P1 = P2 = 0. Next 1 t t + 1 t2 t P 2 = − ( t) + 0 = − and P 2 = 0. 0 2 · − 2 · 2 1 3 t2 t 3 2 Finally P = (1 t) − + t 0 = 1/2 ( t + 2t t) as desired. 0 − · 2 · · − −

Algorithm 2: Barry-Goldman’s algorithm  P 0,...,P 0 : control points of a Catmull-Rom cubic, Input: 0 3 t : parameter Output: C(t) — point on the curve for i 1 to 3 do for←j 0 to 3 i do if ←i < 3 then− i α 1/i (i + j 1 t); j ← · − − else αi 1 t; j ← − i i 1 i 1 i P lerp(P − ,P − ; α (t)); j ← j j+1 j 3 return C(t) = P0 ;

Build: January 28, 2021 Cubic curves 85

B Q1 Q 2 C

P P3 2 Q3 R1

R2 P0 P1 D A R3

Figure 3.15. B-spline construction.

5. B-splines This section is devoted to one of the most commonly used representation of parametric curves, namely the B-splines. The B-splines are second in popularity only to B´eziersplines discussed earlier. Unlike Catmull-Rom splines, in general B- splines do not interpolate their control points. Instead they are always C2-smooth. We construct a B-spline segment starting from a C2-continuous uniform B´ezier spline consisting of three segments with control points respectively:

P0,P1,P2,P3; Q0,Q1,Q2,Q3; R0,R1,R2,R3. The spline is assumed to be C2-smooth hence Observation 2.6 together with Propo- sition 2.7 assert that  P3 = Q0  Q3 = R0  P P = Q Q (5.1) 3 − 2 1 − 0 Q Q = R R  3 2 1 0  − − (P1 P2) + (P3 P2) = (Q2 Q1) + (Q0 Q1)  − − − − (Q Q ) + (Q Q ) = (R R ) + (R R ). 1 − 2 3 − 2 2 − 1 0 − 1 Substitute the first two equations into the last two to get: 2Q Q = 2P P , 2Q Q = 2R R . 1 − 2 2 − 1 2 − 1 1 − 2 Introduce four new points (see Figure 3.15): A := 2P P ,B := 2Q Q = 2P P , 1 − 2 1 − 2 2 − 1 C := 2R R = 2Q Q ,D := 2R R . 1 − 2 2 − 1 2 − 1 Express the control points P1,P2,Q1,Q2,R1,R2 in terms of A, B, C, D: 1 1 P = (2A + B),P = (A + 2B), 1 3 2 3 1 1 (5.2) Q = (2B + C),Q = (B + 2C), 1 3 2 3 1 1 R = (2C + D),R = (C + 2D). 1 3 2 3 Build: January 28, 2021 86 Cubic curves

Figure 3.16. B-spline consisting of 4 segments.

Eq. (5.1) let us write 1 1 Q0 = (P2 + Q1) = (A + 4B + C) (5.3) 2 6 1 1 Q = (Q + R ) = (B + 4C + D). 3 2 2 1 6 Rewriting these equation in matrix notation we have       Q0 1 4 1 0 A Q1 1 0 4 2 0 B   =     Q2 6 0 2 4 0 C     ·  . Q3 0 1 4 1 D Substituting to the formula for the B´eziercurve we express the middle segment using the points A, B, C, D:

 1 3 3 1 t3 − −  3 6 3 0 t2 C(t) = (Q0,Q1,Q2,Q3)  −    = ·  3 3 0 0 ·  t  −1 0 0 0 1 1 0 0 0  1 3 3 1 t3 − − 1 4 4 2 1  3 6 3 0 t2 = (A, B, C, D)    −    = · 6 1 2 4 4 ·  3 3 0 0 ·  t  0 0 0 1 −1 0 0 0 1  1 3 3 1 t3 − − 1  3 6 0 4 t2 = (A, B, C, D)  −    6 3 3 3 1 t ·   ·  . −1 0 0 0 1 The points A, B, C and D are the control points of the new representation. Definition 5.4. The B-spline representation of parametric cubics is given by the matrix  1 3 3 1 − − 1  3 6 0 4 MBS =  −  6 3 3 3 1  . −1 0 0 0 Build: January 28, 2021 Cubic curves 87

1 1 1 1

0 1 0 1 0 1 0 1

Figure 3.17. Graphs of polynomials from the B-spline basis: b3, b2, b1, b0 (the order of polynomials is intentionally reversed).

The B-spline basis consists of the following four polynomials: 1 1 b (t) = (1 t)3, b (t) = (4 6t2 + 3t3), 0 6 − 1 6 − 1 1 b (t) = (1 + 3t + 3t2 3t3), b (t) = t3. 2 6 − 3 6 Figure 3.17 shows the graphs of these polynomials on the unit interval [0, 1]. Propo- sition 1.6 implies: Observation 5.5. The B-spline representation is affinely invariant. On the other hand Proposition 1.5 asserts that every B-spline is contained in the convex hull of its control points. Observation 5.6. The B-spline representation has the convex hull property. Let us note one more fact. 3 Observation 5.7. For every five points P0,...,P4 R the following equation holds ∈

P0b0(1) + P1b1(1) + P2b2(1) + P3b3(1) = P1b0(0) + P2b1(0) + P3b2(0) + P4b3(0). An immediate consequence of the above observation is that every two consec- utive segments of a B-spline share three control points. Proposition 5.8. Every B-spline is C2-smooth. Proof. As before, we need to verify the conditions only at the joint of two segment. Hence let P0,P1,P2,P3 and P1,P2,P3,P4 be the control points of two consecutive segments. Then

P0b000(1) + P1b100(1) + P2b200(1) + P3b300(1) = = P (1 1) + P (3 1 2) + P (1 3 1) + P 1 = 0 · − 1 · · − 2 · − · 3 · = P 2P + P = 1 − 2 3 = P (1 0) + P (3 0 2) + P (1 3 0) + P 0 = 1 · − 2 · · − 3 · − · 4 · = P1b000(0) + P2b100(0) + P3b200(0) + P4b300(0)  There is a direct geometric method for converting a B-spline to a B´ezierform. Take a B-spline cubic curve with control points P0,P1,P2,P3. Divide each segment of the control polygon into three parts of equal length, obtaining six new points (see Figure 3.18): P k := lerpP ,P ; 1+k , for i, j 0, 1, 2, 3 , k 0, 1 . ij i j 3 ∈ { } ∈ { } Build: January 28, 2021 88 Cubic curves

Q1 Q P q 2 1 P 0 q 12 1 P12 1 P01 P2 Q0 Q 0 0 3 P23 P01 1 P23

P0 P3

Figure 3.18. B-spline to B´ezierconversion.

The subdivision of the middle segment P1P2 produces the two “internal” control points of the B´eziercurve:

0 1 Q1 := P12 and Q2 := P12.

1 0 The two remaining control points are the midpoints of the line segments P01P12 1 0 and P12P23:

1 0 1 1 0 1 Q0 := lerp(P01,P12; /2) and Q3 := lerp(P12,P23; /2). The correctness of this method follows immediately from Eq. (5.2) and Eq. (5.3). Observe further that for a spline consisting of more than one segment, the endpoints of each “internal” segment may be computed from the adjacent control points (again by Eq. (5.3)): 1  Q3i = lerp Q3i 1,Q3i+1; /2 . − All in all, Algorithm 3 presents a pseudo-code of the function converting a B-spline to a B´ezierspline.

Algorithm 3: B-spline to B´ezierconversion

Input: P0,...,Pn — control points of a B-spline C Output: Q0,...,Qm — control points of the B´ezierform of C // first the ‘‘internal’’ control points for i 1 to n 2 do ← − 1 Q3i 2 lerp(Pi,Pi+1, /3); − ← 2 Q3i 1 lerp(Pi,Pi+1, /3); − ← // endpoints of the ‘‘internal’’ segments for i 1 to n 3 do ← − 1 Q3i lerp(Q3i 1,Q3i+1, /2); ← − // endpoints of the spline 2 1  Q0 lerp lerp(P0,P1; 3 ),Q1; /2 ; ← 1 1  Q3n 6 lerp Q3n 7, lerp(Pn 1,Pn; ); /2 ; − ← − − 3 return (Q0,...,Q3n 6); −

Build: January 28, 2021 Cubic curves 89

6. Other cubic representations The three representations of parametric cubic curves discussed in the previous sections are the most often encountered in real-life applications. Nevertheless, they are not the only ones. In this section we present five more representations, gener- alizing Catmull-Rom and B-splines. In all the representations discussed below, two consecutive segments share three control points. The first idea is to introduce a tension to a spline. Augmenting the Catmull- Rom representation with the tension attribute leads to cardinal splines invented by J. Clark. They are defined by the following matrix:

 α 2α α 0 2− α α 3− 0 1 M (α) =   CS α− 2 3 −2α α 0  . α− −α 0 0 −

The parameter α [0, 1] determines the tension of the spline as demonstrated in ∈ Figure 3.21. Taking α = 1/2 we get just the Catmull-Rom spline. Tensed B-splines, on the other hand, use the matrix:

 α 3α 3α α  − − 1 12 9α 12α 18 0 6 2α MTB(α) =  − − −  6 9α 12 18 15α 3α α  . α− −0 0 0

Again α [0, 1] specifies the tension. This times, however, the original B-spline representation∈ corresponds to the value α = 1. On the other hand, taking α = 0 one gets the line segment connecting the two middle control points (for a spline consisting of more than one segment, we get the control polyline except the first and the last segment). Figure 3.22 shows how different values of α influence the shape of the curve. Another direction in which one may generalize cubic representations is to in- corporate a bias. An extension to the Catmull-Rom representation which allows the resulting curve to have both the tension and bias was proposed by T. Duff. The Delta-spline is defined using the following matrix:

 (β 1)α 2(1 β)α (β 1)α 0 − − −  2 βα (3β 1)α 3 (1 2β)α 1 M (α, β) = δ (1 −β)α 2− 3 α− − βα 0  . − βα − −βα 0 0 −

The curve has two attributes: α [0, 1] determines the tension and β [0, 1] specifies the bias. The standard Catmull-Rom∈ cubic is obtained by taking∈α = 1 and β = 1/2. Figure 3.23 depicts five splines, all with the same control point and the same tension but different values for the bias. A cubic representation in the spirit of B-splines but augmented with the bias and tension was proposed by B. Barsky under the name Beta-splines. Like the Delta-splines, the Beta-splines possess two attributes: the tension α [0, ) and ∈ ∞ Build: January 28, 2021 90 Cubic curves the bias β [0, ). The matrix defining the Beta-splines has the form: ∈ ∞  2β3 6β3 6β3 2β3  − − 1 2(α+β3+β2+β) 3(α+2β3+2β2) 6(β3 β) α+4β2+4β  − −  α+2β3+4β2+4β+2 2(α+β2+β+1) 3α+6β2 6β 2  . − 2 0 0 0 Notice that Beta-splines generalize the tensed B-splines in the sense that taking 1 α0 β = 1 and α = 12 −α0 results in a tensed B-splines with the tension α0. Figure 3.24 shows Beta-splines· with a varying bias. The last type of cubics we present are the TBC-splines invented by D. Kochanek and R. Bartels. This representation generalizes the Catmull-Rom construction adding three parameters: the tension α, the bias β and the continuity4 γ. Fig- ure 3.25 shows how the shape of the curve depends on γ. The matrix of the TBC-representation is:  (β+1)(γ+1)(α 1) (β+1)(γ+1)(α 1)  − (β+1)(γ+1)(α 1) − 0 2 − − 2  (1+γ γα)(β+3) α(β 1) β(α 1)(γ+3) 5(1+γ γα) α   − − − − − − − (β+γ)(α 1) 1  2 2 − −     (1+γ γα)(β 3) α(β+1) (β 1)(γ 1)(α 1)   − 2− − 2(1+γ γα)+(α βγ+βγα) − − 2− − 0  − −    (β 1)(γ+1)(α 1) (β 1)(γ+1)(α 1) . − 2 − − − 2 − 0 0

In particular for α = β = γ = 0 the matrix simplifies to the Catmull-Rom matrix. For reader’s convenience, Table 1 gathers basic properties of cubic representa- tions discussed in this chapter.

7. Change of basis This section shows how to convert a cubic spline from one representation to another. This is quite a common task in computer graphics and animation when the logic of a program works with one type of cubics (say B-splines) but the un- derlying graphic library accepts only another representation (e.g. B´ezier splines). The application must then internally convert every spline to be displayed from its internal format to the one required by the library. A single segment of a cubic spline is given by a triple of polynomials, hence 5 3 an element of the vector space R [t]3. As such, it can be expressed as a linear 3 combination of elements from whatever basis of R [t]3 we wish. Recall that if we have the coordinates of a vector with respect to one basis and we want to express this vectors using another basis, all we need to do is to multiply the coordinates by the change-of-basis matrix. Every representation of cubics encountered in this book so far is defined by an appropriate matrix, hence the problem boils down to multiplying one matrix by the inverse of the other. Suppose that P0,P1,P2,P3 are the control points of a polynomial cubic C in some representation given by a matrix M. Further let N be a matrix of our intended

4The name “continuity” is a bit misleading as a TBC-spline is C1-smooth only for γ = 0, otherwise it is only C0-continuous. 5 3 3 In fact R [t]3 is not a vector space (since R is not a field) but an object called a module. Nevertheless, all the methods we learnt on linear algebra curse can still be used.

Build: January 28, 2021 Cubic curves 91 continuity Attributes 133 — 3 — tension 3 tension, bias tension, bias, points Shared control 3 2 2 2 2 ,P ,P ,P ,P ,P ——— 3 3 3 — tension tension, bias 0 1 1 1 1 P P P P P control points 0 1 2 1 1 1 0 0 C C C C C C C C Properties of cubic spline representations Smoothness Interpolated Table 1. property RepresentationB´ezier Convex hull Catmull-RomB-splinesCardinal splinesTensed B-splines N Y Delta-splinesBeta-splines N Y Y TBC-splines N Y N

Build: January 28, 2021 92 Cubic curves

Figure 3.19. The same cubic curve represented as a B-spline (left) and as a B´ezierspline (right). representation. We can express C as

t3 t3 t2 t2 C(t) = (P ,P ,P ,P ) M = (P ,P ,P ,P ) M N 1 N 0 1 2 3  t  0 1 2 3 −  t  · ·   · · · ·  . 1 1

Define the points Q0,Q1,Q2,Q3 by the formula

1 (Q ,Q ,Q ,Q ) := (P ,P ,P ,P ) M N − . 0 1 2 3 0 1 2 3 · · This let us write t3 t2 C(t) = (Q ,Q ,Q ,Q ) N   0 1 2 3  t  · ·  . 1

It follows that Q0,Q1,Q2,Q3 are the desired control points of C in the intended representation. In the above discussion we worked with just a single polynomial curve. If instead we have a multisegment spline to work with, then it is clear that the con- version is possible only from a representation with less degrees of freedom, to one with more. A C2-smooth spline may be expressed as a C1 or C0-continuous, but not the other way around. In particular every spline can be converted to a B´ezier form.

Example. Take a B-spline given by the following control points (see Fig- ure 3.19):  5  4 0 2 6  3  − , − , , , , . 3 0 0 2 3 2 − The curve consists of three segments since in B-spline representation consecutive segments share three control points. In order to convert it to a B´ezier form we must multiply the coordinates of each segment by the matrix

1 0 0 0 1 1 4 4 2 1 MBS M − =   BE´ 6 1 2 4 4 ·  . 0 0 0 1 Build: January 28, 2021 Cubic curves 93

In B´ezierrepresentation two segments share only one control point, thus the re- sulting spline—still consisting of three segments—has ten control points (see Fig- ure 3.19):

 7/2  8/3  4/3  1/3 2/3 4/3  7/3  10/3 14/3 29/6 − , − , − , − , , , , , , . 1/2 0 0 1/3 2/3 4/3 11/6 7/3 8/3 2

8. Curve splitting Suppose we are given a polynomial cubic C. Often one needs to find the control points of the arc (sub-curve) C [t0,t1] corresponding to some pair of parameters t0, t1 R. A special case is to split a curve at some t (0, 1) in order to get the ∈ ∈ control points of two arcs C [0,t] (i.e. where we take t0 = 0, t1 = t) and C [t,1] (i.e. t0 = t, t1 = 1). A typical application is to model a shape coarsely at first and then add more details by subdividing some of the segments. For B´eziercurves the desired result can be obtained using de Casteljau’s algorithm described in the next chapter. In this section we present an alternative method based on matrix multiplication, which has the advantage of being applicable to every cubic representation. What’s more, we do not assume that t0, t1 lie in the interval (0, 1) or even that t1 is bigger than t0. Hence the method allow not only to split a curve but also to extend it as well as reverse the parametrization6. Fix a single cubic segment C = C(P0,P1,P2,P3) in some representation given by a matrix MB. Take two distinct real numbers t0, t1 R. Our task is to find the ∈ control points (with respect to the same cubic representation) of the arc C [t0,t1]. As we know, the curve C can be written in the form t3 t2 C(t) = (P ,P ,P ,P ) M   0 1 2 3 B  t  · ·  . 1

Re-parametrize the arc C [t ,t ] substituting lerp(t0, t1; t) for t in the above expres- 0 1  sion in order to define a new curve C1(t) := C lerp(t0, t1; t) . Hence we get  3 t(t1 t0) + t0 − 2  t(t1 t0) + t0  C1(t) = (P0,P1,P2,P3) MB  −  = · ·  t(t1 t0) + t0  − 1  3 2 2 3  3 (t1 t0) 3(t1 t0) t0 3(t1 t0)t0 t0 t −0 (t − t )2 2(t − t )t t2 t2 = (P ,P ,P ,P ) M  1 0 1 0 0 0   0 1 2 3 B  0− 0 t − t t   t  · ·  1 0 0  . 0 0− 0 1 1

Let S(t0, t1) be a matrix defined by the formula  3 2 2 3 (t1 t0) 3(t1 t0) t0 3(t1 t0)t0 t0 − − 2 − 2  0 (t1 t0) 2(t1 t0)t0 t0 1 S(t0, t1) := MB  − −  MB− . ·  0 0 t1 t0 t0 · 0 0− 0 1

6 In this section we adopt a convention in which C [t0,t1] for t0 > t1 means the curve C [t1,t0] but parametrized in the opposite direction.

Build: January 28, 2021 94 Cubic curves

We can express C1 as t3 t2 C (t) = (P ,P ,P ,P ) S(t , t ) M   1 0 1 2 3 0 1 B  t  · · ·  . 1

It follows that the control points Q0,Q1,Q2,Q3 of C1 are obtained from the original control points P0,P1,P2,P3 of C by a matrix multiplication (Q ,Q ,Q ,Q ) = (P ,P ,P ,P ) S(t , t ). 0 1 2 3 0 1 2 3 · 0 1 There are some cases frequently encountered in practice. They may be enu- merated as follows: (1) The initial sub-segment corresponding to splitting C at some t (0, 1). ∈ Then t0 = 0 and t1 = t, hence the matrix S(0, t) simplifies to: t3 0 0 0 2  0 t 0 0 1 (8.1) L(t) = M   M − . B ·  0 0 t 0 · B 0 0 0 1 (2) The terminal sub-segment corresponding to splitting C at some t (0, 1). ∈ Then t0 = t and t1 = t, so that S(t, 1) takes a form  3 2 2 3 (1 t0) 3(1 t0) t0 3(1 t0)t0 t0 − − 2 − 2  0 (1 t0) 2(1 t0)t0 t0 1 (8.2) R(t0) := MB  − −  MB− . ·  0 0 1 t0 t0 · 0 0− 0 1

(3) Curve C extended beyond the terminal point. Then t0 = 0, t1 > 1 and the matrix is given by Eq. (8.1). (4) Curve C extended beyond the initial point. Then t0 < 0, t1 = 1 and the matrix is given by Eq. (8.2). (5) The extension of C at the terminal point: t0 = 1 and t1 > 1. (6) The extension of C at the initial point: t0 < 0 and t1 = 0. (7) The reversion of the parametrization of C: t0 = 1, t1 = 0. The matrix S(1, 0) equals  1 3 3 1 − −  0 1 2 1 1 Inv = M  −  M − . B ·  0 0 1 1 · B 0 0− 0 1 Observe that for the three basic representations: B´ezier,Catmull-Rom and B- splines, the matrix Inv simplifies to 0 0 0 1 0 0 1 0 Inv =   . 0 1 0 0 1 0 0 0 Consequently, in these representations, to traverse the curve in the opposite direc- tion one needs just to reverse the order of the control points. Build: January 28, 2021 Cubic curves 95

Q0 P0

Q1 P P2 Q3 = P = R0 Q2 R2

R1

P1 P3 R3

Figure 3.20. Subdivision of a B´eziercubic curve.

Example. Take a B´eziercurve with control points  4  3 0  1 P = − ,P = − ,P = ,P = − . 0 2 1 0 2 1 3 0

1 23 22 T 1 1 Split C at P = C( /3) = ( − /9, /27) . The matrices L( /3) and R( /3) equal     1 2/3 4/9 8/27 8/27 0 0 0 1 0 1/3 4/9 4/9  1  4/9 4/9 0 0 L =   ,R =   . 3 0 0 1/9 2/9  3  2/9 4/9 2/3 0 0 0 0 1/27 1/27 1/9 1/3 1 The control points of the newly created segments are !  4  11/3  28/9  23/9 (P0,P1,P2,P3) L(t0) = − , − , − , − · 2 4/3 1 22/27 !  23/9  13/9  1/3  1 (P0,P1,P2,P3) R(t0) = − , − , − , − . · 22/27 4/9 2/3 0 The original curve and its two off-springs are shown in Figure 3.20

Example. Now, take the curve C1 = C1(Q0,Q1,Q2,Q3) found in the previous example and extend the parametrization to the interval [0, 3]. The control points of the extended curve are given by the formula !  4  3 0  1 (Q ,Q ,Q ,Q ) L(3) = − , − , , − . 0 1 2 3 · 2 0 1 0 This way we managed to reconstruct the original curve C from its initial sub- segment C1 = C [0,1/3].

Implementation notes TO DO

Exercises TO DO (1) Modify the Bessel’s algorithm presented in Section 3 to construct a peri- odic B´ezierspline passing through a given set of points. Build: January 28, 2021 96 Cubic curves

Bibliographic notes Centripetal parametrization was proposed by E. Lee in [18].TO DO

Build: January 28, 2021 Cubic curves 97

tension: 0

tension: 1/4

tension: 1/2

tension: 3/4

tension: 1

Figure 3.21. Cardinal spline with a varying tension.

Build: January 28, 2021 98 Cubic curves

tension: 0

tension: 1/4

tension: 1/2

tension: 3/4

tension: 1

Figure 3.22. Tensed B-spline with a varying tension.

Build: January 28, 2021 Cubic curves 99

tension: 1 bias: 0

tension: 1 bias: 1/4

tension: 1 bias: 1/2

tension: 1 bias: 3/4

tension: 1 bias: 1

Figure 3.23. Delta-spline with the fixed tension 1 and a varying bias.

Build: January 28, 2021 100 Cubic curves

tension: 0 bias: 1/4

tension: 0 bias: 1/2

tension: 0 bias: 1

tension: 0 bias: 2

tension: 0 bias: 4

Figure 3.24. Beta-spline with the fixed tension 0 and a varying bias.

Build: January 28, 2021 Cubic curves 101

tension: 0 bias: 0 continuity: 0

tension: 0 bias: 0 continuity: 1/2

tension: 0 bias: 0 continuity: 1

tension: 0 bias: 0 continuity: 3/2

tension: 0 bias: 0 continuity: 2

Figure 3.25. TBC-spline with the fixed tension and bias and a varying continuity.

Build: January 28, 2021

CHAPTER 4

Rational parametric curves

1. Why rational splines? In the previous chapter we have studied polynomial cubics. Although this is the type of curves that is most often used in practice, nevertheless polynomial splines have certain limitations, some of which are quite serious. These limitations justify the introduction of rational splines into our discussion. Let us begin with the following motivating example. Example. Consider a polynomial cubic B´eziercurve C with control points  1  1 1 1 − − P = 0 ,P = 1 ,P = 1 ,P = 0 0   1   2   3  . 0 1 1 0 Our aim is to cast it onto a two-dimensional viewport using 1-pt perspective pro- jection. Fix a parameter t [0, 1], the corresponding point on the curve may be computed as: ∈

 3 t  2 3 2 1 + 6t 4t  t  − −2 C(t) = P0,P1,P2,P3 M ´   = 3t 3t BE t  . · ·   3t − 3t2 1 − In homogeneous coordinates this reads as [ 4t3 + 6t2 1, 3t2 + 3t, 3t2 + 3t, 1]T. − − − − Now, take the 1pt-perspective projection (along OZ) with the focal length e = 1/2. Proposition 2.1 asserts that the point C(t) is first mapped to 1 0 0 0  4t3 + 6t2 1  4t3 + 6t2 1 − − − − 0 1 0 0  3t2 + 3t   3t2 + 3t  C1(t) =    −  =  −  0 0 1 0 ·  3t2 + 3t   3t2 + 3t  0 0 2 3 − 1 6−t2 + 6t + 3 − and then orthogonally projected onto OXY . Dehomogenize and drop the Z coor- dinate, to get the resulting C˜ given by the formula  4t3 6t2 + 1  − 3(2t2 2t 1) C˜(t) =    t2− t−  − . 2t2 2t 1 − − Clearly C˜ is no longer a polynomial curve! One may wonder what would happen, if we choose to project only the control points and then (re)construct a curve from the projected points. The homogeneous Build: January 28, 2021 104 Rational parametric curves

TO DO

Figure 4.1. Perspective projection of a B´ezier curve. In the right image, solid lines shows the projected (rational) curve, while the dotted line the polynomial curve constructed by projecting the control points alone. coordinates of the control points are  1  1 1 1 − −  0   1  1 0 P = ,P = ,P = ,P = 0  0  1  1  2 1 3 0        . 1 1 1 1 The 1pt-perspective maps them to  1   1  1  1  − /3 − /5 /5 /3 Pˆ0 = , Pˆ1 = , Pˆ2 = , Pˆ3 = . 0 1/5 1/5 0

The polynomial B´ezier cubic curve Cˆ(Pˆ0, Pˆ1, Pˆ2, Pˆ3) is then  8 4 2 1 t3 + t2 + t ˆ −15 5 5 − 3 C(t) =  3 3  t2 + t . −5 5 It differs in shape from C˜ as one can observe in Figure 4.1. The previous example shows that there is a strong need to admit rationally parametrized curves into our discussion. Projective transformations (and a per- spective in particular) are not the only reason, since we shall soon discover that rational curves offer more flexibility in shape manipulation. One last argument, which should convince even the strongest skeptics is that the only polynomial curves among the conical sections are the parabolas. Neither hyperbolas nor ellipsis (in- cluding circles) could be parametrized without rational functions. Fix a basis B = b0, . . . , bd of R[t]d that gives rise to an affinely invariant { } representation of polynomial curves. Let P0,...,Pd be some points of the three- dimensional space with homogeneous coordinates       x0 x1 xd y y y P =  0  ,P =  1  ,...,P =  d  0 z  1 z  d z   0   1   d . w0 w1 wd

Write the linear combination of the polynomials b0, . . . , bd with the coefficients P ,...,P : 0 d     x(t) xi d y(t) X yi    =   bi(t). z(t) zi  i=0 w(t) wi Unfortunately this sum depends on the choice of the homogeneous coordinates of the control points (see Figure 4.2). Hence it cannot be used to define a parametric curve in the projective space (we will tackle the problem of parametric curves in P3R in the next chapter). Ignoring this obstacle for a moment, we dehomogenize the above formula to get the point Build: January 28, 2021 Rational parametric curves 105

TO DO[[[3.16]]]

Figure 4.2.

    x(t) x(t)/w(t) y(t) = y(t)/w(t)    . z(t) z(t)/w(t)

T Analogously, degomogenize the the control points too and denote (xi, yi, zi) = x y z T ( i/wi, i/wi, i/wi) . Thus, we can rewrite the formula for our curve as     x(t) d x d X i X y(t) w(t) = yi wibi(t), where w(t) = wibi(t). z(t) i=0 zi i=0 This leads us to the desired definition of a rational curve.

Definition 1.1. A rational curve in basis B = b0, . . . , bd with control points T T { } P0 = (x0, y0, z0) ,...,Pd = (xd, yd, zd) and weights w0, . . . , wd R 0 is given by the formula ∈ \{ } Pd wiPibi(t) C(t) = i=0 . Pd wibi(t) i=0 Observe that, if all the weights have a common factor, then it can be canceled from both: the numerator and denominator. It follows that: Observation 1.2. Multiplication of all the weights of a rational curve by a constant term does not alter the curve.

Moreover, since we assumed that the basis B gives rise to an affinely invariant Pd polynomial curve representation, therefore i=0 bi(t) = 1. If all the weights are equal w = = w =: w, then the formula simplifies to 0 ··· d Pd w Pibi(t) d · X C(t) = i=0 = P b (t). d i i P i=0 w bi(t) · i=0 Observation 1.3. A rational curve with all the control points having equal weights simplifies to a polynomial curve.

We derived the above observation directly from the formula of the curve, but there is also a simple geometric reasoning behind it—see Exercise 1. Last but not least advantage of rational curves is the following one: Proposition 1.4. The rational curve representation is projectively invariant (providing that the underlying polynomial representation is affinely invariant). We leave the proof details to the reader. It follows easily from what we did introducing the rational curves using homogeneous coordinates. Build: January 28, 2021 106 Rational parametric curves

2. B´eziercurves In this section we generalize the notion of the B´eziercurves (introduced in Section 2) to an arbitrary degree. Take a positive integer d N and consider the following decomposition of the unity: ∈ d   d d X d i d i 1 = 1 = t + (1 t) = t (1 t). − − i − i=0

For d = 3, the terms appearing under the sum are just the polynomials b0, b1, b2, b3 that we have encountered on page 73. This is, thus, natural to use the above formula to define B´eziercurves of any degree. We define the Bernstein polynomials of degree d to be:   d d i d i (2.1) b (t) := t (1 t), − for 0 i d. i i − ≤ ≤ Moreover, for i < 0 or i > d we define bd(t) 0. i ≡ Pd Observation 2.2. For every d 0 one has bi(t) 1. ≥ i=0 ≡ In order to use Bernstein polynomials to define a curve representation we must make sure that they form a basis (for a fixed degree d). Proposition 2.3. For every d N, the set B = bd, . . . , dd is a basis of the ∈ { 0 d} space R[t]d of polynomials with degree not exceeding d. d Proof. The power basis of R[t]d consists of the monomials 1, t, . . . , t . Di- d i rectly from its definition, the polynomial bi is divisible by t , hence it coordinates i 1 with respect to 1, . . . , t − are all zero. Consequently, writing column-wise the coor- d d dinates (w.r.t. the power basis) of b0, . . . , bd, we arrive at a triangular matrix. The d diagonal of this matrix consists of the elements: 1, d, . . . , i ,..., 1. Therefore the d d matrix is non-singular. It follows that b0, . . . , bd are linearly independent. Thus, they form a basis of R[t]d.  Definition 2.4. A B´ezier (polynomial) curve of degree d with control points P0,...,Pd is given by the formula d X C(t) = P bd(t), for t [0, 1]. i i ∈ i=0 The discussion in the previous section let us immediately define a B´ezierrational T T 1 curve with control points P0 = (x0, y0, z0) ,...,Pd = (xd, yd, zd) and weights w0, . . . , wd to be: Pd w P bd(t) C(t) = i=0 i i i . Pd d i=0 wibi (t) d d Observe that b0(0) = 1 and bd(1) = 1 it follows that a B´ezier curve C = C(P0,...,Pd) interpolates the first and the last of its control points:

C(0) = P0 and C(1) = Pd. Observation 2.2 together with Proposition 1.3 and Proposition 1.4 gives us the first important property of the B´ezierrepresentation.

1 T Alternative we can write in homogeneous coordinates Pi = [xiwi, yiwi, ziwi, wi] . Build: January 28, 2021 Rational parametric curves 107

TO DO

Figure 4.3. A rational B´eziercurve without the convex hull property.

Observation 2.5. The polynomial B´ezierrepresentation is affinely invariant, the rational B´ezierrepresentation is projectively invariant.

i d i Observe that for t [0, 1] both t and (1 t) − are non-negative and so is d ∈ − bi (t), hence consequently Proposition 1.5 asserts: Observation 2.6. The polynomial B´ezierrepresentation has the convex hull property. In general, a rational B´eziercurve does not have to be contained in the convex hull of its control points. Take for example a plane conic curve C(P0,P1,P2) with control points P = ( 1, 0)T , P = (0, 1)T and P = (1, 0)T with weights w = 0 − 1 2 0 w = 1 and w = 1/2 (see Figure 4.3). Then the point 2 3 − 1 2 1 1 0 2 1 1 2 1    −0 b0( /2) /2 1 b1( /2) + 0 b2( /2) 0 C 1/2 = · − · · · = b2(1/2) 1/2 b2(1/2) + b2(1/2) 1 0 − · 1 2 − lies clearly outside the convex hull of P0, P1 and P2. Nevertheless one has a limited version of a convex hull property for rational B´eziercurves.

Proposition 2.7. If all the weights of a rational B´eziercurve C(P0,...,Pd) are strictly positive, then C(P ,...,P ) conv(P ,...,P ). 0 d ⊂ 0 d Proof. Fix a parameter t [0, 1] and rewrite the formula for the curve in the following way: ∈ d X wi d C(t) = Pi b (t). Pd d i i=0 j=0 wjbj (t)

wi Pd d  d All the coefficients / j=0 wj bj (t) bi (t) are non-negative, since every wj > 0. Moreover they clearly sum up to 1.· Therefore the point C(t) on the curve is a convex combination of the control points.  We are now ready to present an algorithm, due to P. de Casteljau, which can be used to achieve both: find a point on a curve and split a curve into two arcs. Surprisingly, algorithm uses the linear interpolation only. For the sake of clarity, we restrict ourselves to polynomial curves alone, nevertheless the algorithm may be effectively applied to rational curves as well, providing that all the computations are done in homogeneous coordinates. Take a B´ezier(polynomial) curve C(P0,...,Pd) with control points P0,...,Pd and fix a parameter t [0, 1]. In order to unify the notations we use the superscript zero to denote the original∈ control points, so that 0 Pi = Pi for every 0 i d. Subdivide each line segment of the control polyline with the ratio t : 1 ≤t constructing≤ new points − 1 0 0 1 0 0 P0 := lerp(P0 ,P1 ; t) ,...,Pd 1 := lerp(Pd 1,Pd ; t). − − i i Now, repeat the process iteratively. In each step construct new points P0,...,Pd i as weighted averages of the points from the previous iteration: − i i 1 i 1 P = lerp(P − ,P − ; t), for 1 i d and 0 j d i. j j j+1 ≤ ≤ ≤ ≤ − Build: January 28, 2021 108 Rational parametric curves

TO DO[[[4.1]]]

Figure 4.4. Illustration of the de Casteljau’s algorithm.

Each repetition reduces the number of points by one, Hence after d iterations, we d are left with just a single point P0 , which we claim to be the point C(t) on the curve 0 d d 0 while the intermediate points P0 ,...,P0 and P0 ,...,Pd are the control points of the two arcs joining at C(t). Figure 4.4 illustrates how the algorithm works. The pseudo-code of the process is presented in Algorithm 4.

Algorithm 4: The de Casteljau’s algorithm  P ,...,P : control points of a B´eziercurve Input: 0 d t [0, 1] : a fixed parameter  ∈ Q0,...,Qd : control points of the arc C  [0,t] Output: R0,...,Rd : control points of the arc C [t,1]  C(t) : point on the curve // rename the arguments 0 0 P0 := P0,...,Pd := Pd; // the first and the last control points Q P 0; 0 ← 0 R P 0; d ← d // main loop for i 1 to d do //← loop over the points for j 0 to d i do i← −i 1 i 1 P lerp(P − ,P − ; t); j ← j j+1 i Qi P0; ← i Rd i Pd i; − ← − d return (Q0,...,Qd), (R0,...,Rd),P0 ;

Theorem 2.8. Use the notation introduced above. The points

0 i d d d i 0 P0 ,...,P0,...,P0 and P0 ,...,Pi − ,...,Pd are the control points of the B´ezierrepresentation of the arcs C [0,t] and C [t,1], d respectively. In particular P0 = C(t).

In order to prove the theorem, we need two lemmas.

Lemma 2.9. If d N is a natural number and i Z is an integer, then ∈ ∈ d d 1 d 1  bi (t) = lerp bi − (t), bi −1 (t); t . − Build: January 28, 2021 Rational parametric curves 109

Proof. Expand the right-hand side of the above equation as follows:

d 1 d 1  d 1 d 1 lerp bi − (t), bi −1 (t); t = (1 t) bi − (t) + t bi −1 (t) = −   − ·  · − d 1 i d i d 1 i d i = − t (1 t) − + − t (1 t) − = i − i 1 − − (d i)(d 1)! + i(d 1)! i d i = − − − t (1 t) − = i!(d i)! · − −   d i d i d = t (1 t) − = b (t). i − i  Lemma 2.10. Use the notation introduced above. If i, j are two integers satis- fying the conditions 0 i d and 0 j d i, then ≤ ≤ ≤ ≤ − i i X i Pj = Pj+kbk(t). k=0 Proof. The proof proceeds by an induction on i. The case i = 0 is trivial. 0 0 0 Since b0(t) 1 by the definition and so Pj = Pj = Pj b0(t). Assume that the assertion is≡ true for integers less than i. Write · i i 1 i 1  Pj = lerp Pj− ,Pj+1− ; t . i 1 i 1 Use the induction hypothesis for the points Pj− , Pj+1− :

i 1 i 1 X− i 1 X− i 1  = lerp Pj+kbk− (t), Pj+k+1bk− (t); t = k=0 k=0 i 1 i 1 X− i 1 X− i 1 = P (1 t)b − (t) + P tb − (t). j+k − k j+k+1 k k=0 k=0 Change the indexation of the second sum taking k k + 1 and use the fact that i 1 i 1 ← bi− (t) 0 and b −1 (t) 0 by the definition. ≡ − ≡ i i X i 1 X i 1 = Pj+k(1 t)bk− (t) + Pj+ktbk− 1(t) = − − k=0 k=0 i X i 1 i 1  = Pj+k lerp bk− (t), bk− 1(t); t . · − k=0 Now, the previous lemma asserts that the linear interpolation of two Bernstein polynomials of degree i 1 gives a Bernstein polynomial of degree i. Thus, we last −Pi i expression evaluates to k=0 Pj+kbk(t), as desired.  We are now ready to prove the theorem.

Proof of Theorem 2.8. The initial subsegment C [0,t] of C can be para- metrized as u C(ut) with the parameter u varying over the unit interval (t being fixed). Take a7→ single Bernstein polynomial of degree d:   d d i d i b (ut) = (ut) (1 ut) − = i i −

Build: January 28, 2021 110 Rational parametric curves

1 t 1  Rewrite the expression 1 ut in the following way 1 ut = t −t u + t (1 u) and expand the (d i)-th power− using the binomial formula− to get − −     d i    j  d i j d i i d i X− d i 1 t j 1 − − d i j = t u t −  − − u (1 u) − −  = i j t t − j=0 d i    X− d d i i j i+j d (i+j) = − t (1 t) u (1 u) − . i j − − j=0

Now, substitute k for i + j:

d    X d d i i k i k d k = − t (1 t) − u (1 u) − = i k i − − k=i − d     X k i k i d k d k = t (1 t) − u (1 u) − . i − k − k=i

k d Each summand is clearly a product of the Bernstein polynomials bi (t) and bk(u). k Using the fact that bi (t) 0 for k 0, . . . , i 1 , we rewrite the last expression Pd k d ≡ ∈ { − } as k=0 bi (t)bk(u). Substitute it into the formula for C

d d d d k ! X d X X k d X X k d C(ut) = Pibi (ut) = Pibi (t)bk(u) = Pibi (t) bk(u). i=0 i=0 k=0 k=0 i=0

Pd k d The previous lemma asserts that this is actually k=0 P0 bk(u), which proves the first assertion of the theorem. In order to show that P d,...,P 0 are the control points of the other subsegment 0 d (i.e. the arc C [t,1]), use the symmetry of the Bernstein basis:

d d bi (t) = bd i(1 t) − − together with the previous part. The “in particular” part follows immediately from the interpolation property of the B´ezierrepresentation. 

Example. Consider a cubic B´eziercurve2 with control points

 4  3 0  1 P = − ,P = − ,P = ,P = − . 0 2 1 0 2 1 3 0

2This is the same curve as in the example on page 95 in Section 8.

Build: January 28, 2021 Rational parametric curves 111

Subdivide the curve at t = 1/3 using the de Casteljau’s algorithm. The successive steps of the computations are shown on the following diagram:  4  3 0  1 − − − 2 0 1 0 2 1 2 1 2 1 -3 3 -3 3 -3 3     11/3  2  1/3 − − − 4/3 1/3 2/3 2 1 2 1 -3 3 -3 3    28   13  − /9 − /9 1 4/9 2 1 -3 3   23  − /9 22/27 The left edge of the above diagrams consists of the control points of the initial subsegment, while the right edge consists of the control points of the terminal subsegment. In particular, the single element in the last row is the point on the − 23/9 1 3 curve C( / ) = 22/27 . We have stated and proved the theorem for polynomial curves only. But it remain true for rational ones, as long as all the computations are performed in homogeneous coordinates (see the previous section). We encourage the reader to work up the details of the proof in this more general context. Moreover, let us notice that the de Casteljau’s algorithm may be used not only to subdivide a curve, but also to extend it when the input parameter t lies outside the unit interval. We have already encountered a similar phenomenon in Section 8 of Chapter 3. One more, extremely important application of the de Casteljau’s algorithm follows from the fact that the control polylines of successive subdivisions can effec- tively approximate the original B´eziercurve. Recall that a subset A X is said to be dense in X if for every element x of X and every positive distance⊂ ε > 0 there is an element y in A “close enough” to x, which means that x y < ε (using a fancier language, we say that A is dense in X if and only if its| closure− | cl (A) is the whole set X).

Proposition 2.11. Fix a B´eziercurve C and let (un n N) be a non- repeating sequence of parameters, dense in the unit interval [0|, 1].∈ Take a sequence of B´eziersplines (Cn n N), where C0 := C and Cn is obtained by subdividing | ∈ Cn 1 at un. Then the sequence of the corresponding control polylines converges uniformly− to C.

Proof. Denote by Ln the control polyline of the spline Cn. There is a per- mutation σ of the (finite) set u , . . . , u sorting it in a strictly ascending order: { 1 n} u < u < < u . σ(1) σ(2) ··· σ(n) The polyline Ln meets the curve C at least at the points :

Q0 := C(0),Q1 := C(u1),...,Qn := C(un),Q := C(1). ∞ Parametrize the polyline monotonically and in such a way that Ln(ui) = Qi for every i 0, . . . , n, . ∈ { ∞} Build: January 28, 2021 112 Rational parametric curves

TO DO

Figure 4.5. Approximation of a B´eziercurve by successive subdivisions. TO DO

Figure 4.6.

Fix ε > 0 and take any s [0, 1]. The set un n is dense in [0, 1]. Thus there ∈ { } ∈N is some u close enough to s such that C(s) C(u ) < ε/3. The maximal n(s) k − n(s) k length of line segments of successive polylines Ln converges to zero, therefore there is some n0 N such that for every n > n0 the maximal line segment of Ln is smaller ∈ than ε/3. The curve C is a continuous function defined on a compact set, hence it is ε uniformly continuous. It follows that there is δ(s) > 0 such that C(t) C(t0) < /3, k − k when t t0 < δ(s). Consequently Ln(t) C(t) < ε for every n > max n0, n(s) and every| − parameter| t (s δ(s), sk + δ(s)).− k { } The collection (s∈ δ(−s), s + δ(s)) : s [0, 1] forms an open cover of the compact set [0, 1]. Thus− there exists a finite set∈ s , . . . , s [0, 1] such that 1 m ∈ [0, 1] s δ(s ), s + δ(s ) ... s δ(s ), s + δ(s ). ⊂ 1 − 1 1 1 ∪ ∪ m − 1 m 1 With every s s , . . . , s we have already associated an appropriate n(s ). i ∈ { 1 m} i Take N = max n0, n(s1), . . . , n(sm) . It follows that for every n > N and every t [0, 1] the distance{ L (t) C(t)} is smaller than the fixed ε. This proves our ∈ k n − k proposition.  An area where the above proposition may be immediately applied is visualiza- tion of B´eziercurves. One just subdivides a curve recursively until the resulting control polyline is close enough to the original curve, with tolerance depending on the actual display device. Then one just draws the polyline instead of the actual curve. This procedure is illustrated in Figure 4.5. Let us note also another conse- quence of this convergence. Observe that the new vertices of a subsequent polyline always lie on the edges of its predecessor. Thus it is a corner-cutting process. Consequently the lengths of the polylines form a non-ascending sequence, which converges to the length of the original curve (see also Section 8). Thus we have just proved: Corollary 2.12. The length of a B´eziercurve does not exceed the length of its control polyline. Proposition 2.13. TO DO[[[rowne wagi na koncach krzywej wymiernej Beziera]]] Example. TO DO[[[zastosowanie podzialu krzywej do sprawdzania czy punkt na niej lezy (przyklad zgodny z rozdz. 6)]]] Example. TO DO[[[zastosowanie podzialu krzywej do znajdowania przeciec (przyklad zgodny z rozdz. 6)]]] Figure 4.6 shows both curves. 3. Uniform B-splines In this section (and the next one) we generalize the second type of parametric curves from the cubics presented in Chapter 3 to an arbitrary degree. This time, however, we need to first readjust our perspective and change the way we perceive splines, before we generalize the B-splines. So far, we have considered a spline in a Build: January 28, 2021 Rational parametric curves 113

“segment-wise” fashion, treating the segments nearly independently. The focus was put on a segment representation and control points were just the coordinates of a given segment of a spline. But there is a different approach, where the emphasis is put on the control points; a spline is considered to be a weighted sum over all its control points, while the influence of each point is local (with respect to a parametrization). Let us first look at a cubic spline from a new perspective. Take a B-spline C with control points P0,...,Pn, n 3. It consists of n 2 segments. Recall that the basis of the cubic B-spline representation≥ consists of− the following four polynomials: 1 1 b (t) = (1 t)3, b (t) = (4 6t2 + 3t3), 0 6 − 1 6 − 1 1 b (t) = (1 + 3t + 3t2 3t3), b (t) = t3. 2 6 − 3 6 Let U : R R be a piecewise function obtained by shifting and gluing them together: →

 3 2 b (t + 2) = 1/6 t + t + 2t + 4/3, if t [ 2, 1)  3  3 2 ∈ − − b (t + 1) = 1/2 t t + 2/3, if t [ 1, 0)  2 − 3 − 2 ∈ − U(t) := b (t) = 1/2 t t + 2/3, if t [0, 1) 1 − ∈  1 3 2 4 b0(t 1) = /6 t + t 2t + /3, if t [1, 2]  − − − ∈ 0, if t < 2 or t > 2. − Observation 3.1. The function U : R R defined above is symmetric and has a bounded support equal ( 2, 2). → − It turns out that we may express the curve C using the function U alone.

Proposition 3.2. Let C = C(P0,...,Pn) be a cubic B-spline with control points P0,...,Pn, then n X C(t) = P U(n 2)t i + 1, for t [0, 1]. i · − − ∈ i=0

Proof. Fix a single segment Ck of C with control points Pk, Pk+1, Pk+2 and Pk+3. It has the form 3 X Ck(t0) = Pk+jbj(t0), j=0 where t0 [0, 1] is the local parameter of Ck (the corresponding global parameter t ∈ k (k + 1) varies over [ /(n 2), /(n 2)]). Substitute b (t0) with U(t0 j + 1) to get − − j − 3 X C (t0) = P U(t0 j + 1). k k+j − j=0 The support of U is supp(U) = ( 2, 2) and so we may expand the indexation beyond the set 0,..., 3 without altering− the sum, hence { } n k X− C (t0) = P U(t0 j + 1), for t0 [0, 1]. k k+j − ∈ j= k − Build: January 28, 2021 114 Rational parametric curves

0 Return to the global parametrization setting t = (t + k)/(n 2) and take i = j + k − to see that n X h k k + 1 i C(t) = P U(n 2)t i + 1, for t , . i · − − ∈ n 2 n 2 i=0 − − This proves the proposition for a single segment Ck of C. But the choice of the segment was fully arbitrary, hence the assertion holds for the whole spline.  The proposition suggests how to generalize the B-splines to an arbitrary de- d d gree. We need to find a family U d N of functions, where each U is piecewise polynomial of degree d and with{ a bounded} ∈ support. In particular, we wish to have U 3 = U. Once we have such a family at our disposal, then a B-spline of degree d may be defined as a sum over all its control points scaled by shifted copies of U d in similar fashion as in Proposition 3.2. We have to take care to ensure that the resulting curve representation is affinely invariant and to this end, for every d, the shifted copies of U d must sum up to the unity everywhere. The definition of U d is recursive and utilizes the notion of a convolution, which we need to recall first. Definition 3.3. Let f, g : R R be two integrable functions. The convolution → of f and g is a function f g : R R defined by the formula ∗ → Z (f g)(t) := f(τ)g(t τ)dτ. ∗ R − There are many important properties of the convolution, we will need the fol- lowing one.

Lemma 3.4. Let f, g : R R be two integrable functions and let Tα : R R denote the translation T (t) :=→t α, then (f T ) (g T ) = (f g) T →. α − ◦ α ∗ ◦ β ∗ ◦ α+β The proof boils down to a simple substitution. The reader can easily do it on a scrap of paper or find in almost any calculus textbook. Definition 3.5. Take U 0 to be a pulse function ( 1, if t [ 1/2, 1/2] U 0(t) := ∈ − 0, otherwise. For d > 0, we define U d recursively by the formula: d d 1 0 U := U − U . ∗ 1 1 d 1 0 The support of U is supp U = [ /2, /2]. Hence the product U − (τ) U (t τ) 0 0 − · − vanishes everywhere outside the interval [t 1/2, t + 1/2]. On the other hand, inside d 1− 0 1 this interval the product simplifies to U − (τ), since U (t τ) = 1 for t τ /2. − | − | ≤ Observation 3.6. For any d > 0, 1 Z t+ 2 d d 1 U (t) = U − (τ)dτ. t 1 − 2 Let us explicitly compute the first few of the functions U d. The graphs are presented in Figure 4.7. For d = 1 the resulting function is piecewise linear:  t + 1, if t [ 1, 0)  ∈ − U 1(t) = t + 1, if t [0, 1) − ∈ 0, elsewhere. Build: January 28, 2021 Rational parametric curves 115

TO DO

Figure 4.7. Graphs of U 0, U 1, U 2 and U 3 (compare the last graph with Figure 3.17).

TO DO

Figure 4.8. Construction of a 1-dimensional B-spline.

TO DO

Figure 4.9. Construction of a 2-dimensional B-spline.

For d = 2 we have  2 1/2t + 3/2t + 9/8, if t [ 3/2, 1/2)  ∈ − −  2 3 1 1 2  t + /4, if t [ /2, /2) U (t) = − 2 ∈ − 1/2t 3/2t + 9/8, if t [1/2, 3/2)  − ∈ 0, elsewhere. Finally, convolving the above function with U 0, we notice that indeed U 3 = U, as expected. Observation 3.7. For every d > 0, the U d is non-zero only on the interval ( d+1 , d+1 ), where it is strictly positive. − 2 2 As promised earlier, we define a B-spline to be a sum over all its control points weighted by shifted copies of U d. Definition 3.8. A uniform polynomial B-spline C of degree d with control points P0,...,Pn (for some n > d) is defined by the formula n X  d 1 C(t) = P U d t i + − , for t 0, n (d 1). i − 2 ∈ − − i=0

A uniform rational B-spline with control points P0,...,Pn and weights w0, . . . , wn is n P d d 1  PiwiU t i + −2 i=0 −   C(t) = n , for t 0, n (d 1) . P d d 1  ∈ − − wiU t i + −2 i=0 − The construction of a B-spline is illustrated in Figures 4.8 and 4.9. Notice that, according to the definition, a B-spline is parametrized on the interval [0, n (d 1)] rather than the usual [0, 1]. One can of course re-parametrize it, taking− − t t0 = /(n d + 1), but the wider parameter space will be more convenient in what − follows. An immediate consequence of Observation 3.7 is the following “local-control property” of the B-spline representation:

Observation 3.9. Let C = C(P0,...,Pn) be a uniform B-spline with control points P ,...,P . The change of the position of the control point P influences only 0 n i the shape of the arc C [i d,i+1]. The same holds for rational B-splines, too. − Build: January 28, 2021 116 Rational parametric curves

d d 1 Proposition 3.10. For every d > 0 the function U is C − -smooth and piecewise polynomial of degree d.

d Proof. Let Ad be an antiderivative of U . Use Observation 3.6 to write d 1 1 U (t) = Ad 1(t + /2) Ad 1(t /2). − − − − Using the properties of an antiderivative we see that U 1 is piecewise linear and continuous and so U 2 is piecewise conic and C1-smooth. Proceed by an induction d d 1 will we show that U is of degree d and C − -smooth.  d 1 Corollary 3.11. A uniform B-spline of degree d is always C − -smooth. As elegant is the definition of U d, it is not very convenient, when it comes to explicitly write down the formula of a given B-spline. Thus we need to find another, yet still recursive, way to compute U d. Proposition 3.12. For every d > 0

d d + 1 + 2t d 1 1 d + 1 2t d 1 1 (3.13) U (t) = U − t + + − U − t . 2d · 2 2d · − 2 Proof. The proof is by induction. For d = 1 it is straightforward to verify 0 0 the assertion. Indeed, for t < 1 or t > 1 both U (t + 1/2) and U (t 1/2) are null, hence the right-hand-side of Eq.− (3.13) vanishes as expected. For −t [ 1, 0) we 0 0 ∈ − have U (t+ 1/2) = 1 and U (t 1/2) = 0. Consequently, the second term of the sum − 2t+1+1 disappears and the first one evaluates to 2 1 = t + 1. On the other hand, for t [0, 1], the first term vanishes and the second· gives 1 t. This proves our claim for∈ d = 1. − Assume that Eq. (3.13) holds for d 1. We shall show it for d. By Observa- tion 3.6 one has − Z t+1/2 d d 1 U (t) = U − (τ)dτ. t 1/2 − Use the inductive hypothesis to write: Z t+1/2 1 d 2 = (d + 2τ)U − (τ + 1/2)dτ + 2(d 1) t 1/2 − − Z t+1/2 1 d 2 + (d 2τ)U − (τ 1/2)dτ. 2(d 1) t 1/2 − − − − Compute both integrals by parts to get  Z t Z t+1  1 d 2 d 2 = (d + 1) U − (τ)dτ + U − (τ)dτ + 2(d 1) t 1 t − − Z t+1 Z t  ! d 2 d 2 d + 2t U − (τ)dτ U − (τ)dτ + 2U (t) . · t − t 1 − Use, Lemma 3.4 to write  1 d 1 1 = (d + 1 + 2t) U − t + 2(d 1) · − 2 −  d 1 1 d + (d + 1 2t) U − t + 2U (t) . − · − 2

Build: January 28, 2021 Rational parametric curves 117

Compare the first end the last term in the above series of equation. We have proved that d d 1 d 1 d 2(d 1)U (t) = (d + 1 + 2t)U − (t 1/2) + (d + 1 2t)U − (t 1/2) + 2U (t). − − − − Rearranging the terms we conclude the proof.  The proposition we have just proved gives rise to a recursive method of evalu- ating a point on a B-spline in a spirit of the de Casteljau’s and Barry-Goldman’s 0 0 algorithms. Take a B-spline C with some control points that we denote P0 ,...,Pn and fix a parameter t [0, n (d 1)]. Use Proposition 3.12 to write: ∈ − − n X  d 1 C(t) = P 0U d t i + − = i − 2 i=0 n   X 0 d + t i d 1 d 2 1 t + i d 1 d 2 = P − U − t (i 1) + − + − U − t i + − = i · d − − 2 d − 2 i=0

0 d + t d 1 d = P U − (t + )+ 0 · d 2 n 1 X−  0 0 d + t i 1 d 1 d 2 + lerp P ,P ; − − U − t i + − + i i+1 d · − 2 i=0

0 1 t + n d 1 d 2 + P − U − t n + − . n · d · − 2 Observe that the first and the last terms in the above expression are null. Indeed, d d d d 1 d 1 d t is non-negative and so t + /2 / ( /2, /2) = supp U − . Hence U − (t + /2) = 0. (d 2) ∈ d − d 1 (d 2) Analogously t n + − /2 = /2 thus also U − (t n + − /2) = 0. Denoting 1 0 − 0 d+t i 1 − − Pi := lerp(Pi ,Pi+1; −d − ) we abbreviate the formula to: n 1 X− 1 d 1 d 2 C(t) = P U − t i + − . i − 2 i=0

The right-hand-side is a B-spline, denote it C1, of degree d 1 with control points 1 1 − P0 ,...,Pn 1. Each control point of this new spline is a convex combination of control points− of the original spline C. Repeating the above procedure recursively, we build a new B-spline C of degree d 2, then C of degree d 3 and so on 2 − 3 − until we reach a degree zero, hence piecewise constant, B-spline Cd. Points of this d d d last curve are just its control points P0 ,...,Pn d. Consequently C(t) = Pk , where t 1 < k t. − − In each≤ iteration, the new control points are built as convex combinations of the control points from the previous step:

j  j 1 j 1 d + t i j  P = lerp P − ,P − ; − − . i i i+1 d j + 1 − It follows that they are convex combinations of the control points of the original d 0 0 spline C. In particular the point C(t) = Pk is a convex combination of P0 ,...,Pn . Considering that the weights depend only on: the parameter t, index i and degree d, it turns out we have proved: Observation 3.14. The B-spline representation is affinely invariant and has the convex hull property. Build: January 28, 2021 118 Rational parametric curves

Corollary 3.15. The rational B-spline representation is projectively invari- ant. Moreover, if the weights of all the control points are strictly positive, a rational B-spline curve has the convex hull property. The above procedure is known as the de Boor’s algorithm. Observe that only 0 0 d the points Pk ,...,Pk+d contribute to the position of the resulting point C(t) = Pk . Thus we can limit our computations to these points alone. A relevant pseudo- code is presented in Algorithm 5. The algorithm works both on polynomial as well as rational B-splines, providing that all the computations are performed in homogeneous coordinates.

Algorithm 5: The de Boor’s algorithm for uniform B-splines   P0,...,Pn : control points of a B-spline Input: d : the degree of the spline  t [0, n (d 1)] : a fixed parameter ∈ − − Output: C(t) – the point on the spline // find the (d + 1)-tuple of contributing control points k t ; ← d e t0 t k; ← − // rename the arguments 0 0 P0 := Pk,...,Pd := Pk+d; // main loop for j 1 to d do //← loop over the points for i 0 to d j do j← −j 1 j 1 d+t0 i j Pi lerp(Pi − ,Pi+1− ; d j−+1− ); ← − d return P0 ;

Example. Take a rational B-spline C of degree 5 with control points P0,...,P6 with coordinates respectively:  5  8  2 0 2 8 5 − , − , − , , , , 0 8 7 2 7 8 0 and weights: w = 2 and w = 1 for i = 3. Fix a parameter t = 3/2. The point 3 i 6 C(t) belongs to the segment controlled by P1,...,P6 and the corresponding local 1 parameter t0 is /2. The de Boor’s algorithms computes the position of C(t) in five steps. The computations are presented in Figure 4.10 while Figure 4.11 shows their geometric interpretation. All in all, the algorithm returns the point with the ho- T T mogeneous coordinates [4783/3840, 1471/256, 2761/1920] [1.2, 6, 1.5] ; consequently T T ≈ C(t) (1.2/1.5, 6/1.5) = (0.88, 4). ≈ 4. NURBS In the previous section we have defined uniform B-splines, now it is time to define non-uniform B-splines. Previously, the only building blocks were: the pulse function U 0 and a translation. Adding one more ingredient, namely a dilatation, we obtain non-uniform rational B-splines, commonly abbreviated as NURBS. Build: January 28, 2021 Rational parametric curves 119

 8  2 0 2 8 5 − −  8   7  4 7 8 0 1 1 2 1 1 1

- - - - -       2.5  0.62  1  4 8 − −  7   5   6  7 7 1 1.8 1.5 1 1

- - - -      0.88 0.38  2  4 −  5   5   6  7 1.5 1.5 1.2 1

- - -    0.19 1.2 2.5  5   6   6  1.5 1.5 1.2

- -

   1  1.5  6   6  1.5 1.5

-

 1.2  6  1.5

Figure 4.10. Successive iterations of the de Boor’s algorithm.

TO DO

Figure 4.11. Illustration of the de Boor’s algorithm.

Fix a non-decreasing sequence of real numbers u0 u1 un. We will refer to them as knots. For every 0 i < n let N 0 be the≤ pulse≤ function · · · ≤ associated ≤ i to the interval [ui, ui+1): ( 1, if t [u , u ), N 0(t) := ∈ i i+1 i 0, otherwise.

0 0 It is clear that Ni is obtained by translation and dilatation of U .

Observation 4.1. Let Tα denotes a translation Tα(t) = t + α and Sβ a scaling S (t) = β t. If u = u , then β · i+1 6 i 0 0 N = U S 1 T ui+1+ui . i u −u ◦ i+1 i ◦ − 2 Build: January 28, 2021 120 Rational parametric curves

In order to define basis function of higher degrees, we generalize Eq. 3.12. Take d a uniform knot vector: u0 = 0, u1 = 1, . . . , ud = d. We want Ni to identical with d d U T i 1/2 (d+1), so that the support of Ni is (i, i+d+1). Proposition 3.12 asserts that◦ − − ·

 d + 1 N d(t) = U d t i = i − − 2 t i d 1 d i + d + 1 t d 1 d = − U − t i + − U − t (i + 1) = d · − − 2 d · − − 2 t ui d 1 ui+d+1 t d 1 = − N − (t) + − N − (t). u u · i u u · i+1 i+d − i id+1 − i+1 d We use the last formula to define Ni for any non-decreasing sequence of knots.

Definition 4.2. Fix a non-decreasing sequence of knots u0 u1 un with n > d. For d > 0 let ≤ ≤ · · · ≤

d t ui d 1 ui+d+1 t d 1 (4.3) N (t) := − N − (t) + − N − (t). i u u · i u u · i+1 i+d − i id+1 − i+1 Observe that the definition may lead to an indeterminate expression 0/0, if the inequalities in the knot sequence are not strict. We solve this obstacle by passing to the limit. Consider a sequence of knot vectors (Uk)k , where Uk consists of knots ∈N uk,0 uk,n with strict inequalities only. The length of all the knot vectors is constant··· and equal n. Fix an index i 0, . . . , n d and assume that in our sequence ∈ − of knot vectors, all the knots are constant save the knots uk,i+1, . . . , uk,i+d, while the remaining d knots converge to u := u const: i k,i ≡ ( u = = u = , for j / i + 1, . . . , i + d 0,j ··· k,j ··· ∈ { } lim uk,i uk,j = 0, for j i + 1, . . . , i + d . k | − | ∈ { } →∞ d The knot vectors give rise to associated functions Nk,i. All these functions are well defined since we assumed that all the inequalities in every knot vectors are strict. We claim that the sequence (N d k N) converges to a function Nˆ d defined k,i | ∈ i recursively:

d ui+d+1 t d 1 Nˆ (t) = − Nˆ − (t). i u u i+1 i+d+1 − i+1 d Fix a parameter t (u0, un). We will show in 4.5 that the support of Ni is d ∈ d 1 d 1 supp N (u , u ). It follows that for t u or t u both N − and N − i i i+d+1 ≤ i ≥ i+d+1 k,i k,i+1 vanish at t for every k. Hence

d t uk,i d uk,i+d+1 t d 1 N (t) = − N (t) + − N − (t) = 0. k,i u u · k,i u u · k,i+1 k,i+d − k,i k,i+d+1 − k,i+1 Likewise

d ui+d+1 t d 1 Nˆ (t) = − Nˆ − (t) = 0 i u u · i+1 i+d+1 − i+1 d ˆ d and so trivially Nk,i(t) Ni (t). −−−−→k →∞ Build: January 28, 2021 Rational parametric curves 121

Now suppose that t (ui, ui+d+1). For k sufficiently large t > uk,i+d, therefore d 1 ∈ Nk,i− (t) = 0. It follows that

d t uk,i d uk,i+d+1 t d 1 N (t) = − N (t) + − N − (t) = k,i u u · k,i u u · k,i+1 k,i+d − k,i k,i+d+1 − k,i+1 ui+d+1 t d 1 = − Nˆ − (t). u u · i+1 i+d+1 − i+1 d ˆ d Thus Nk,i(t) Ni (t) for every t. This proves our claim. −−−−→k One can show→∞ that if d knots converge to a fixed knot from left, then the similar argumentation as above shows that it is the other part of Eq. (4.3) which vanishes. All in all we may summarize our discussion as follows:

Observation 4.4. If any of the fractions in Eq. (4.3) results in an indetermi- nate expression 0/0, then the corresponding term shall be omitted in the formula for d 0 Ni (in other words /0 reads as 0).

d d Observation 4.5. The support of Ni is supp Ni = (ui, ui+d+1), except the 0 case d = 0, when supp Ni = [ui, ui+1).

0 Proof. This follows immediately by an induction. The support of Ni is [ui, ui+1) straight from the definition. Now, for every other degree d, the function d d 1 d 1 Ni is a linear combination of Ni − and Ni+1− . Therefore it is a linear combination 0 0 of Ni ,...,Ni+1. Consequently

i+d [ supp N d supp N 0 = [u , u ). i ⊂ j i i+d+1 j=0

d It is easy to verify that for any d > 0, the function Ni vanishes on the left end of this interval. Indeed,

d ui ui d 1 ui+d+ ui d 1 N (u ) = − N − (u ) + − N − (u ) = 0 + 0 = 0. i i u u i i u u i+1 i i+d − i i+d+1 − i+1 1 On the other hand, for i < j < i + d + i, already Nj 1(uj) = 0, hence inductively − 6 N d(u ) = 0. It is trivial that for t (u , u ) not a knot N d(t) = 0. i j 6 ∈ i i+d+1 i 6  Definition 4.6. A non-uniform polynomial B-spline of degree d with control points P ,...,P , n d and knots u u is defined by the formula 0 n ≥ 0 ≤ · · · ≤ n+d+1 n X C(t) = P N d(t), for t [u , u ]. i i ∈ d n+1 i=0 A non-uniform rational B-spline (NURBS in short) of degree d with control points P ,...,P , n d, weights w , . . . , w and knots u u is 0 n ≥ 0 n 0 ≤ · · · ≤ n+d+1 n P d PiwiNi (t) i=0 C(t) = n , for t [ud, un+1]. P d ∈ wiNi (t) i=0 Build: January 28, 2021 122 Rational parametric curves

We wish to emphasize the point that the parameter t varies not over the whole interval [u0, un+d+1] but over the subinterval [ud, un+1]. This is the closure of the d d set where the supports of d + 1 consecutive functions Ni ,...,Ni+d intersect:  n d i+d  [− \ d [ud, un+1] = cl supp Nj . i=0 j=i In real-life applications, one usually sets u = = u and u = = u 0 ··· d n+1 ··· n+d+1 or even u0 = = ud = 0 and un+1 = = un+d+1 = 1. A direct consequence of Observation 4.5··· is the following local-control··· property. Corollary 4.7. The change of the position of the control point P (respectively i of its weight wi) affects only the arc C [ui,ui+d+1].

Recall that we allow some knots to be equal. We say that a knot ui has multiplicity m, if ui 1 < ui = ui+1 = = ui+m 1 < ui+m. − ··· − Lemma 4.8. Fix knots u0 un+d+1. If the multiplicity of the knots do ≤ · · · ≤ d not exceed d, then for any t (ud, un+1) all Ni (t) are non-negative and they sum up to the unity: ∈ n X d Ni (t) = 1. i=0 Proof. The proof is by induction. For d = 0 the assertion is trivial. For d > 0 it follows directly form Eq. (4.3).  Along exactly the same lines as for uniform B-splines, one shows that a point C(t) on the curve C is a convex combination, providing that all the weights are positive (otherwise it is a linear combination), of the control points of C. Observation 4.9. The non-uniform polynomial B-spline representation is affinely invariant and has the convex hull property. Observation 4.10. The non-uniform rational B-spline representation is pro- jectively invariant. Moreover, if all the weights are positive, it also has the convex hull property. The de Boor’s alogithm (c.f. Algorithm 5) can now be easily adjusted to non- uniform splines. One simply uses Eq. (4.3) in place of Eq. (3.13). It follows that j SPR! the point Pi (we us the same notation as in the previous section) is computed as j  j 1 j 1 t ui+1  P = lerp P − ,P − ; − . i i i+1 u u i+d+1 − i+1 The pseudo-code is presented in Algorithm 6. Proposition 4.11. Let C be a non-uniform spline of degree d 1 with control ≥ points P0,...,Pn and knots u0 un+d+1. If the multiplicity of some knot u (with d k n + 1) equals≤ the · · · degree ≤ of C, then the spline interpolates the k ≤ ≤ corresponding control point, namely C(uk) = Pk.[[[TO DOczy indeksacja jest OK. na przyklad na lewym ko´ncu]]]

d Proof. The support of Ni is (ui, ui+d+1) by Observation 4.5. Consider five possible cases: if i < k d 1, then u < u and so u / supp N d; • − − i+d+1 k k ∈ i Build: January 28, 2021 Rational parametric curves 123

Algorithm 6: The de Boor’s algorithm for non-uniform B-splines   P0,...,Pn : control points of a B-spline  d : the degree of the spline Input:  u0, . . . , un+d+1 : knots  t [u , u ] : a fixed parameter ∈ d n+1 Output: C(t) – the point on the spline // find the (d + 1)-tuple of contributing control points k d; ← while t > uk+1 do k k + 1; ← // rename the arguments 0 0 P0 := Pk,...,Pd := Pk+d; // main loop for j 1 to d do //← loop over the points for i 0 to d j do j← −j 1 j 1 t ui+1 P lerp(P − ,P − ; − ); i i i+1 ui+d+1 ui+1 ← − d return P0 ;

d if k d 1 i k 2, then supp Ni = (ui, ui+d 1) = (ui, uk) and again • − − ≤d ≤ − − uk / supp Ni ; ∈ d if i = k 1, then uk supp Nk 1; • − ∈ − d d if k i k + d 1, then supp Ni = (uk, ui+d 1) and uk / supp Ni ; • finally≤ if≤k + d −i, then u < u and u / supp− N d. ∈ • ≤ k i k ∈ i d All in all, Nk 1 is the only function that does not vanish at uk. It follows now from − d (Pkwk) Lemma 4.8 that Nk 1(uk) = 1. Consequently C(uk) = /wk = Pk.  − d 1 Recall that a uniform B-spline of degree d was always C − -continuous. The same holds for non-uniform B-splines, unless we encounter a knot with the multi- plicity greater than one.

Proposition 4.12. Take a B-spline C of degree d and let ui be its knot. If d m the multiplicity of ui is m, then C is C − -continuous at ui. Moreover, C is C∞-smooth in-between the knots. It is easy, we let the reader provide the proof. Consider now an extreme case, when the knots’ multiplicities are as high as possible: half of the knots are equal zero and the other half are equal one. If this is the case, then the NURBS curve “degenerates” to a B´ezierone.

Proposition 4.13. Let u0 = = ud = 0 and ud+1 = = u2d+1 = 1. The associated non-uniform B-spline of··· degree d is identical to a··· B´ezierspline with the same control points (either polynomial or rational). Proof. It suffices to show that, under the assumptions of the proposition, d d d d the resulting functions N0 ,...,Nd equal the Bernstein polynomials b0, . . . , bd (see 0 Eq. (2.1)) on the unit interval. To this end we use induction. Observe that all Ni Build: January 28, 2021 124 Rational parametric curves

0 vanish everywhere, with the single exception of Nd which equals 1 on [0, 1). Con- 1 1 1 sequently, all Ni vanish everywhere, except Nd 1 and Nd that equal respectively: − 1 ud+1 t 0 1 t ud 0 Nd 1(t) = 0 + − Nd (t) = 1 t, Nd (t) = − Nd (t) + 0 = t. − u u − u u d+1 − d d+1 − d 1 1 Hence they equal b0 and b1 respectively. Now observe that in our case, for s d and i d s, . . . , d , the formula Eq. (4.3) simplifies to ≤ ∈ { − } s s 1 s 1 N (t) = t N − (t) + (1 t)N − (t). i · i − i+1 1 1 Since we have already proved that Ni = bi d+1, it follows from Lemma 2.9 that s s d d − Ni = bi d+s. In particular Ni = bi .  − 5. Tangent and curvature 6. On-curve alignment 7. Manifolds and geometric continuity 8. Arc-length parametrization Exercises

(1) Let C = C(P0,...,Pd) be a polynomial curve in an affinely invariant representation. Show that the curve is contained in some affine subspace U if and only if all the control points P0,...,Pd of C lie in U. Use this result to give an alternative geometric proof of Observation 1.3. (2) Prove Proposition 1.4. (3) Prove the following explicit, non-recursive formula for the function U d, defining uniform B-splines of degree d: d+1 ( X ωd(t i) xd, if x 0 U d(t) = (d + 1) − , ωd(x) := ≥ · d+1 0, if x < 0. i=0 Q (j i) j=0 − j=i 6

Build: January 28, 2021 CHAPTER 5

Spherical curves

“you know, all that stuff about three right angles making a triangle.” — T. Pratchett

1. Transformation interpolation revisited

Build: January 28, 2021

CHAPTER 6

Algebraic curves

“Eliminate, eliminate, eliminate, Eliminate the eliminators of elimination theory.” — S.S. Abhyankar

The previous few chapters discussed parametric curves, obtained by mapping a real interval to a subset of a three-dimensional space. This type of curves is most often encountered in applications. Nevertheless, they are not the only ones. This chapter deals with another type of curves known, as algebraic curves. They are sometimes called implicit curves 1, as well. Contrary to the rest of this book, in this chapter we restrict our discussion only to plane curves. Although the vast majority of the results generalizes to space curves, the latter case requires a stronger background from than we can provide here.

1. Affine algebraic curves

In what follows, the symbol K will always denote a fixed subfield of the field C of the complex numbers. In practice, K equals either R or C. The pair (f, Cf ) consist-  T 2 ing of a polynomial f K[x, y] and its zero locus Cf = (x, y) K f(x, y) = 0 is called an algebraic∈ curve. As in the previous chapters we simplify∈ | the notation writing Cf alone, as long as it does not lead to any confusion. Elementary exam- ples of algebraic curves are: an affine line (the associated polynomial is of the form ax + by + c) and a circle (the associated polynomial is (x a)2 + (y b)2 r2). − − − Observe that for any non-zero scalar a K 0 we have Cf = Caf . Therefore, we identify two algebraic curves if their associated∈ \{ } polynomials are proportional. Formerly speaking, we define an equivalence relation on the set of algebraic curves so that (f, C ) = (g, C ) if and only if f = ag for some a = 0. f ∼ g 6 The ring R[x, y] of bivariate polynomials over the reals is a subring of C[x, y]. In particular, every real polynomial f R[x, y] may be treated as a polynomial ∈  T 2 over C. Hence a real Cf (R) = (x, y) R f(x, y) = 0 forms  T∈ 2| a subset of a complex algebraic curve Cf (C) = (x, y) C f(x, y) = 0 with the same associated polynomial f. The elements of the∈ former| set are called the real points of Cf . In what follows we need the following, rather elementary fact; we state it explicitly in order to simplify future referencing.

Observation 1.1. Let f R[t] be a real polynomial. A complex number z C is a root of f if and only if its∈ conjugate z is a root of f. ∈

1Strictly speaking, the class of implicit curves is broader than the class of algebraic curves.

Build: January 28, 2021 128 Algebraic curves

Let us emphasize the fact that although a polynomial f determines its zero- locus Cf , the assignment f Cf is not one-to-one, in general. Scalar multiplica- tion, mentioned earlier, being7→ the least problem here. Consider two real polynomials f = (x2 + 1)y R[x, y] and g = y R(x, y]. Their associated (real) zero-loci are equal because in∈ both cases it is just∈ a line y = 0 . On the other hand, the sets of their complex zeros do differ since f(i, 1){ = 0,} while g(i, 1) = 1. In fact the following holds:

Theorem 1.2. Let f C[x, y] be a square-free2 complex polynomial and let ∈ (f, Cf ) be the associated algebraic curve. If g C[x, y] is another polynomial such ∈ that g Cf 0, then f divides g. In particular, the set Cf determines f uniquely up to a scalar≡ multiplication.

The above theorem is a special case of the celebrated Hilbert’s Nullstellensatz. The reader may find its general version, together with a proof, in [17, Chapter IX, §1]. In the rest of this chapter we will consider only curves associated to square-free polynomials. This assumption allows us to define the degree of an algebraic curve (f, Cf ) to be the degree of the associated polynomial f. Observe that if f is a product of two polynomials f = gh, then its zero-locus is a union Cf = Cg Ch. Indeed, a point P belongs to the set Cg Ch if and only if either g(P ) = 0 or∪h(P ) = 0. This is equivalent to the condition∪f(P ) = 0. The algebraic curve (f, Cf ) is called irreducible if f cannot be factored into terms of lower degree (i.e. if f is an irreducible polynomial).

2. Resultants In order to continue our discussion about algebraic curves, we shall introduce a special “tool” known as a . On start let us contemplate the following 2 example. Consider two quadratic polynomials f = f0 + f1t + f2t and g = g0 + 2 g1t + g2t . Our aim is to decide, whether they have a common root. Treat the consecutive powers t0, t1, t2 of t as if they were independent variables. Therefore, our problem reduces to a question about the existence of non-trivial solutions to the system of “linear” equations

( 0 1 2 f0t + f1t + f2t = 0 0 1 2 g0t + g1t + g2t = 0. We have only two equations here but three “variables”. Fortunately, we can easily produce two more equations multiplying the above ones by t, at the same time introducing only one new “variable” t3. This way we get a system of four “linear” equations in four “variables”: t0, t1, t2, t3.

 0 1 2 f0t + f1t + f2t = 0  1 2 3  f0t + f1t + f2t = 0 g t0 + g t1 + g t2 = 0  0 1 2  1 2 3 g0t + g1t + f2t = 0.

2A polynomial is called square-free if it is not divisible by a square of any polynomial of a positive degree.

Build: January 28, 2021 Algebraic curves 129

As we know (from the course of linear algebra), the system has a non-trivial solution if and only if its determinant vanishes, i.e.   f0 f1 f2 0  0 f0 f1 f2 det   = 0. g0 g1 g2 0  0 g0 g1 g2 This means that, the polynomials f and g have a common root only if the above determinant is null. This is also a sufficient condition, as we shall shortly discover. Recall that an integral ring R is called a unique factorization domain if every non-invertible element, except zero, has a unique factorization into primes (irre- ducible elements). Typical examples of unique factorization domains are the ring of integers and rings of polynomials (of any number of variables) over a field. For further details see e.g. [17, Chapter II, §5]. Let f, g R[t] be two polynomials over a unique factorization domain R. De- ∈ note their degrees respectively n := deg f and m := deg g. Let f = f0 + f1t + + n m ··· fnt and g = g0 + g1t + + gmt with fn = 0 and gm = 0. The Sylvester matrix associated to f and g is the··· square matrix of6 the size (m +6 n) (m + n) of the form ×   f0 g0  .. ..  f1 . g1 .     ......   . . f0 . . g0    fn f1 gm g1     . . . .   ......    fn gm | {zm } | {zn } The determinant of this matrix is called the Sylvester resultant of the polynomials f and g with respect to the variable t. We denote it Rest(f, g). Example. Consider the following two polynomials f = 2 + 3x 4y + xy2 2y3 − − and g = 1 + x y + 2x2 + 3y3. Take R = R[x] and compute the Sylvester resultant −

Resy(f, g) = 3x + 2 0 0 2x2 + x + 1 0 0   4 3x + 2 0 1 2x2 + x + 1 0   − −   x 4 3x + 2 0 1 2x2 + x + 1 det  − −  =  2 x 4 3 0 1   − − −   0 2 x 0 3 0  0− 0 2 0 0 3 − = 12x7 + 76x6 + 239x5 + 902x4 + 2511x3 + 4788x2 + 2100x + 904. On the other hand, Res (f, g) = 3y7 + 8y6 + 19y5 + 33y4 + 15y3 + 36y2 29y + 11. x − Proposition 2.1. The polynomials f, g R[t] have a non-trivial common ∈ divisor in R[t] if and only if Rest(f, g) = 0. Proof. Suppose that a non-constant polynomial h divides both f and g. Thus, there are some polynomials p, q R[t] satisfying f = hp and g = hq with deg p < ∈ Build: January 28, 2021 130 Algebraic curves deg f and deg q < deg g. This leads to the equation (2.2) fq = gp. Conversely, assume that Eq. (2.2) holds for some p, q R[t] with deg p < deg f and deg q < deg g, then gp is divisible by every prime divisor∈ of f. Now, the degree of p is strictly smaller than the degree of f, hence at least one prime divisor of f divides g, as well. k l Let p = p0 + p1t + + pkt and q = ( q0) + ( q1)t + + ( ql)t . Comparing the coefficients of the consecutive··· powers− of t in Eq.− (2.2)··· one builds− the following system of linear equations with variables p0, . . . , pk, q0, . . . , ql:   p0f0 = q0g0  −  p0f1 + p1f0 = q0g1 q1g0 ...... − −  p f + p f = q g + q g  k n 1 k 1 n l m 1 l1 m  − −p f = − − q g . k n − l m The appropriate polynomials p, q exist, when the system has a non-trivial solution. And this happens if and only if the determinant of the system is null. But the determinant is exactly the resultant of f and g.  Recall that every polynomial over an algebraically closed field factors into linear terms. Hence, passing to the algebraic closer of the fraction field of R (i.e. to the smallest algebraically closed field containing R), we have:

Corollary 2.3. The resultant Rest(f, g) of two polynomials f, g R[t] van- ishes if and only if they have a common root in the algebraic closer of the∈ fraction field of R. By its very definition, the resultant of two polynomials is a sum of prod- ucts of their coefficients. In other words, Rest(f, g) is an element of the ring Z[f0, . . . , fn, g0, . . . , gm]. In fact, it can be proved (see e.g. [25, Theorem 3.1]) that it is an irreducible element even in C[f0, . . . , fn, g0, . . . , gm]. We will use the notion of the resultant to define such important terms like a discriminant or an (for the latter see Section 4, below).

Definition 2.4. Let f be a polynomial of degree n, and lc(f) = fn be its leading coefficient. An expression n·(n−1) ( 1) 2 ∆ := − Res (f, g0) f lc(f) · t is called the discriminant of f. As an example let us compute the discriminant of a quadratic polynomial f = 2 at + bt + c, with a = 0. We have f 0 = 2at + b and so 6   2·(2−1) a 2a 0 2 ( 1) 1 2 ∆f = − Rest(f, f 0) = − det b b 2a = b 4ac. a a · · c 0 b − As we learned in a high school, the quadratic polynomial f has a double root if and only if ∆f = 0. This is not a random coincidence. Lemma 2.5. Let f R[t] be a fixed polynomial. A number t is a multiple root ∈ 0 of f if and only if it is a common root of both f and f 0. Build: January 28, 2021 Algebraic curves 131

k Proof. Let t0 be a root of f with multiplicity k 1. Hence (t t0) divides f. Say f = (t t )kg, with g(t ) = 0. Compute the derivative≥ − − 0 0 6 k  k 1 k k 1  f 0(t) = (t t ) g 0 = k(t t ) − g + (t t ) g0 = (t t ) − kg + (t t )g0 . − 0 − 0 − 0 − 0 − 0 It follows that (t t ) divides f 0 if and only if k 1 > 0. − 0 −  Combine the above lemma with Corollary 2.3 to get: Corollary 2.6. A polynomial f has a multiple root (in an algebraically closed field) if and only if it has a zero discriminant. As important the Sylvester resultant is from the theoretical point of view, it is not well behaving numerically when we need to actually compute it using floating-point arithmetic (see e.g. [21]). It is a B´ezoutresultant that rules in real life applications. Take two polynomials f, g R[t] of equal degrees. Denote this common degree by n. Define a polynomial ∈ R[t , t ] by the formula Bf,g ∈ o 1 f(t )g(t ) f(t )g(t ) (2.7) (t , t ) := 0 1 − 1 0 . Bf,g 0 1 t t 0 − 1 i j Let bi,j be the coefficient of f,g at t0t1. The degree of f,g with respect to each variable is deg = deg B = n 1. Moreover, Bis symmetric in the sense t0 Bf,g t1 Bf,g − Bf,g that f,g(t1, t0) = f,g(t0, t1). It follows that bi,j = bj,i for all indexes i, j. In other words,B once we writeB in the matrix form Bf,g     1 b0,0 b0,n 1 ··· − t1 n 1 . .   (t , t ) = 1, t , . . . , t −  . .    f,g 0 1 0 0  . .   .  B  .  bn 1,0 bn 1,n 1 n 1 , − ··· − − t1 − the matrix of coefficients is symmetric. The determinant of this matrix is called the B B´ezoutresultant of f and g with respect to the variable t and denoted Rest (f, g). It is not very convenient to compute the coefficients of f,g directly from the def- inition. Fortunately, there is a better method. Consider theB numerator in Eq. (2.7). We can express it as follows:

f(t )g(t ) f(t )g(t ) = 0 1 − 1 0  X  = (t t ) b ti tj = 0 − 1 ij 0 1 0 i,j n 1 ≤ ≤ − X X = b ti+1tj b ti tj+1. ij 0 1 − ij 0 1 0 i,j n 1 0 i,j n 1 ≤ ≤ − ≤ ≤ − i j Let ci,j denote the coefficient at t0t1 in the above formula (as usually, we set ci,j = 0 if the corresponding term does not appear in the sum). We may express ci,j as   fi fj ci,j = det = bi 1,j bi,j 1. gi gj − − −

Our goal is to compute bi,j. It appears twice, namely in the following two expres- sions:

ci+1,j = bi,j bi+1,j 1 and ci,j+1 = bi 1,j+1 bi,j. − − − − Build: January 28, 2021 132 Algebraic curves

Recall that bi,j = bj,i, hence without loss of generality we may assume that i j. The first of the above equations give rise to a simple recursive formula ≥ M   X fi+k fj+1 k bi,j = ci+1,j+bi+1,j 1 = ci+1,j+ci+2,j 1+bi+2,j 2 = = det − , − − − ··· gi+k gj+1 k k=1 − with M = min j + 1, n i . With the help of this formula, we may fill the matrix { − } of coefficients of f,g, diagonal after diagonal, starting at the bottom-left and top- right corners andB proceeding toward the main diagonal. The pseudo-code of this procedure is presented in Algorithm 7.

Algorithm 7: B´ezoutmatrix construction

Input: f0, . . . , fn, g0, . . . , gn: coefficients of polynomials f and g Output: (b ): matrix of coefficients of i,j Bf,g for j 0 to n 1 do for←k 0 to−j do ←   c det fn−j+k fk ; ← gn−j+k gk if (n j + k n 1) (k 1 0) then − ≤ − ∧ − ≥ c c + bn j+k,k 1; ← − − bn 1 j+k,k c; − − ← bk,n 1 j+k c; − − ←

2 3 2 3 For instance, if f = f0 + f1t + f2t + f3t and g = g0 + g1t + g2t + g3t are two cubic polynomials, then the matrix is computed as

 f1 f0  f2 f0  f3 f0  det g1 g0 det g2 g0 det g3 g0 f2 f0  f2 f1  f3 f0  f3 f1  det g2 g0 det g2 g1 + det g3 g0 det g3 g1  f3 f0  f3 f1  f3 f2  . det g3 g0 det g3 g1 det g3 g2

The only coefficient computed recursively is the central one b1,1 = c2,1 + b2,0. Example. Consider the same two polynomials as in the previous example f = (2 + 3x) 4y + xy2 2y3 and g = (1 + x + 2x2) y + 3y3. The B´ezoutresultant of f and g with− respect− to the variable y is −

B Resy (f, g) =   4 2+3x   x 2+3x   2 2+3x  − 2 2 − 2 det 1 1+x+2x det 0 1+x+2x det 3 1+x+2x −   x 2+3x  x 4   2 2+3x  2 4    2 − 2  = det det 0 1+x+2x det 0 −1 + det 3 1+x+2x det −3 −1 =  − −    2 2+3x  2 4  2 x   − 2 det 3 1+x+2x det −3 −1 det −3 0 − = 12x7 + 76x6 + 239x5 + 902x4 + 2511x3 + 4788x2 + 2100x + 904. Notice that the Sylvester and B´ezoutresultants computed in the last two ex- amples are identical. In order to explain why, we need to investigate how the two notions relate to each other. Take a Sylvester matrix and write it as a block-matrix F1 G1  of the form consisting of four n n cells. The matrices F1 and G1 are F2 G2 × Build: January 28, 2021 Algebraic curves 133

lower-triangular, while the cells F2, G2 are upper-triangular. Consequently, the product F G is again a lower-triangular matrix. It has the form 1 · 1  d 0 0  0 ···  .. .   d1 d0 . .     . . .   . .. .. 0  , dn 1 d1 d0 − ··· Pk with dk = figk i. Notice that, multiplication of these two matrices in the i=0 − opposite order renders the same result. This means that F1 and G1 commute. Write F G  I G  F 0  1 1 − 1 = 1 F2 G2 · 0 F1 F2 G2F1 F2G1 − and compute the determinants of both sides. Observe that the first term on the left-hand-side is just the Sylvester matrix, hence Res (f, g) det(F ) = det(F ) det(G F F G ). t · 1 1 · 2 1 − 2 1 The matrix G F F G that appears in the above expression closely reassembles 2 1 − 2 1 the matrix of coefficients of f,g, except that the order of rows is reversed and all the enries have opposite signs.B Indeed, the element in the ith row and jth column of this matrix is computed as

(fn j 1gi+1 fi+1gn j 1) + (fn j 2gi+2 fi+2gn j 2) + = − − − − − − − − − − ··· M   X fn j k fi+k = det − − = bi,n 1 j. gn j k gi+k − − − k=1 − − Reversing the order of rows one switches the sign of the determinant of the matrix exactly n/2 times, while changing the sign of all the entries, one switches the sign b c of the determinant next n times. Thus, the determinant of G2F1 F2G1 equals n/2 n − n(n + 1)/2 the B´ezoutresultant of f and g multiplied by ( 1)b c ( 1) = ( 1) . Therefore, we have proved the following result: − · − − Proposition 2.8. Let f and g be two polynomials of degree n, then

n(n+1) B Res (f, g) = ( 1) 2 Res (f, g). t − t In particular, for cubic polynomials, we have ( 1)3 · 4/2 = 1 and so the two resultants are equal, as observed above. −

3. Projective algebraic curves In the first part of this book, we have defined the projective plane. Recall that the projective coordinates of a point P P2K are of the form x : y : w and are unique only up to a multiplication by a∈ non-zero scalar. ThisJ requiresK a special care when it comes to defining algebraic curves in a projective realm. Observe that, in general, it does not make any sense to talk about a value of a polynomial (of three variables) at a point of P2K. Indeed, take for example a polynomial f = x2 + y3 w + 1 and a point P = 1 : 1 : 1 , then f(1, 1, 1) = 0, but 1 : 1 : 1 are another− coordinates of the veryJ same− pointK P while−f( 1, 1, 1) =J 4−= 0. Thus,− K there is absolutely no way that one could give any meaning− to− the symbol6 f(P ). Build: January 28, 2021 134 Algebraic curves

Consequently, in order to define projective curves, we have to restrict ourselves to a special class of polynomials.

Definition 3.1. A polynomial F K[x0, . . . , xk] of the form ∈ m X d d F = a x 0,i x k,i i 0 ··· k i=0 is called homogeneous of degree d if d + + d = d for every 0 i m. 0,i ··· k,i ≤ ≤ In other words, a homogeneous polynomial is a sum of monomials, all of the same total degree d. For example, a polynomial 2x3 3xy2 + xyw is homogeneous of degree 3. It is not difficult to give an equivalent condition− for homogeneity.

Observation 3.2. A polynomial F K[x0, . . . , xk] is homogeneous of degree d if and only if the condition ∈ d F (ax0, . . . , axk) = a F (x1, . . . , xk) is satisfied for every a K. ∈ The above observation is crucial for defining projective algebraic curves. Al- though the value of a trivariate homogeneous polynomial F on one set of coordinates x : y : w of a projective point P still differs (by a factor ad) from its value on Janother setK of coordinates ax : ay : aw of P , but now either both are zero or both are non-zero (and different).J Thus, it isK possible to define the zero-locus of F .

Definition 3.3. A projective algebraic curve is a pair (F,CF ) consisting of a homogeneous polynomial F and its zero-locus  2 CF = x : y : w P K F (x, y, z) = 0 . J K ∈ | As in the affine case, we tend to simplify the notation, writing CF alone, when it does not lead to any confusion. We identify two curves CF and CG, when F = aG for some a K, a = 0. The degree of a projective algebraic curve is the degree of its defining∈ polynomial.6 We used to homogenize and dehomogenize coordinates of points in Chapter 1. We may do the same with polynomials. Let F K[x0, . . . , xk] be a homogeneous ∈ polynomial. We define the dehomogenization f K[x0, . . . , xk 1] of F (with respect ∈ − to the variable xk) by the formula

f(x0, . . . , xk 1) := F (x0, . . . , xk 1, 1). − − Analogously, one defines the dehomogenization with respect to any other variable. The opposite operation, called homogenization, assigns to a (non-homogeneous) polynomial f K[x0, . . . , xk 1] the homogeneous polynomial F K[x0, . . . , xk] defined in the following∈ way − ∈ deg f x0 xk 1  F (x0, . . . , xk) := xk f ,..., − . · xk xk The polynomial F has the same degree as f. Moreover, if the non-homogeneous polynomial is given as a sum n X c0,i ck−1,i f = aix0 xk 1 , ··· − i=0 Build: January 28, 2021 Algebraic curves 135 then its homogenization is given by a similar sum of monomials but with the addi- tional variable xk raised to a “missing degree”: n X c0,i ck−1,i deg f c0,i ck−1,i − −···− F = aix0 xk 1 xk . ··· − i=0 As an explicit example, take f = x2 + xy2 + y. Then deg f = 3 and so its homoge- nization is F = x2w + xy2 + yw2. Recall (see Section 1 of Chapter 1) that the projective plane is a union of the 2 affine plane K and the line at infinity. Fix a projective algebraic curve (F,CF ). Let f K[x, y] be the dehomogenization of the polynomial F . Take an affine point ∈ T P = (x0, y0) . Homogenize its coordinates to get a point on the projective plane (denoted P again) having projective coordinates x0 : y0 : 1 . If P lies on CF , J K then F (x0, y0, 1) = 0. But F (x0, y0, 1) is just f(x0, y0). Hence P lies on the affine algebraic curve (f, Cf ). Thus we have just proved: Proposition 3.4. The intersection of the affine plane with a projective alge- braic curve (F,CF ) is the affine algebraic curve (f, Cf ), where f is the dehomoge- nization of F . For instance the intersection of a projective line ax+by+cw = 0 with the affine plane gives the affine line ax + by + c = 0. Similarly a parabola ax2 + bx + c = 0 is obtained from the projective conic associated to the polynomial{ ax2 +bxw +cw2}. The following observation is quite simple. Nevertheless it deserves to be stated explicitly as we will apply it frequently.

Observation 3.5. Let G be a homogeneous polynomial and (G, CG) be an associated algebraic curve. If Φ: P2K P2K is a projective automorphism, then F := G Φ is a homogeneous polynomial→ and Φ(C ) = C . ◦ F G Definition 3.6. We say that two algebraic curves CF and CG are projectively equivalent if there is a projective automorphism Φ : P2R P2R sending one onto → the other (i.e. F = G Φ and CG = Φ(CF )). They are affinely equivalent if there is an appropriate affine◦ automorphism. One subject that frequently reappears in geometric modeling is the problem of finding a curve that interpolates a given set of points. Take for example five points (for simplicity assume they are all affine): 0  1  3 4 0 , , , , . 0 1 0 1 1 − The Lagrange interpolation formula provides us with two polynomials x, y R[t] both of degree 4 that interpolate respectively the abscissas and ordinates∈ of the above points. Hence, there is a quartic parametric polynomial curve C(t) = x(t), y(t)T passing through all five points. If we do not wish to struggle with quartic curves, we may find a piecewise polynomial cubic curve using the methods described in Section 3 of Chapter 3. Yet, the algebraic curves beat down the degree even further. Observe that an algebraic curve given by the polynomial f = y2 2xy y + 2x2 6x − − − interpolates all five points. And its degree is only two. This is an evident advantage of algebraic curves over the parametric ones. The existence of such a curve follows from Corollary 3.8 below. Build: January 28, 2021 136 Algebraic curves

Theorem 3.7. Let P1,...,Pm be a fixed pair-wise distinct points in the pro- 2 (d+2)(d+1) jective plane P K with n = 2 1. Then there exists an algebraic curve (possibly reducible) of degree d interpolating− all these points. Proof. A homogeneous trivariate polynomial of degree d is a sum of the mono- mials xiyjwk with i + j + k = d. Therefore, the set of all such polynomials is a (d+2)(d+1) linear space of dimension . Let xi : yi : wi be the projective coordinates 2 J K of the point Pi. Form a system of linear equations  d d 1 d 1 d ad,0,0x1 + ad 1,1,0x1− y1 + ad 1,0,1x1− w1 + + a0,0,dw1 = 0  − − ··· ......  d d 1 d 1 d ad,0,0x1 + ad 1,1,0x1− y1 + ad 1,0,1x1− w1 + + a0,0,dw1 = 0 − − ··· with variables ad,0,0, ad 1,1,0, ad 1,0,1, . . . , a0,0,d. The equations are linearly inde- − − pendent, because the points P1,...,Pm are pair-wise distinct by the assumption and the number of variables exceeds the number of equations (by one). Therefore, the system has a non-zero solution. Let F be the corresponding homogeneous poly- nomial. Then (F,CF ) is the desired projective algebraic curve interpolating all the points given.  The above theorem is a special case of a far more general result known as the Cayley–Bacharach theorem. An even more special case is the following corollary, sometimes referred to as the 5-points theorem. Corollary 3.8. For any five points there is a conic curve through all of them. Moreover, if no three points are colinear, then the curve is irreducible. We conclude this section with the theorem due to E.´ B´ezoutthat determines a number of intersections of two projective complex curves. We begin with a simple observation. Take a homogeneous polynomial F C[x, y, w] of positive degree d 2 ∈ and let CF P C be the associated projective algebraic curve. Further, let L be a ⊂ projective line with Pl¨ucker-Grassmann coordinates L12 : L20 : L01 = a : b : c  2 J K J K (i.e. L = x : y : w P C : ax+by+cw = 0 ). Assume that L * CF . We wish to J K ∈ count the number of intersection points between L and CF . There is a projective  transformation Φ of P2C sending L to the line M = x : y : w y = 0 . 1 J K | Denote Fˆ := F Φ− , then the algebraic curve C ˆ is the image of C under Φ. ◦ F The number of intersection points of CF and L is the same as the number of intersection points between CFˆ and M. The latter, however, are much simpler 1 to count. Identify M with the projective line P C, then M CFˆ is the set of solutions to the equation Fˆ(x, 0, 1) = 0. Recall that a number∩ of roots, counted with multiplicities, of a complex univariate polynomial equals its degree. It follows that there are exactly deg Fˆ = deg F , where the line L intersects the curve CF , when counted with multiplicities. We have proved: Proposition 3.9. The number of intersection points, counted with multiplic- ities, between a projective line and a complex projective curve (not containing the line) equals the degree of the curve.

The multiplicity of a root x0 of a dehomogenization fˆ of Fˆ is called the inter- section number of CFˆ and M at x0 : 0 : 1 . The intersection number is denoted  J K I x0 : 0 : 1 ,CFˆ M . The intersection number of C and L at a point P is by J K ∩  definition I(P,C L) := I Φ(P ),CF Φ−1 Φ(L) . ∩ ◦ ∩ Build: January 28, 2021 Algebraic curves 137

Example. Let F = x3 yw2+w3, then Proposition 3.9 asserts that an arbitrary line intersects C exactly three− times. If for instance L = x + y w = 0 , then F { − } L CF consists of the points 0 : 1 : 1 , i : 1 i : 1 and i : 1 + i : 1 . ∩ J K J − K J− K Lemma 3.10. Let F , G be two homogeneous polynomials over C. Assume that they are relatively prime (i.e. gcd(F,G) = 1), then the algebraic curves CF and C intersect in at most deg F deg G points. G · Proof. Without loss of generality we may assume that the origin O := 0 : 0 : 1 is not one of the intersection points—otherwise we could always translateJ both curves.K Take an intersection point P = x : y : w . Its coordinates form one of the solutions of the system of homogeneousJ polynomialK equations: ( F (x, y, w) = 0 G(x, y, w) = 0. We may think of F and G as of polynomial of one variable w with coefficients in the polynomial ring C[x, y]. Proposition 2.1 asserts that the resultant Resw(F,G) is then null. Thus, the point x : y P1C of the projective line is the root of J K ∈ the homogeneous polynomial R := Resw(F,G) C[x, y]. Let r be the dehomoge- ∈ nization of R. It follows that x/y is the root of r. The degree of r is the product (see Exercise 1) of degrees of F and G. Consequently r has exactly deg F deg G complex roots when counted with multiplicities. · 1 Identifying the point x : y on the projective line P C with the point P 0 = x : y : 0 in the projectiveJ planeK P2C, we realize from the above discussion that Jthe cardinalityK of the set

n 2 _ o Ξ := x : y : 0 P C x : y : w CF CG ∈ | ∈ ∩ J K w J K ∈C does not exceed the product deg F deg G. The point P 0 lies at the intersection of the axis w = 0 with the line through· O and P . Proposition 3.9 asserts that C { } F intersects that line at only finitely many points and so does CG. It follows that there are only finitely many points P corresponding to a fixed point P 0. Consequently the set C C is finite. Therefore, the lines through every two intersection F ∩ G points does not cover the whole P2C and so, choosing an appropriate projective transformation, we may assume that O does not lie on any of these lines. This implies that the assignment P P 0 is injective. Hence the number of intersection points is not greater than the number7→ of elements of Ξ. This concludes the proof.  2 Fix two projective algebraic curves CF , CG over C. Take a point P P C. ∈ If P does not belong to CF CG, the intersection number I(P,CF CG) is zero by definition. If P C for∩ some (homogeneous) polynomial H dividing∩ both F ∈ H and G, then I(P,CF CG) := . If neither of the two above special cases holds, then without loss of generality∩ ∞ we may assume that O := 0 : 0 : 1 is neither an J K intersection point of CF and CG nor it lies on a line through any two intersection points. As in the proof of the above lemma, the intersection points are in one-to-one correspondence with the roots x : y of the resultant R := Resw(F,G). We then J K define I(P,CF CG) to be the multiplicity of the corresponding root of R. The number of roots∩ of R equals deg F deg G when counted with multiplicities (see Exercise 1), hence we have proved the· following important theorem: Build: January 28, 2021 138 Algebraic curves

Theorem 3.11 (B´ezout). Let F,G C[x, y, w] be two homogeneous polynomi- ∈ als of degrees n and m, respectively. Then the curves CF and CG intersect precisely at nm points, when counted with multiplicities: X I(P,C C ) = nm. F ∩ G P CF CG ∈ ∩ 4. Singular points on algebraic curves Description of singular points on algebraic curves is exceptionally simple. Fix a non-homogeneous polynomial f K[x, y] and the associated affine algebraic curve 2 ∈ Cf K . We say that a point P on C is singular if both the partial derivatives of f vanish⊂ at P , i.e.: ∂f ∂f (P ) = (P ) = 0. ∂x ∂y A curve that does not have any singular points is called smooth or non-singular.A unit circle is an example of a smooth algebraic curve since ∂(x2 + y2 + 1) ∂(x2 + y2 + 1) = 2x and = 2y, ∂x ∂y hence the origin is the only point, where both the derivatives are null, but it does not lie on the curve. The definition of a singular point of a projective curve is analogous. We say 2 that P P K is a singular point of a projective curve (F,CF ) if all three partial derivatives∈ of F vanish at P : ∂F ∂F ∂F (P ) = (P ) = (P ) = 0. ∂x ∂y ∂w The following identity due to L. Euler ensures that any point where all three deriva- tives are zero already belongs to CF .

Observation 4.1. If F K[x0, . . . , xn] is a homogeneous polynomial of de- gree d, then ∈ ∂F ∂F x0 + + xn = dF. ∂x0 ··· ∂xn T The proof is straightforward. An affine curve Cf has a singularity at (x, y) if and only if x : y : 1 is a singular point of CF , where F is the homogenization of f. J KT Let P = (x0, y0) be a singular point on an affine algebraic curve Cf . Translate P to the origin taking fˆ(x, y) := f(x x , y y ). Then O = (0, 0)T is a singular − 0 − 0 point of Cfˆ. Write the polynomial fˆ as a sum of homogeneous polynomials of distinct degrees: fˆ = F + F + + F , 0 1 ··· d with deg Fk = k. In particular, F0 is the constant term of f and F1 is the linear part. It has the form F1 = ax + by for some a, b K. Now, Cfˆ passes through the ∈ origin, thus F0 = 0. Next, a partial derivative of any homogeneous polynomial of degree greater than one always vanishes at the origin. It follows that ∂fˆ ∂F ∂fˆ ∂F 0 = (0, 0) = 1 (0, 0) = a and 0 = (0, 0) = 1 (0, 0) = b, ∂x ∂x ∂y ∂y consequently F 0. 1 ≡ Build: January 28, 2021 Algebraic curves 139

1 1

2 1 12 1 12 − − − 1 1 − −

Figure 6.1. The tri- Figure 6.2. A crunodal folium curve. cubic and its two tan- gents.

Observation 4.2. Let F +F + +F be the decomposition of a polynomial fˆ 0 1 ··· d into homogeneous parts, with deg Fk = k. Then the algebraic curve Cfˆ has a singularity at the origin if and only if F0 = F1 = 0.

Denote by mP (CF ) := min m : Fm = 0 the lowest degree for which the homogeneous part in the above{ decomposition6 } does not vanish. It is called the multiplicity of the point P . It is clear that P is non-singular if and only if mP (CF ) = 1. This explains why singular points are sometimes referred to as multiple points, as well. Example. Take a tri-folium curve defined by the polynomial f = x4 +2x2y2 + y4 +x3 3xy2. The curve is depicted in Figure 6.1. Compute the partial derivatives: − ∂f ∂f = 4x3 + 4xy2 + 3x2 3y2 and = 4x2y + 4y3 6xy. ∂x − ∂y − They both vanish at (0, 0)T , hence the curve has a singularity at the origin. The first non-zero homogeneous part of f is F = x3 3xy2, thus the origin has the 3 − multiplicity three (i.e. it is a “triple point” of Cf ). T Assume now that P = (x0, y0) a is non-singular point of an algebraic curve Cf . Observation 4.2 asserts that F1 is non-zero—say F1 = ax + by. The gradient f(P ) of f at P is a vector consisting of the partial derivatives of f at P . It determines∇ the direction of the steepest slope of the graph of f. Using our notation we have ∂f ! ! ∂x (P ) a f(P ) = ∂f = . ∇ ∂y (P ) b

The gradient is perpendicular to Cf . It follows that the tangent line to Cf at P is T x x0 given by the equation 0 = f(P ) − , which simplifies to 0 = F (x x , y y y0 1 0 ∇ · − − − y0). Example. Take a unit circle. The associated polynomial is f = x2 + y2 1. T T − The gradient of f is f = (2x, 2y) . Let P = (√2/2, √2/2) , the tangent line to Cf at P is given by the∇ equation

√2 !  √ √  x 2 2 , 2 2 − 2 = 0, · 2 · 2 · y √2 − 2 Build: January 28, 2021 140 Algebraic curves which simplifies to x + y √2 = 0. − The above discussion shows that at a non-singular point, there is a well defined tangent line to Cf . What about singular points, then? A quick glance at Figure 6.1, let us suspect that the tri-folium curve should have as much as three tangents at the origin. Indeed, in some cases, an algebraic curve may have more than one tangent line at a singular point. T Let P = (x0, y0) be a singular point of an algebraic curve Cf . Once again translate it to the origin O and let Cfˆ denote the translated curve. Let m := mP (Cf ) = mO(Cfˆ); dehomogenize the first non-zero homogeneous part Fˆm of fˆ to ˆ x get a polynomial f m K[t] of one variable t = /y. Over the complex numbers every univariate polynomial∈ factors into linear terms and so we can write fˆ = lr1 lrk . m 1 ··· k Denote the homogenization of li by Li. It is a homogeneous linear polynomial, say Li = aix + biy. The forms L1,...,Lk provide a factorization of Fˆm: Fˆ = Lr1 Lrk . m 1 ··· k The lines ai(x x0) + bi(y y0) = 0 are the tangent lines to Cf at the singular point P . − − We say that P is an ordinary singular point if all the exponents ri are equal 1 (in other words, if all the tangent lines are distinct). An ordinary double point is called a node (or a nodal point). A double point, which is not a node, is called a (or a cuspidal point). Example. Take a cubic curve C , where f = x3 4x2 + y2 + 5x 2 (see f − − Figure 6.2). It has a unique singular point P = (1, 0)T . Translate it to the origin 3 2 2 to get a curve Cfˆ, with fˆ = x + (y x ). It follows that mP (Cf ) = 2. The homogeneous part Fˆ = y2 x2 factors− into y2 x2 = (y x)(y + x). Therefore, 2 − − − the tangent lines to Cf at P are given by the following two equations: y x + 1 = 0 and y + x 1 = 0. − − T It follows that Cf is a nodal cubic curve with the node P = (0, 1) . The notion of the multiplicity of a point on a curve is closely related to the intersection number defined in the previous section. Proposition 4.3. Let F , G be two relatively prime homogeneous polynomials. If P is one of the intersection points of the associated algebraic curves CF , CG, then I(P,C C ) m (C ) m (C ). F ∩ G ≥ P F · P G Moreover, the above inequality is strict if and only if CF and CG have a common tangent line at P , otherwise an equality holds. We omit the proof referring the reader to [9, Lemma 14.8] instead. In the next section we will need, however, the following consequence of this proposition. Corollary 4.4. A cubic curve may have at most one singular point which is a double point then. Indeed, suppose a contrario that a cubic curve has two distinct singular points. Consider a line through these two points. By the means of Proposition 4.3, the sum of intersection numbers is then greater or equal four. But this contradicts the B´ezouttheorem (see Theorem 3.11). Next suppose that a cubic curve has a point of multiplicity greater than two. Take a line through it and any other point of the Build: January 28, 2021 Algebraic curves 141 curve. Then again the sum of intersection numbers must be greater than three by Proposition 4.3 contradicting the B´ezouttheorem.

5. Parametrization of algebraic curves In this section we investigate the problem of representing an algebraic curve (of low degree) in a parametric form. The class of algebraic curves is strictly wider than the class of parametric curves. Hence the conversion from an implicit form to a parametric form is not always possible (unlike the opposite conversion discussed in Section 6). Here, we concentrate on a few simplest cases only. Definition 5.1. We say that a parametric curve C(t) = x(t), y(t)T is a parametrization of an algebraic curve Cf if the following two conditions are satisfied:  f x(t), y(t) = 0 for every t R, • ∈ the set Cf C(R) is finite. • \ Notice that in the above definition t varies over the whole field R of the reals, not just a compact interval as in the previous chapters. We will use the term untrimmed parametric curve, when we need to emphasize this point of view. Undoubtedly, the simplest algebraic curve is a line. An affine line L is given by a (linear) polynomial Ax + By + C. Suppose that P and Q are two points lying on the line, then C(t) = lerp(P,Q; t) is a parametric form of L. If we know only one point P L, then we just take the other one to be Q := P + B . ∈ A As a next step consider a parametrization of a conic curve.− One method is to intersect a curve with a of lines through a fixed point of the curve. This is a procedure we describe farther in this section to parametrize cubic curves, but it works for conics as well (see Exercise 6). There is, however, a more direct approach in this case. Let f R[x, y] be a quadratic polynomial of the form ∈ 2 2 f = f20x + f11xy + f02y + f10x + f01y + f00 T and Cf be the associated algebraic curve. Take two points P = (xP , yP ) and T R = (xR, yR) lying on CF . One can obtain them intersecting CF with a line in general position. We wish to express the arc PR as a B´ezier(trimmed) curve. The tangent to Cf at P satisfies the equation ∂f  ∂f Ŋ  (P ) (x x ) + (P ) (y y ) = 0. ∂x − P ∂y − P Analogously, the tangent line at R is given by ∂f  ∂f  (R) (x x ) + (R) (y y ) = 0. ∂x − R ∂y − R T Denote the intersection point of these two lines by Q = (xQ, yQ) . The partial derivatives of f with respect to its two variables are: ∂f ∂f = 2f x + f y + f and = 2f y + f x + f . ∂x 20 11 10 ∂y 02 11 01 Therefore the coordinates of the point Q are obtained by solving the system of linear equations ( Ax + By = AxP + ByP

Cx + Dy = CxR + DyR, Build: January 28, 2021 142 Algebraic curves

∂f ∂f with A = ∂x (P ) = 2f20xP + f11yP + f10, B = ∂y (P ) = 2f02yP + f11xP + f01, ∂f ∂f C = ∂x (R) = 2f20xR + f11yR + f10 and D = ∂y (R) = 2f02yR + f11xR + f01. There AB are two possible degenerate cases, recognized by the fact that the matrix ( CD ) of the coefficients is singular. First, it may happen that the two tangents coincide. In this case, Cf is in fact a line, not a proper conic and we may use the method described earlier. Second degenerate case happens when the two tangent lines are distinct but parallel (e.g. P and R are two antipodal points on a circle). In this case, Q is a point at infinity and the arc PR does not admit a parametrization by a single affine B´eziersegment. The three points P , R and Q computedŊ above are the control points of the desired B´eziercurve. By the means of Proposition 2.13, we may take the weights of the two endpoints P and R to be equal one. Denote by w the weight of the remaining point Q. The B´eziercurve is given by the formula 2 2 2 b0(t)P + b1(t)wQ + b2(t)R C(t) = 2 2 2 , b0(t) + b1(t)w + b2(t) 2 2 i 2 i with b = t (1 t) − . Let Q0 be the midpoint of the line segment PR (see i i − Figure 6.3) and take M := C(1/2). We may express M as follows

2 1 2 1 2 1 P +R b0( 2 )P + b1( 2 )wQ + b2( 2 )R 2 + wQ M = 2 1 2 1 2 1 = = b0( 2 ) + b1( 2 )w + b2( 2 ) w + 1 1 P + R w 1  = + Q = lerp Q, Q0; . w + 1 · 2 w + 1 w+1

w 1 Thus, M lies on the line segment QQ0 dividing it with a ratio /w + 1 : /w + 1 = w : 1. This let us compute w as follows: first find the intersection point M of the curve Cf and the line segment QQ0, then take

M Q0 w = k − k. M Q k − k The only step that still needs explanation is how to find the intersection point of Cf and QQ0. To this end we first parametrize the line through Q and Q0 so that x(t) M(t) = = lerp(Q, Q0; t). y(t)

Now M lies on Cf , hence the polynomial f vanishes on its coordinates. Thus 2 2 f20 x(t) + f11x(t)y(t) + f02 y(t) + f10x(t) + f01y(t) + f00 = 0. This is a quadratic equation in a variable t. Find a root in the interval [0, 1], to get the coordinates x(t), y(t) of the point M. Algorithm 8 presents the pseudo-code of the parametrization procedure of a conic arc. Example. Consider a unit circle centered at the origin (see Figure 6.4). The corresponding polynomial is f = x2 + y2 1. Take the first quarter of the circle, T T − ∂f so that P = (1, 0) and R = (0, 1) . The partial derivatives of f are ∂x = 2x ∂f and ∂y = 2y, therefore the tangents to the circle at the two points are given by the equations x = 1 and y = 1, respectively. The intersection point Q of these two tangent lines has the coordinates (1, 1)T , while the midpoint of the line segment Build: January 28, 2021 Algebraic curves 143

Q

M P

Q0 R

Figure 6.3. B´ezierparametrization of a conic segment.

Algorithm 8: B´ezierparametrization of a conic arc.  f , . . . , f : the coefficients of f Input: 20 00 P = xP ,R = xR : the endpoints of the arc. yP yR Output: the B´eziercontrol points and weights of the arc PR A 2f x + f y + f ; ← 20 P 11 P 10 B 2f y + f x + f ; Ŋ ← 02 P 11 P 01 C 2f x + f y + f ; ← 20 R 11 R 10 D 2f y + f x + f ; ← 02 R 11 R 01 ∆ det ( AB ); ← CD if ∆ = 0 then return ERROR; ;     Q 1 det AxP +ByP B , 1 det A AxP +ByP ; ← ∆ CxR+DyR D ∆ C CxR+DyR 1 Q0 (P + R); ← 2 M intersection(QQ0,Cf ); ← M Q0 w k M− Q k ; ← k − k return ([P, 1]T , [wQ, w]T , [R, 1]T )

1 1 T PR is Q0 = ( /2, /2) . It follows that the auxiliary point M where the arc Cf √ √ T intersects QQ0 is M = ( 2/2, 2/2) . Consequently q √2 1 2 √2 1 2 + √ 2 − 2 2 − 2 2 w = q = . √ 2 √ 2 2 2 1 + 2 1 2 − 2 − It follows that the control points of the B´ezierform of the first quarter of the unit circle are (in homogeneous coordinates):       1 √2/2 0 0 , √2/2 , 1      . 1 √2/2 1

Build: January 28, 2021 144 Algebraic curves

1 R Q

1

P

Figure 6.4. B´ezierparametrization of a circle.

2 R 1

1

1 1 PQ − 1

Figure 6.5. B´ezierparametrization of a parabola.

Similarly, we compute the control points of the B´ezierrepresentation of an arc of the parabola y x2 = 0 with x [0, 1]. These are (see Figure 6.5): − ∈    1    0 2 1 0 , 0 , 1      . 1 1 1 Observe that all the weights are equal, thus, unlike a circle, a parabolic arc has a polynomial parametrization The last type of a non-degenerate affine conic is a hyperbola. Take f = x2 y2 = − 1, then the control points of the B´ezierform of the arc of C with 1 x 5/3 and f ≤ ≤ 0 y 4/3 (see Figure 6.6) are: ≤ ≤    2√3   5  1 3 3   ,  √3  ,  4  0  3   3  2√3 . 1 3 1

Once we are done with the conics, it is time to consider cubics. Take an irreducible polynomial f R[x, y] of degree three and let Cf be the associated ∈ algebraic curve. Assume that Cf is singular. Thus, it has exactly one double point by Corollary 4.4. Take an appropriate projective transformation to bring the singularity to the origin C = 0 : 0 : 1 and map some other (fixed) point to 0 : 1 : 0 . J K J K Build: January 28, 2021 Algebraic curves 145

2 4 R 1 /3

2 1 12 Q − − 1 − 2 − P 5/3

Figure 6.6. B´ezierparametrization of a hyperbola.

Take a pencil of lines through the origin (see Figure 6.7). Let L be a line in the pencil. Proposition 3.9 asserts that it intersects Cf exactly three times, but the origin O counts already for two, hence, if only the line is not tangent to Cf at O, then it intersects Cf at exactly one more point. On the other hand for every point P on the curve one finds a line through O and P . Thus, the points on the curve are in one-to-one correspondence with elements of the pencil of lines through the double point. The unique point at infinity 0 : 1 : 0 corresponds to OY . Suppose that the line L is given by the equation axJ+ by =K 0. We parametrize the pencil taking t := a/b, for b = 0, and associating with the OY axis. 6 ∞ The third intersection point of L and Cf is the unique non-zero solution to the system of equations: ( ax + by = 0 f(x, y) = 0. Substitute ( tx) for y in the second equation to get f(x, tx) = 0. The polynomial − − f can be decomposed into a sum of its homogeneous parts f = F0+F1+F2+F3. The origin is a double point of Cf , therefore both F0 and F1 vanish (see Observation 4.2). Thus, we may write f(x, tx) = F (x, tx) + F (x, tx) = Ax2 + Bx3 = 0, − 2 − 3 − for some A, B depending on f. Canceling the term x2, we have A A x = and y = tx = t . −B − B This is the desired parametrization of Cf . Example. Take the cubic curve associated to f = x3 x2 + y2. We already − know (see Example on page 140) that Cf has a unique node at the origin. Take y = tx, to get − 0 = f(x, tx) = x3 x2 + ( tx)2 = x2(x + t2 1). − − − − Consequently, x = 1 t2 and y = tx = t3 t. Convert it to the B´ezierrepresen- tation to get the control− points: − − 1  1   2/3  0 , , , . 0 1/3 2/3 0 − − In the above discussion, we assumed that the curve was singular. One may ask whether it is possible to parametrize a smooth cubic curve. The answer is: no. Build: January 28, 2021 146 Algebraic curves

Figure 6.7. A pencil of Figure 6.8. An elliptic lines parametrizing a sin- curve consisting of two gular cubic. connected components.

2 3 Take for example f = y x + x. Then the associated curve Cf is not connected (see Figure 6.8). Instead− it consists of two components—one homeomorphic to a circle, the other to a line.3 Consequently it cannot be parametrized by a continuous function. In fact, a more general theorem holds. An algebraic curve has a rational parametrization if and only if its equals zero (for the proof see e.g. [1]). We do not have enough space here to precisely define the notion of the genus, hence we 1 will only mention that the genus of a smooth curve of degree d is 2 (d 1)(d 2). An immediate consequence is the following proposition: − − Proposition 5.2. The only smooth algebraic curves admitting rational para- metrization are of degree not exceeding two. A curve of non-zero genus cannot be parametrized exactly, yet it is still possible to find an approximate parametrization. We refer the reader to [13] for details. So far we have been looking for a rational parametrization of an algebraic curve. But one can be more demanding and require a polynomial parametrization. Suppose T that C(t) = f(t)/h(t), g(t)/h(t) is a rational parametric curve with f, g, h R[t] being polynomials. It is obvious that if h divides both f and g, then C ∈has a polynomial parametrization. But it is by no means a necessary condition. Fix a point P = C(t0) on the curve corresponding to some parameter t0 R (we do not ∈ restrict here the parameter space to the unit interval!). Any complex number z C 1 ∈ in the inverse image C− (P ) is called a place of P . If C is properly parametrized (see Section 1 of Chapter 3), then there are only finitely many points having more than one place. Any non-singular point has only one place. A non-ordinary double point (i.e. a cusp) has only one place, as well. On the other hand, an ordinary double point (i.e. a node) has two places.

T Theorem 5.3. Let C(t) = f(t)/h(t), g(t)/h(t) be a rational parametric curve. Assume that the parametrization is proper and gcd(f, g, h) = 1. The following conditions are equivalent: (1) The curve C admits a polynomial parametrization. (2) The curve C has exactly one place at infinity.

3 The two components of the projective curve CF , obtained by homogenizing f, are both homeomorphic to a circle.

Build: January 28, 2021 Algebraic curves 147

(3) The denominator h(t) is of the form a (t b)d for some a, b R and d equals the maximum of the degrees of f·and−g. ∈ The proof of the theorem exceeds the scope of this book. The equivalence of points 1 and 2 can be found in [1], while the equivalence of 2 and 3 is proved in [19]. Let as take a look at 2. The B´ezouttheorem says that C intersects the line at infinity in precisely d points, where d is the degree of C. Thus, if C is a polynomial curve of degree d, then it intersects the line at infinity in a single point of multiplicity d. In particular, the line at infinity is tangent to C, there. This explains why among conics it is only the parabola that has a polynomial parametrization (see also Exercise 3).

6. Implicitization of parametric curves In this section we deal with the opposite problem to the one discussed above. T Suppose, that we are given a parametric curve C(t) = f(t)/h(t), g(t)/h(t) . What we are looking for is its implicit form. In other words, we search for a polynomial  r R[x, y] such that r C(t) = 0 for every t and C(R) is dense in Cr. ∈ Without loss of generality, we may assume that gcd(f, g, h) = 1. Fix a point P = (x, y)T on C and let t be the corresponding parameter so that the coordinates T of P are f(t)/h(t), g(t)/h(t) . Write it as a system of two polynomial equations ( h(t)x f(t) = 0 − h(t)y g(t) = 0. − We need to combine these two equations into a single one, eliminating the variable t. Treat h(t)x f(t) and h(t)y g(t) as two polynomial of one variable t with − − coefficients in the ring R[x, y]. Thus, we are looking for some r R[x, y] which is zero if and only if the above system has a solution. Corollary∈ 2.3 asserts that r = Res (hx f, hy g). t − − Example. Take a cubic B´eziercurve C with control points ( 1, 1)T ,( 1, 1)T , (1, 1)T and (1, 1)T . Write it explicitly as − − − − ( x = 4t3 + 6t2 1 (6.1) − − y = 8t3 12t2 + 6t 1. − − Compute the B´ezoutresultant

ResB4t3 6t2 + (x + 1), 8t3 + 12t2 6t + (y + 1) = t − − −  6x + 6 6y 12x 18 4y + 8x + 12 − − − = det  6y 12x 18 4y + 8x + 48 24  = −4y +− 8x +− 12 24− 0 − = 64(8x3 27y + 12x2y + 6xy2 + y3). − It follows that the B´eziercurve C may be expressed as an algebraic curve Cr, where r is the polynomial obtained above. This allows us to effectively check if 13 1 T a given point lies on the curve. Take for instance P = ( − /27, − /27) , then 13 1 r( − /27, − /27) = 0 and so the curve passes through P . Compare it with the example on page 112. Build: January 28, 2021 148 Algebraic curves

This is not the end of the story. The method we used above to implicitize a parametric curve may be also applied to another problem, namely how to find a parameter t corresponding to given coordinates x, y of a point on the curve (of course for a multiple point there may be more than one such t). Take again a T parametric curve C(t) = (f(t)/h(t), g(t)/h(t)) . We know that C may be represented B as an algebraic curve just by computing the B´ezout resultant Rest (hx f, hy g) with respect to the variable t. Recall that the B´ezout resultant is the determinant− − of the matrix of the coefficients of the polynomial hx f,hy g in two variables t0, B − − t1. Write this polynomial as    0  b0,0 b0,1 b0,n 1 t1 ··· − 1  b1,0 b1,1 b0,n 1   t1  0 1 n 1 − = (t , t , . . . , t − )  ···    hx f,hy g 0 0 0  . . .   .  B − − ·  . . .  ·  .  n 1 . bn 1,0 bn 1,1 bn 1,n 1 t1 − − − ··· − − Take t0 = 1 and t1 = t (the polynomial is symmetric, hence the opposite substi- tution renders the same result). As in Section 2, we treat the resultant as a “lin- B earlization” of a system of polynomial equations. Thus, the equation Rest (hx f, hy g) = 0 of C may be treated as a system of simultaneous “linear” equations− − 0 1 n 1 in “variables” t , t , . . . , t −    0    b0,0 b0,1 b0,n 1 t 0 ··· − 1  b1,0 b1,1 b0,n 1   t  0  ··· −    =    . . .   .  .  . . .  ·  .  . n 1 . bn 1,0 bn 1,1 bn 1,n 1 t − 0 − − ··· − − We are looking for a non-zero solution of it. It follows from Cramer’s rule that the matrix must be singular. Therefore, its rows are linearly dependent. Assume that the rank of the matrix is n 1, thus after dropping just one row, the remaining ones are linearly independent.− In such a case we may solve the system for t1 with t0 treated as a parameter. Putting then back t0 = 1 we express t in terms of x, y and the coefficients of f, g, h. This is known as the inversion formula for the parametrization of C. Example. Take the same curve C as in the previous example. The corre- sponding matrix equation reads as  6x + 6 6y 12x 18 4y + 8x + 12  1  0 − − − 6y 12x 18 4y + 8x + 48 24 t = 0      . −4y +− 8x +− 12 24− 0 · t2 0 − The last row gives rise to an equation 4x + 8y + 12 24t = 0, which evaluates to − 1 (6.2) t = 6 (y + 2x + 3). 13 1 T Hence, for the point P = ( − /27, − /27) used in the previous example, the cor- responding value for the parameter t is 1/4. We let the reader check by himself that substituting Eq. (6.2) into Eq. (6.1) one gets back the implicit form of C.

7. Intersection points The B´ezouttheorem tells us that two curves of degrees respectively n and m intersect exactly nm times in the complex projective plane. This section is devoted to the problem how to explicitly compute these intersection points. We Build: January 28, 2021 Algebraic curves 149 will concentrate on the case of real affine curves since these are the ones most often encountered in applications. Let f, g R[x, y] be two polynomials. Compute the resultants ry := Resx(f, g) ∈ ∈ R[y] and rx = Resy(f, g) R[x]. Corollary 2.3 asserts that ry(y0) = 0 if and only ∈ if the two polynomials f(x, y0) R[x] and g(x, y0) R[x] have a common root in ∈ ∈ C. This means that the two curves Cf and Cg intersect at a certain point with the ordinate y0. Analogously, the resultant rx vanishes at some x0 R if and only if ∈ x0 is the abscissa of some intersection point of Cf , Cg. Both the resultants rx, ry are univariate polynomials and so there are efficient and robust numerical methods to find their roots. This leads to a simple yet still quite effective (at least for low degree curves) method for finding the intersection points: first find all the roots x0, . . . , xn of rx and y0, . . . , ym of ry, then check all the possible pairs (xi, yj) for{ 0 i }n and 0 j{ m to see} if any of them constitutes an intersection point. ≤ ≤ ≤ ≤ Example. Take two cubic curves Cf and Cg associated to the polynomials f = x3 xy + x2y y3 and g = 2x3 xy2 + y3. First eliminate the variable y to get − − −

 y4(y + 1) y4 3y3  B − 4 3 ry = Resx (f, g) = det  y 2y y(y 2) = 3y3 y(y 2) − 2−y − − − = (y 1) (17y2 + 4y + 4) y6 − − then eliminate x to get

2x4(x 1) x4 3x3  B 4− 2 − rx = Resy (f, g) = det  x x (2x + 1) x(x 1) = 3x3 − x(x 1) − x− − − − = (x + 1) (17x2 6x + 2) x6. − The roots of r are: 1, 0, 1/17 (3 5i), while the roots of r are 0, 1, 2/17 (1 4i). x − · ± y − · ± Skip the non-real solutions and check the four remaining pairs: ( 1, 0)T ,( 1, 1)T , (0, 0)T , (0, 1)T to see that − − f(0, 0) = 0 = g(0, 0) and f( 1, 1) = 0 = g( 1, 1), − − while f( 1, 0) = f(0, 1) = 1 = 0. It follows that C and C intersect in the real − − 6 f g plane at exactly two points: (0, 0)T and ( 1, 1)T . − In practice one often has to find the intersection points of two parametric curves. In the previous section we learned how to convert a parametric curve to an implicit form. Hence one solution is two express both input curves in their implicit forms and then proceed as explained above. But this is subopti- mal, there is a better solution. It suffices to convert one curve only. Take two T parametric curves, either polynomial or rational, C1(s) = x1(s), y1(s) and T C2(t) = x2(t), y2(t) . Express C1 as an algebraic curve Cr, using the meth- ods described in Section 6 and substitute x2(t), y2(t) into the polynomial r to get a  function g(t) = r x2(t), y2(t) R(t) of one variable t. The roots t0, . . . , tn of g are ∈ the values of the parameter t where C2 intersects C1. The coordinates of the inter- T T section point are x2(t0), y2(t0) ,..., x2(tn), y2(tn) . To find the corresponding values of the parameter s of C1 use the inversion formula described earlier. Build: January 28, 2021 150 Algebraic curves

4 Example. Let C1,C2 be two B´eziercubic segments with control points re- spectively: 0  7   1 3  2 5 2  5  , , − , and − , , , . 0 1 6 3 3 1 1 1 − − Write them explicitly  27s3 45s2 + 21s  16t3 30t2 + 21t 2 C (s) = ,C (t) = . 1 18s3−+ 24s2 3s 2 4t3−+ 6t2 6t +− 3 − − − − Write C1 in an implicit form r = 0, where the corresponding polynomial is r = ResB(x 27s3 + 45s2 21s, y + 18s3 24s2 + 3s) = s − − −  21y 3x 45y + 24x 27y 18x − − − − = det  45y + 24x 27y 18x 369 297  = 27y 18x − −297 − 162 − − − = 729(27y3 + 54xy2 297y2 + 36x2y 318xy + 819y + 8x3 72x2 + 117x). − − − Drop the constant term and substitute C2 into it to get (2t 1)(4000t8 23200t7+55720t6 68080t5+41488t4 6940t3 7268t2+5177t 1295). − − − − − − 1 The polynomial has only one root in the interval [0, 1], which is t0 = /2. Hence the 1 T coordinates of the unique intersection point are C2( /2) = (3, 1) . Use the inversion formula for the parametrization of C1 to find the parameter s of the intersection point. We have  21y 3x 45y + 24x 27y 18x  1  − − − −  45y + 24x 27y 18x 369 297   s  = 27y 18x − −297 − 162 · s2 − − −  27s2y + 45sy 21y 18s2x + 24sx 3x − − − − = 27sy + 45y 18sx + 24x + 297s2 369s  . − 27y − 18x 162s2 + 297s − − − − y+2x T It follows that s = 6y+4x 39 and so the intersection point (3, 1) correspond to − − s = 1/3.

8. Hessian and the inflection points We have already encountered singular points of an algebraic curve. But there is another category of points that are somehow “special”, known as inflection points or just flexes. They are the subject of this section. We begin with an example. Let n f = f0 +f1t+ +fnt R[t] be a univariate polynomial. We may treat the graph  ··· ∈ gr(f) = (x, f(x)) x R of f as an algebraic curve Cg associated to a bivariate | ∈ polynomial g(x, y) = f(x) y. Notice that C is non-singular since ∂g 1 = 0. − g ∂y ≡ − 6 Assume that the polynomial f has an inflection point (in traditional sense) at the origin. The basic calculus says that the first and the second derivatives of f vanish: 0 = f(0) = f 0(0) = f 00(0). Express this condition using the polynomial g: ∂2g ∂2g (0, 0) = f 00(0) = 0 and (0, 0) = 0. ∂x2 ∂y2

4These are the same two curves as in the example on page 112.

Build: January 28, 2021 Algebraic curves 151

2 n By its definition g has the form g = f0 + (f1x y) + f2x + + fnx . Homogenize it to get − ··· n n 1 2 n 2 n G = f w + (f x y)w − + f x w − + + f x . 0 1 − 2 ··· n The abscissa is tangent to gr(f) at the origin and the intersection number I( 0 : 0 : 1 , gr(f) OX) equals the multiplicity of the root 0 : 1 of the homogeneousJ polynomialK G∩(x, 0, w) = F (x, w). Here F stands for theJ homogenizationK of f. Now, the coefficients f0, f1, f2 are all zero, consequently 3 n 3 n F = f x w − + + f x . 3 ··· n Hence the intersection number I( 0 : 0 : 1 , gr(f) OX) is greater or equal 3. We use this condition to define inflectionJ pointsK of the∩ curve gr(f).

Definition 8.1. Let CF be a projective algebraic curve, P a non-singular point on CF and L the tangent to CF at P . We say that P is an inflection point (or a flex 5) if the intersection number I(P,C L) is strictly greater than two. F ∩ Just from the definition we see that if the curve is a line, then every point is a flex. But as we will learn shortly, lines are the only curves having infinitely many inflection points. The definition does not suggest any direct method for actually finding the inflection points. In order to develop such a method we need an additional tool.

Definition 8.2. Let F K[x, y, w] be a homogeneous polynomial and P be ∈ any point in the projective plane P2K. The Hessian matrix of F at P is a matrix HF (P ) consisting of second derivatives of F at P :

 ∂2F ∂2F ∂2F  ∂x2 (P ) ∂x∂y (P ) ∂x∂w (P ) 2 2 2 H (P ) :=  ∂ F ∂ F ∂ F  F  ∂y∂x (P ) ∂y2 (P ) ∂y∂w (P ) ∂2F ∂2F ∂2F . ∂w∂x (P ) ∂w∂y (P ) ∂w2 (P ) The determinant of this matrix is called the Hessian of F at P and denoted hF (P ) := det HF (P ). We have to check how the hessian behaves under a projective change of vari- ables. First consider a one-dimensional case that should provide us with some motivation. Let F K[t] be a univariate polynomial. Take a non-zero scalar a K ∈ 2 ∈ and let g(t) := f(at). The second derivative of g is g00(t) = a f 00(at) = a f(s) a for s = at. · · The multivariate case requires a little more labor, but is still basically similar. Take an invertible matrix A = aij 1 i,j 3 GL3(K) and a homogeneous polyno- ≤ ≤ ∈ mial F K[x, y, w]. For a projectiveJ K point P = x : y : w let Q := A P be its image ∈ · under the projective automorphism associated withJ A. SayK Q = x0 : y0 : w0 . Take G(x, y, w) := F (x0, y0, w0) and compute the partial derivative of JG with respectK to the first variable: ∂G ∂F ∂F ∂F (x, y, w) = a (x0, y0, w0) + a (x0, y0, w0) + a (x0, y0, w0). ∂x 11 ∂x 21 ∂y 31 ∂w

5In orthodox books on algebraic geometry, projective curves have flexes while the affine ones have inflection points. Here we will use these two terms interchangeably.

Build: January 28, 2021 152 Algebraic curves

Now, compute the second derivatives: ∂2G (x, y, w) = ∂x2  ∂2F ∂2F ∂2F  = a a (x0, y0, w0) + a (x0, y0, w0) + a (x0, y0, w0) + 11 11 ∂x2 21 ∂x∂y 31 ∂x∂w  ∂2F ∂2F ∂2F  + a a (x0, y0, w0) + a (x0, y0, w0) + a (x0, y0, w0) + 21 11 ∂y∂x 21 ∂y2 31 ∂y∂w  ∂2F ∂2F ∂2F  + a a (x0, y0, w0) + a (x0, y0, w0) + a (x0, y0, w0) , 31 11 ∂w∂x 21 ∂w∂y 31 ∂w2 the mixed second derivative ∂2G (x, y, w) = ∂x∂y  ∂2F ∂2F ∂2F  = a a (x0, y0, w0) + a (x0, y0, w0) + a (x0, y0, w0) + 11 12 ∂x2 22 ∂x∂y 32 ∂x∂w  ∂2F ∂2F ∂2F  + a a (x0, y0, w0) + a (x0, y0, w0) + a (x0, y0, w0) + 21 12 ∂y∂x 22 ∂y2 32 ∂y∂w  ∂2F ∂2F ∂2F  + a a (x0, y0, w0) + a (x0, y0, w0) + a (x0, y0, w0) 31 12 ∂w∂x 22 ∂w∂y 32 ∂w2 and so on for the remaining combinations. All in all, what we get is T H (x, y, w) = A H (x0, y0, w0) A. G · F · Compute the determinants of both sides to get: 2 Corollary 8.3. Let A GL3(K), P P K and F K[x, y, w] be respectively: an invertible matrix, a projective∈ point and∈ a homogeneous∈ polynomial. If Q := A P and G(P ) := F (Q), then · h (P ) = det(A)2 h (Q). G · F We are now ready to present a method for finding inflection points on algebraic curves.

Theorem 8.4. Let F be a homogeneous polynomial deg F 2, CF the asso- ciated algebraic curve and P C a non-singular point on it. Then≥ P is a flex if ∈ F and only if hF (P ) = 0. Proof. A projective automorphism does not change the intersection numbers, hence it maps flexes to flexes. On the other hand, it follows from the preceding corollary that the zero-locus of the hessian is invariant under projective transfor- mation. Therefore, without loss of generality, we may assume that P = 0 : 0 : 1 J K is the origin and the tangent L to CF at P is the OX axis. This implies ∂F ∂F ∂F (8.5) (P ) = 0, (P ) = 1, (P ) = 0. ∂x ∂y ∂w ∂F Honestly speaking, we have only (P ) = a = 0, but we can substitute F by F/a ∂y 6 without altering the curve. Sort the terms of F with respect to the degree of w.

n  n 1 F = f0,0,nw + f1,0,n 1x + f0,1,n 1y w − + − − 2 2 n 2 + f2,0,n 2x + f1,1,n 2xy + f0,2n 2y w − + . − − − ··· Build: January 28, 2021 Algebraic curves 153

Since F (P ) = 0, thus f0,0,n = 0. Moreover it follows from Eq. (8.5) that also f1,0,n 1 = 0, while f0,1,n 1 = 1. Consequently − − n 1 2 2 n 2 F = yw − + f2,0,n 2x + f1,1,n 2xy + f0,2n 2y w − + . − − − ··· By the definition (see Section 3), the intersection number I(P,CF OX) equals the multiplicity of the root 0 : 1 of the bivariate polynomial G(x, w∩) := F (x, 0, w) ∈ K[x, w]. The origin is, thus,J aK flex if and only if this multiplicity is at least three, meaning that f2,0,n 2 = 0. On the other hand,− observe that the Hessian matrix of F at P has the form   2f2,0,n 2 f1,1,n 2 0 − − HF (P ) =  f1,1,n 2 2f0,2,n 2 n 1 0 − n 1− − 0 − 2 Consequently, the Hessian equals hF (P ) = 2(n 1) f2,0,n 2. This means that − − − the Hessian vanishes if and only if f2,0,n 2 is null. But, as observed above, this − happens if and only if P is a flex. 

It is now obvious how to find the flexes of CF . All we need to do is to build the algebraic curve associated to the hessian of F and find where it intersects CF . Notice, that, since F is homogeneous so for any a, b x, y, w , not necessarily ∈2 { } distinct, the degree of the second derivative of F is deg ∂ F = deg F 2. Therefore, ∂a∂b − the Hessian is a polynomial of degree deg hF = 3 (deg F 2). The immediate application of the B´ezouttheorem is now: · − Corollary 8.6. An algebraic curve of degree d > 1 has no more than 3d(d 2) inflection points. −

In general we cannot expect an equality in the above corollary even for curves over the complex numbers, as the Hessian may vanish also at a singular point of CF . Example. Take once again the B´ezier cubic curve C with control points (1, 1)T , ( 1, 1)T , (1, 1)T , (1, 1)T . We know (see Example on page 147) that the − − implicit form of C is (CF ,F ), where F = 8x3 27yw2 + 12x2y + 6xy2 + y3. − Compute the Hessian of F : 48x + 24y 24x + 12y 0  2 hF = det 24x + 12y 12x + 6y 54w = 69984(2x + y)w . 0 54w 54y − Drop the constant factor ( 69984). The flexes of C are the solutions of the system of polynomial equations: − ( 8x3 27yw2 + 12x2y + 6xy2 + y3 = 0 − 2xw2 + yw2 = 0. Dehomogenize it and substitute y = 2x into the first equation to see that the only inflection point of C in the affine plane− is the origin (0, 0)T . Now, take w = 0 and check that the are no solutions on the line at infinity. Thus, the origin is the only flex of C in the whole projective plane. Build: January 28, 2021 154 Algebraic curves

9. Cubic curves In this section we return to cubic curves, thus, in a certain sense, it can be viewed as an addendum to Chapter 3. We will use the techniques developed earlier in this chapter to present a full classification of cubics. In this entire section F ∈ R[x, y, w] is a fixed irreducible homogeneous cubic polynomial with real coefficients and CF is the associated projective curve. Recall (c.f. Corollary 4.4) that a cubic curve has at most one singular point, which is then necessarily a double point. It follows from Observation 1.1 that it has real coordinates. Beside a singular point (if any), an algebraic curve may have (finitely many) inflection points. Corollary 8.6 provides an upper limit for their number. Observation 9.1. A cubic curve has at most nine inflection points. Surprisingly there is also a lower bound. A reader may find a proof of the following proposition in [9, Chapter 15]. For a special case—see Exercise 8. Proposition 9.2. A real cubic curve has at least one real flex. Our first goal is to find a special (canonical) form of an algebraic real cubic. Take a projective automorphism that sends a fixed flex of CF to 0 : 1 : 0 at the same time mapping the tangent to the line at infinity w = 0 J. Now F Kis a homogeneous cubic polynomial. In full generality F has a form{ }

3 2 2 3 2 2 2 2 3 F = f0x +f1x y +f2xy +f3y +f4x w +f5y w +f6xyw +f7xw +f8yw +f9w .

We know that CF passes through 0 : 1 : 0 , hence 0 = F (0, 1, 0) = f3. Moreover, J K the line at infinity is tangent to CF at 0 : 1 : 0 , therefore the partial derivatives satisfy J K ∂F ∂F ∂F 0 = (0, 1, 0) = f , 0 = (0, 1, 0) = 3f , 1 = (0, 1, 0) = f . ∂x 2 ∂y 3 ∂w 5 Honestly speaking, we have only ∂F (0, 1, 0) = a = 0 but we may always substitute ∂w 6 F/a for F without altering the curve. Compute the hessian. It must vanish at 0 : 1 : 0 as this is an inflexion point: J K     2f1 2f2 f6 2f1 0 f6 0 = hF (0 : 1 : 0) = det 2f2 6f3 2f5 = det  0 0 2  = 8f1. − f6 2f5 2f8 f6 2 2f8 It follows that F simplifies to a sum of only 7 terms:

3 2 2 2 2 3 F = f0x + f4x w + y w + f6xyw + f7xw + f8yw + f9w . Dehomogenize with respect to the variable w and sort the terms with respect to the powers of y:

2 3 2 f = y + (f6x + f8)y + f0x + f4x + f7x + f9 = 1 1 = y2 + (f x + f )y + (f x + f )2 + f x3 + f x2 + f x + f (f x + f )2 = 6 8 4 6 8 0 4 7 9 − 4 6 8  f x + f 2 f 2 f f f 2 = y + 6 8 + f x3 + (f 6 )x2 + (f 6 8 )x + f 8 . 2 0 4 − 4 7 − 2 9 − 4 Build: January 28, 2021 Algebraic curves 155

T T Take an affine automorphism (x, y) x, y 1/2(f x + f ) . This maps C to 7→ − 6 8 f a new affine curve Cfˆ with fˆ = y2 + Ax3 + Bx2 + Cx + D, 2 2 where A = f , B := f 1/4f , C := f 1/2f f and finally D := f 1/4f . The 0 4 − 6 7 − 6 8 9 − 8 curve CF is irreducible by the assumption and so is Cfˆ. This means that A = 0. T 6 T Take one more affine automorphism, this time mapping (x, y) (x B/3A, y) . 7→ − Substituting it into fˆ we get yet another cubic polynomial  B2  2B3 BC f˜ = y2 + Ax3 + C x + + D. − 3A 27A2 − 3A Finally scale x by 1/√3 A and denote the resulting coefficients: α and β. This way we arrive at the desired− canonical form. Theorem 9.3. For every irreducible cubic curve there is a projective automor- phism mapping it to the curve  x : y : w y2w x3 αxw2 βw3 = 0 . J K | − − − The above is called the Weierstrass normal form of a cubic curve. Recall that two algebraic curves are said to be projectively equivalent if there is a projective automorphism that maps onto the other. The theorem asserts that any cubic is projectively equivalent to a curve in normal form. We will concentrate on singular cubics since they admit parametrization (in this case it is also possible to simplify the Weierstrass form even further as we shall soon discover). A singular cubic curve has a unique double point. There are exactly three possible cases depicted in Figure 6.9: (A) The two tangents at the singular points are equal. Thus the point is a cusp and the double tangent is necessarily real by Observation 1.1. (B) The two tangents are distinct and real. The singular point is then a node called a . (C) One of the tangents is not real. It follows from Observation 1.1 that the other tangent is conjugated (and so also not real). The singular point is then isolated in the real plane but a node in the complex plane. We call it an . It is easy to classify cubic curves in normal forms. 2 3 2 3 Proposition 9.4. Let (CF ,F ) with F = y w x αxw βw be a cubic curve in the normal form. The curve is − − − smooth if and only if 4α3 + 27β2 = 0; • cuspidal if and only if α = β = 0;6 • crunodal if and only if 4α3 + 27β2 = 0 and β > 0; • acnodal if and only if 4α3 + 27β2 = 0 and β < 0. • Proof. We know that 0 : 1 : 0 is an inflection point of CF and the tangent to J K CF at this point is just the line at infinity. It follows from the B´ezouttheorem that it is the only point where CF intersects the line at infinity. The curve is singular if there is a point P = x : y : w where all three partial derivatives are zero. The partial derivatives are J K ∂F ∂F ∂F = 3x2 αw2, = 2yw, = y2 2αxw 3βw2. ∂x − − ∂y ∂w − − Build: January 28, 2021 156 Algebraic curves

Figure 6.9. Three types of singular cubics. Left to right: cus- pidal, crunodal and acnodal. The positions of double points are marked with dots.

The singular point, if there is one, is affine. Hence we may take w = 1. These leads to the system of polynomial equations  3x2 α = 0 − − 2y = 0 y2 2αx 3β = 0. − − It follows that y = 0 and x = 3β/2α, when α = 0 and x = 0 if α = 0. In both cases 4α3 + 27β2 = 0 which proves− the first assertion.6 Suppose now that CF is singular. Dehomogenize F to get the affine curve 2 2 3 T Cf = CF R and f = y x αx β. The singular point is either (0, 0) if ∩ T − − − 2 3 α = β = 0 or ( 3β/2α, 0) if α = 0. In the first case f = y x and the double tangent has the− equation y = 0.6 − If, on the other hand, α = 0, then also β = 0 since 4α3 + 27β0 = 0 and the T 6 6 singular point is ( 3β/2α, 0) . Translate it to the origin substituting f with − 3β  9β  fˆ(x, y) = fx , y = x3 + x2 + y2 . − 2α − 2α The homogeneous part of fˆ of degree 2 factors as r r 9β  9β  9β  x2 + y2 = y + x y x . 2α −2α − −2α

Hence Cfˆ has two distinct tangents at the origin, thus the singular point is a node. 3 2 The tangents are real if and only if 9β/2α > 0. Recall that 4α + 27β = 0 and so − α < 0. It follows that the singular point is a crunode if and only if β > 0.  Write the Weierstrass normal form of f as y2 = x3 + αx + β. Then the expres- sion ∆ := 4α3 + 27β2 appearing in the above proposition is nothing else but the discriminant of the right hand side. Figure 6.10 provides a geometric interpolation of the proposition: consider a cubic curve C∆ in the 0αβ plane associated to the discriminant ∆. It partitions the plane into five parts. Any pair (α, β)T not on C∆ gives rise to a non-singular curve Cf . Those that are right to C∆ correspond to connected curves, while those left to C∆ corresponds to curves consisting of two components. The points directly on the curve C∆ give rise to singular cubic curves: the pairs (α, β)T above the Oα axis produce crunodal curves, the ones below Oα Build: January 28, 2021 Algebraic curves 157

C ∆ β crunodal one comp.

α two comp’s cuspidal

acnodal

Figure 6.10. Weierstrass plane partitioning. produce acnodal curves. Finally the origin corresponds to a cuspidal curve, as we know from the proposition. Imagine that we move on Oαβ plane around the origin in the counter-clockwise direction starting somewhere on the negative half-axis Oα. First we deal with a curve with two connected components: one bounded and one unbounded. As we approach the lower half-branch of C∆, the bounded component contracts to collapse finally to an isolated point when we reach C∆. After we cross the discriminant curve the point disappears completely and we deal with a curve with just one component, which gradually bulges. On the upper half-branch of C∆, two so far distinct point of the curve Cf merge together producing a loop. The bulge separates from the rest of the curve once we cross C∆. Observe that Theorem 9.3 together with Proposition 9.4 imply that every cus- pidal cubic is projectively equivalent to the curve associated with the polynomial y2 x3. One may prove a similar result for nodal curves, as well. Indeed, take a crunodal− cubic given by the equation y2 = x3 + αx + β with 4α3 + 27β2 = 0 and β > 0. Consider the substitution (i.e. an affine iso- p morphism) x 3β/2α 9β/2α x and y y 27/2 β. The equation becomes then 7→ − − · 7→ · 27  3β 9β 3  3β 9β  βy2 = − x + α − x + β. 2 2α − 2α 2α − 2α This simplifies to y2 = x3 + x2.

Analogously, if the given curve is acnodal, then take the substitution x 3β/2α p 7→ − − 9β/2α x and y y 27/2 β. to show that it is affinely equivalent to · 7→ − · y2 = (x3 + x2). − Corollary 9.5. Every cuspidal curve of degree 3 is projectively equivalent to the curve • Cy2 x3 . In particular every two cuspidal cubics are projectively equivalent. Every− crunodal curve of degree 3 is projectively equivalent to the curve • Cy2 x3 x2 . In particular every two crunodal cubics are projectively equiv- alent.− − Build: January 28, 2021 158 Algebraic curves

Every acnodal curve of degree 3 is projectively equivalent to the curve • Cy2+x3+x2 . In particular every two acnodal cubics are projectively equiv- alent.

The above corollary provides the classification criterion of irreducible singular cubics. For non-singular cubics, the situation is completely different since there are infinitely many classes of smooth cubic curves with respect to projective equivalence (see e.g. [9, Chapter 15]). We now compute the number of inflection points for all three classes of singular cubic curves. Take the projective cuspidal curve CF with F = y2w x3. Its Hessian is −  6x 0 0  − 2 hF = det  0 2w 2y = 24xy . 0 2y 0

The curve hF = 0 intersects CF at two points: 0 : 0 : 1 and 0 : 1 : 0 . The { } J K J K first one is the cusp and so the second is the unique flex of CF . Analogously one counts the number of flexes of a crunodal and an acnodal curves.

Proposition 9.6. A cuspidal cubic has exactly one flex. It has real coordinates. • A crunodal cubic has one real and two non-real flexes. • An acnodal cubic has three flexes, all of them real. • In Section 8 we learned that every singular cubic can be parametrized. Hence, we may apply the above results to parametric curves. First we deal with an untrimmed curve and only later turn our attention to a trimmed one. Let C = C(P0,P1,P2,P3) be an untrimmed polynomial B´eziercubic curve. If all four con- trol points are co-linear, then the curve degenerates into a line (see Exercise 1 in Chapter 4), possibly incorrectly parametrized. Assume that they are not co-linear. Without loss of generality we may assume that the points P0,P1,P2 do not lie on a common line (if they do just reverse the parametrization taking C( t) in place of C(t)). What’s more, choosing an appropriate affine , we− may actually assume that the positions of these three points are fixed as follows:

0 0 1 P = ,P = ,P = . 0 0 1 1 2 1

Denote the last control point by P := P3. Its position determines the geometric T type of C. Let P = (xP , yP ) , we write C in an explicit form:

0 0 1 x  (x 3)t3 + 3t2 C(t) = b3(t) + b3(t) + b3(t) + P b3(t) = P − , 0 0 1 1 1 2 y 3 y t3 3t2 + 3t P P − 3 where bi is the i-th Bernstein polynomial of degree three (see Section 2 in Chapter 3 or Section 2 in Chapter 4). First we deal with the special case, when the coefficients at t3 vanish.

Observation 9.7. The curve C degenerates to a parabola if and only if P = (3, 0)T . Build: January 28, 2021 Algebraic curves 159

T T T In what follows, assume that P = (3, 0) and let Q = (xQ, yQ) = (xP 3, yP ) be its translation. Implicitize C eliminating6 the variable t: − (9.8) ResB(x x t3 3t2, y y t3 + 3t2 3t) = t − Q − − Q −  3x 3x 3y y x x y  − − Q − Q = det  3x 3y 9 + yQx xQy 3xQ  = y−x −x y 3x − 3x 3y Q − Q Q − Q − P = (y x x y)3 + 9A x2 + A xy + A y2 27A x, − Q − Q 1 2 3 − 3 2 2 where A1 = 3(xQ xQyQ + yQ) 2yQ, A2 = (6xQ + xQyQ + 6yQ) + 3xQ and −2 − A3 = 3(xQ + yQ) + xQ. Let F denote the homogenization of the above polynomial. In order to find the intersection points of C and the line at infinity let w = 0. We have F (x, y, 0) = (x y y x)3 = 0 so that y x = x y. Consequently the C has Q − Q Q Q only one point at infinity which is xQ : yQ : 0 = xP 3 : yP : 0 . Theorem 5.3 asserts that C, beingJ a polynomialK J − curve, hasK exactly on place at infinity. On the other hand, it follows from the B´ezout theorem that C has exactly three points at infinity. This leaves us with two possibilities only: the point xP 3 : yp : 0 is either a cusp or a flex. In both cases the line at infinity must be tangentJ − to C there.K Consider the first case. If the point at infinity is a cusp, then C has exactly one inflexion point, necessarily affine, by Proposition 9.6. The point xQ : yQ : 0 is singular, hence all three derivatives of F vanish at it. Thus J K ∂F (x , y , 0) = 3y3 x2 + 6x y2 x y 3x2 y y2 = 0 ∂x Q Q − Q Q Q Q Q Q − Q Q Q ∂F (x , y , 0) = 3x y2 x2 6x2 y x y + 3x3 y2 = 0 ∂y Q Q Q Q Q − Q Q Q Q Q Q and the last one ∂F (x , y , 0) = 9(A x2 + A x y + A y2 ) = 27(x + y )3. ∂w Q Q 1 Q 2 Q Q 3 Q Q Q Therefore, the point xQ : yQ : 0 = xP : yP : 0 is singular on C if and only if x + y 3 = 0. Thus,J we have proved:K J K P P − Observation 9.9. The curve C has a cusp at infinity, and consequently a single affine inflection point, if and only if the last control point P lies on the line x + y 3 = 0 with the point (3, 0)T excluded. − Now, suppose that xQ + yQ = 0 and so C has a flex at infinity and the tangent to C at it is the line at infinity.6 Consider a projective (in fact linear) isomorphism 2 1  ϕ sending x : y : w to xyQ yxQ : yyQ : wyQ . Then ϕ− x : y : w = J K J − K J K xyQ + yxQ : yyQ : w . Let Cˆ be the image of C under ϕ. The associated J K 1 polynomial is G = F ϕ− . Observe that ϕ maps the inflection point xQ : yQ : 0 to 0 : 1 : 0 preserving◦ the tangent line at the same time. Thus,J we are atK exactlyJ the sameK situation as when we introduced the Weierstrass normal form (c.f. page 154). Repeat the same computations to get: 2 3 3(xQ(xQ + 4) + 4yQ) (xQ(xQ + 4) + 4yQ) α = 4 , β = 6 . − 16(xQ + yQ) 32(xQ + yQ) Both denominators are non-zero by the assumption. On the other hand, the nu- merators vanish if and only if the condition 4y + (x 3)(x + 1) = 0 holds. This P P − P Build: January 28, 2021 160 Algebraic curves

y

two infl. points P1 P2 parabola

one infl. point P0 x

cusp node

Figure 6.11. Plane partitioning following from Corollary 9.11. is just a parabola equation. If P lies on this parabola, then α = β = 0 and C is a cuspidal curve. If P lies above or below the parabola, then the curve C is respec- tively acnodal or crunodal by Proposition 9.4. The following theorem summarizes our discussion. Theorem 9.10. Let C be an untrimmed polynomial B´eziercurve with control points (0, 0)T , (0, 1)T , (1, 1)T and P . The position of P determines the geometric type of the curve C as follows: C is a parabolla if and only if P = (3, 0)T ; • C is cuspidal with the cusp at infinity and an affine flex if and only if P • lies on the line x + y 3 = 0 with the point (3, 0)T excluded; C is cuspidal with the− cusp at a finite distance and a flex at infinity if and • only if P lies on the parabola 4y + (x 3)(x + 1) = 0 with the point (3, 0)T excluded; − C is crunodal if P lies below the parabola 4y + (x 3)(x + 1) = 0; • C is acnodal if P lies above the parabola 4y + (x −3)(x + 1) = 0 but not • on the line x + y 3 = 0. − − Observe that in the last case, the acnode is an isolated point of the algebraic curve C and so it does not belong to the parametric curve. Restricting ourselves to affine part of C and combining Theorem 9.10 with Proposition 9.6 we get: Corollary 9.11. Let C be as in the above theorem, then it is a parabola if and only if P = (3, 0)T ; • it has one inflection point if and only if P lies on the line x + y 3 = 0 • excluding the point (3, 0)T ; − it has two inflection points but no (affine) singularities if and only if P lies • above the parabola 4y +(x 3)(x+1) = 0 but not on the line x+y 3 = 0; it has a cusp and no (affine− ) flexes if and only if P lies on the parabola− • 4y + (x 3)(x + 1) = 0 with the point (3, 0)T excluded; it has a− crunode and no (affine) flexes if and only if P lies below the • parabola 4y + (x 3)(x + 1) = 0. − Figure 6.11 illustrates the above corollary. So far we have been analyzing untrimmed curves. In real life applications, most of the time we deal with trimmed parametric curves (segments) with the parameter varying over the unit interval [0, 1]. One may extend the results of Corollary 9.11 to cover the trimmed case Build: January 28, 2021 Algebraic curves 161 as well—see [24] for details. There is, however, another more straightforward ap- proach. Propositions 9.12–9.14 below together with the accompanying Algorithm 9 are based upon [27]. We omit the proofs referring the reader to the above-mentioned paper instead. Let C = C(P0,P1,P2,P3) be a “standard” trimmed polynomial B´eziercurve T with the parameter varying over the unit interval and let Pi = (xi, yi) . For a triple i, j, k with 0 i < j < k 3 we denote by D the following determinant ≤ ≤ ijk   xi yi 1 Dijk := det xj yj 1 . xk yk 1 We let s := sgn D be the sign of this determinant and S = s , s , s , s ijk ijk { 012 013 023 123} be the set of all sijk’s. Finally denote ∆ := D (D + 2D ) D (3D + 4D ), σ := sgn ∆. 013 013 012 − 012 012 023 Observe that, just by its definition, the determinant Dijk is zero if and only if the control points Pi, Pj, Pk are co-linear. First, we shall deal with the “general” case, when no three control points are co-linear. Using the terminology introduced in Section 1 in Chapter 2, we say that the points are in general position. The set S does not contain zero, then.

Proposition 9.12. If the control points P0,P1,P2,P3 of a B´eziercurve C are in general position, then

(1) C has a single inflection point if and only if s012 = s123; (2) C has two inflection points if and only if σ = 1 and6 exactly one of the two conditions holds: either s012 = s123 = s013 = s023 • 6 D  or s = s , s = s and the point P := C 013/D013 D023 • 012 123 013 6 023 − lies on the line segment P0P3; (3) C has a cusp if and only if σ = 0 and exactly one of the two conditions of point 2 holds; (4) in all other cases C has neither a flex nor a singular point. Algorithm 9 is an immediate implementation of the above proposition. We are now left with the special case when three (or four) control points are co-linear. If all the points are co-linear, then the curve degenerates to a line (or a point if they are equal). Hence suppose that exactly three of them lie on one line. Either these are the consecutive points or not.

Proposition 9.13. If the points P0, P1, P2 are co-linear, then C has no sin- gular point. Moreover C has a single flex if and only if s013 = s123, otherwise C has no inflection points. 6

The other case of consecutive co-linearity (i.e. when P1, P2, P3 are co-linear and so s123 = 0) is fully analogous. It suffices to reverse the parametrization taking C( t) instead of C(t). Consider the case of nonconsecutive co-linearity. We − explicitly formulate the result only for s013 = 0 since the case s023 = 0 is again analogous.

Proposition 9.14. If the points P0, P1 and P3 are co-linear, then C has one flex if and only if P lies on P P ; • 1 0 3 Build: January 28, 2021 162 Algebraic curves

Algorithm 9: Geometric type classification of a trimmed B´eziercubic with control points in general position.

Input: P0,P1,P2,P3 — control points of a B´eziercurve Result: geometric type of a curve forall (0 i < j < k 3) do ≤  xi yi≤1  Dijk det xj yj 1 ; ← xk yk 1 s sgn D ; ijk ← ijk P C( D013 ); D013 D023 ← − if s012 = s123 then return6 one flex;

else if (s123 = s013 = s023) (s013 = s023 P P0P3) then ∆ D 6 (D + 2D ∨) D 6 (3D ∧+ 4∈D ); ← 013 013 012 − 012 012 023 σ sgn ∆; ← switch σ do case σ = 1 do return two flexes; ; case σ = 0 do return cusp; ; case σ = 1 do return crunode; − ; else return no flexes and no singularities;

C has two flexes if and only if P3 lies on P0P1 and σ = 1; • C has a cusp if and only if P lies on P P and σ = 0; • 3 0 1 C has a crunode if and only if P3 lies on P0P1 and σ = 1; • in all other cases C has neither a flex nor a singular point.− • Example. Consider once again the B´eziercurve with control points ( 1, 1)T , ( 1, 1)T , (1, 1)T and (1, 1)T , that we have already encountered in previous− − ex- amples.− This− time, however, we concentrate on the arc corresponding to t [0, 1]. Compute the four determinants ∈

 1 1 1  1 1 1 − − − − D012 = det  1 1 1 = 4,D013 = det  1 1 1 = 4 −1 1 1 − −1 1 1 − −  1 1 1  1 1 1 − − − D023 = det  1 1 1 = 4,D123 = det  1 1 1 = 4. 1− 1 1 1− 1 1

It follows that s012 = 1 = 1 = s123 and Proposition 9.12 asserts that C has a single flex. This agrees− with6 our earlier findings. As we know C has a flex at the origin corresponding to t = 1/2 (see the example on page 153). Build: January 28, 2021 Algebraic curves 163

Implementation notes TO DO

Exercises

(1) Let F,G C[x, y, w] be two homogeneous polynomials. Assume that they are relatively∈ prime and their degree equal respectively n and m. Prove that the resultant Resw(F,G) C[x, y] is a homogeneous polynomial of degree n m. ∈ · (2) Prove that the discriminant ∆f of a polynomial f C[t] equals ∈ 2(n 1) Y 2 b − (a a ) , j − i 1 i 1. (8) Prove• Proposition 9.2 for non-singular cubic curves using B´ezout’s theo- rem. (9) Let C(t) = x(t), y(t)T be a parametric B´ezier cubic. Show that a point P = C(t0) is a cusp if and only if x0(t0) = 0 = y0(t0). (10) Extend Algorithm 9 to cover the criteria described in all three propositions 9.12–9.14. Bibliographic notes TO DO

Build: January 28, 2021

Part 3

Geometry of solids and surfaces

CHAPTER 7

Polygons and polyhedra

1. Triangles Triangles are the simplest of all polygons. At the same time, of all the polygons that exist, these are the triangles that are most often used in practice (computer graphics, geodesy). In early days of 3D computer graphics, triangles along with points and line segments were the only primitives used. Thus, in this section we gather some basic properties of the triangles. Recall from a basic course of calculus that a subset S Rn is convex if the line segment PQ, joining any two points P,Q of S, is full contained⊂ in S. In other words, S is convex of lerp(P,Q; t) S for all P,Q S and every t [0, 1]. (The operator lerp was introduced in Section∈ 4 of Chapter∈ 2.) An empty∈ set is a (degenerate) example of a convex set. The convex hull of a nonempty set S Rn is the smallest convex set containing S. The convex hull of S is denoted conv⊂ S. Later we will learn how to find a convex hull of a finite set. Given three distinct and non-collinear points P, Q, R Rn. their convex hull conv P, Q, R is called the triangle with vertices P, Q, R and∈ denoted P QR. All the points{ of} the given triangle P QR are convex combinations of the4 vertices: P QR = p P + q Q + r R 4p, q, r [0, 1] and p + q + r = 1 . The numbers p,4 q, r are called· the ·barycentric· | coordinates∈ of the point B. The line segments P Q, QR, RP are the edges of P QR. The points on the edges are characterized by the property that one of the4 barycentric coordinates (the one corresponding to the opposite vertex) is null. Recall from the course of linear algebra that the affine plane spanned by P, Q, R is

 aff(P, Q, R) = p P + q Q + r R p, q, r R and p + q + r = 1 . · · · | ∈

Here we do not assume that p, q, r are non-negative. It follows immediately that every triangle is contained in the plane spanned by its vertices. Therefore, in what follows, we will often restrict our discussion to triangles contained in R2, unless it is important that the triangle in question is contained in a bigger ambient space. There are many known formulas for the area of a triangle. Marcus Baker in his two papers [2, 3] collected over a hundred such formulas. Probably the best 1 known is the formula 2 ah, where a stands for the length of a (fixed) edge and h is the height of this triangle (with respect to the selected edge). Figure 7.1 presents a geometric derivation of this formula. From the computational point of view, a more convenient formula is the one based on the notion of a cross-product, as it directly uses the coordinates of the T vertices of the triangle. Recall that a cross-product of two vectors u = (xu, yu, zu) Build: January 28, 2021 168 Polygons and polyhedra

h

h/2

a a

Figure 7.1. Graphical proof of the formula for the area of a triangle.

T and v = (xv, yv, zv) is  yu yv  det ( zu zv ) zu zv u v := det ( xu xv ) . × xu xv det ( yu yv ) More briefly, albeit not quite formally, we may write   ε1 xu xv u v = det ε2 yu yv  . × ε3 zu zv

Here ε1, ε2 and ε3 denote the canonical basis vectors. Proposition 1.1. If P, Q, R R3 are three points, then the area of the triangle ∈ P QR equals 1 −−→PQ −→PR . 4 2 k × k Proof. If P , Q, R happen to be colinear, then the triangle degenerates to a line segment. Hence its area is null. On the other hand, in such a case the vectors −−→PQ and −→PR are linearly dependent and so −−→PQ −→PR = 0, as well. Thus, without loss of generality we may assume that the three× points are not colinear. Observe that the cross-product −−→PQ −→PR is invariant under translations, since we are using only the vectors (i.e. differences× between points) not the vertices themselves. When translating the triangle, the coordinates of its vertices change, but the coordinates of the corresponding vectors are intact (see Corollary 1.3.2). Further, if Ov,α is the matrix of a rotation, then

(Ov,α −−→PQ) (Ov,α −→PR) = Ov,α (−−→PQ −→PR) = −−→PQ −→PR , · × · · × k × k since rotation do not alter the length of a vector (rotation is an isometry). Of course, neither translation nor rotation changes the area of a triangle. Thus, without loss of generality, we may assume that the triangle P QR is contained in the OXY plane, the vertex P lies at the origin and Q lies4 on the OX axis. In other words, we have       0 xQ xR P = 0 ,Q =  0  ,R = yR  . 0 0 0

Let PQ be the base of the triangle. Hence, the length of the base equals xQ and the corresponding height is y . Compute now the cross-product | | | R|

1 1 xQ xR T 1 1 −−→PQ −→PR = 0, 0, det = xQyR = xQ yR . 2 × 2 0 yR 2 | | 2 | | · | | Build: January 28, 2021 Polygons and polyhedra 169

This proves the proposition.  Observe that for a triangle P QR contained in the OXY plane it is only the 4 last coordinate of the cross-product −−→PQ −→PR which is nonzero. (We have already used this fact in the above proof.) Thus,× the length of the cross-product (i.e. twice the area of the triangle) is just

−−→PQ −→PR = det(−−→P Q, −→PR) . × Her, as always, −−→PQ and −→PR are treated as column vectors. This let us introduce a notion of a signed area, that will be useful later.

2 1 Definition 1.2. If P, Q, R R are three distinct points, then 2 det(−−→P Q, −→PR) is called the signed are of the triangle∈ P QR. 4 We do not assume here that the points are in general position. If they are collinear, then the triangle degenerates to a line segment and its signed area is null. The signed area of a proper triangle is positive (hence equal the actual area) if and only if the vertices are arranged in counter-clockwise order. Otherwise it is negative. The rest of this section is devoted to describing various characteristic points (“centers” in different sense) in a given triangle. Theorem 1.3. The three altitudes of a triangle intersect in a single point, called the orthocenter of the triangle. Recall that the orthogonal bisector of a line segment PQ is a line perpendicular to PQ and passing through its midpoint. Theorem 1.4. The orthogonal bisectors of the three edges of a triangle intersect in a single points, called the circumcenter of the triangle. The circumcenter is the center of the circle circumscribed on the triangle.

The angle bisector of an angle ^P QR is the line dividing the angle into two congruent angles. Equivalently it is a line consisting of all the points equidistant from the lines aff(P,Q) and aff(QR). Theorem 1.5. The angle bisectors of the three angles of a triangle intersect in a single point, called the incenter of the triangle. The incenter of the triangle is the center of the circle inscribed in the triangle. A median of a triangle is the line that passes through one of its vertices and the midpoint of the opposite side. Theorem 1.6. The three medians of a triangle intersect in a single point, called the centroid of the triangle. . Proposition 1.7. The centroid divides each median in a ratio of 2 : 1 1 1 1 Proposition 1.8. The centroid has barycentric coordinates 3 , 3 , 3 . In par- ticular each coordinate of the centroid is obtained as the arithmetic mean of the corresponding coordinate of the three vertices. Proposition 1.9. The three medians divide the triangle into six triangles of equal areas.

Proofs, symedians, nine-points-circle

Build: January 28, 2021 170 Polygons and polyhedra

2. Convex polytopes In this section we introduce one of the most fundamental classes of geometric objects, that includes convex polygons and convex polyhedra. Here we will only touch the issue since we do not have enough space to full present this deep and beautiful subject. For a more complete discussion we refer the reader to monographs missing . Definition 2.1. A convex polytope is a convex hull of any finite set of points in an affine space Rn. The dimension of the convex polytope A = conv P ,...,P is the dimension { 1 k} of the smallest affine space containing it, i.e. dim A := dim aff P1,...,Pk . By virtue of the above definition, the empty set is a convex polytope.{ We} define its dimension to be 1. A convex polytope of dimension zero is a singleton, a set consisting of just− a single point. Convex polytopes of dimension one are line segments. Convex polytopes of dimension two are called convex polygons. Convex polytopes of dimension three are called convex polyhedra. In this book we will not deal with convex polytopes of higher dimensions. Some examples of convex missing polytopes are presented in Figure . The most fundamental fact about convex polytopes is that they can be al- ternatively described as intersections of finitely many half-spaces. A half-space of n dimension n > 0 is a set H = Hv,α R of a form ⊂  n Hv,α := P R v −−→ΘP α ∈ | • ≥ for some α R and a vector v Rn. ∈ ∈ Theorem 2.2. A bounded subset A Rn is a convex polytope if and only if n ⊂ there are half-spaces H1,...,Hk R such that A = H1 ... Hk. ⊂ ∩ ∩ Before we present a proof, let us first build some intuition. To this end consider the following example. Take a triangle (see Figure 7.2) with vertices: 1 10 7 P = ,Q = ,R = . 1 2 6 Construct a line through every two vertices: aff(P,Q): x 9y + 8 = 0, − aff(P,R) : 5x 6y + 1 = 0, − aff(Q, R) : 4x + 3y 46 = 0. − Each of these three lines defines two half-planes. Choose the one that contain the vertex not on the line:        x 2 1 x H1 = R 8 , y ∈ | 9 • y ≤ −   −     x 2 5 x H2 = R 1 , y ∈ | 6 • y ≥ −   −    x 2 4 x H3 = R 46 . y ∈ | 3 • y ≤

It is now clear that P QR = H1 H2 H3. We will now generalize this idea to prove Theorem 2.2. 4 ∩ ∩ Build: January 28, 2021 Polygons and polyhedra 171

R

Q P

Figure 7.2. Triangle as an intersection of three half-planes.

Pi

P1

Figure 7.3. Triangulation of a convex polygon.

Proof

3. Convex polygons We will define arbitrary polygons as unions of triangles (see ). First, however, missing we need to show that convex polygons, as defined above, admit triangulations.

Observation 3.1. Let A be a convex polygons with vertices P1,...,Pk. Then the pencil of lines passing through P1 and each of P2,...,Pk subdivides A into (k 2) triangles with the following properties: − A is a union of all these triangles; • any two distinct triangles share either a vertex P or an edge P P . • 1 1 i Figure 7.3 illustrates the above observation. We let the reader write a detailed formal (and boring) proof. We know that a convex polygon is the convex hull of finitely many points. This raises a question how do we find the convex hull given a finite subset of the real affine plane. This is an example of problems considered in a branch of mathematics called “computational geometry”. There are numerous algorithms for constructing the convex hull of a given (finite) set. For a thorough discussion of a problem we refer the reader to specialized monographs like [20, 5]. Here we present just one solution. T T 2 Let P1 = (x1, y1) ,...,Pn = (xn, yn) R be some fixed points. Denote A := P ,...,P . We are going to construct∈ the polyline that forms the boundary { 1 n} Build: January 28, 2021 172 Polygons and polyhedra

of the convex hull conv(A). Since sorting algorithms are well known, we may assume that the points are arranged in a non-descending order with respect to their abscissæ, that is x x for i < j. This implies that P is the left-most and i ≤ j 1 Pn the right-most point of the set. In particular, both these points must belong to the boundary we are after. Take a line L through P1 and Pn. It splits the boundary missing into two chains of points (see Figure ). One chain, denoted conv(A), is called the upper hull and consists of the boundary points laying on and above L. The other chain, consisting of the points on and below L, is called the lower hull and denoted conv(A). In a degenerate case, when all the points are colinear, the upper and lower hull coincide. In such a case the convex hull consists of the line segment P1Pn. We will incrementally construct the lower (respectively upper) hull of A starting from its right-most point Pn. To this end, denote A := P ,P ,...,P for i 1. i i i+1 n} ≥ In particular A1 = A and An = Pn . We have conv(An) = conv(An) = pn . Assume that we have constructed{ the} lower and uppers hulls of A for some i{ n}. i ≤ We shall construct the lower and upper hulls of Ai 1. We will use the following basic fact. −

Observation 3.2. There is a unique line Li that passes through Pi 1 and at − least one of the points of conv(Ai), and all the points of Ai lie on or above Li. Likewise, there is a unique line Ui that passes through Pi 1 and at least one of the − points of conv(Ai), and all the points of Ai lie on or below Ui.

In order to prove this observation consider all the lines through Pi 1 and one − of the points of Ai. There are only finitely many of them. Then Li is the line of the minimal slope and Ui is the line of the maximal slope. Consider now the intersection L A .(respectively U A ). The left-most point of this set will be i ∩ i i ∩ i called the point of tangency of Li (respectively Ui). It is clear that the point of tangency of Li belongs to the lower hull conv(Ai) , while the point of tangency of Ui belongs to conv(Ai). Assume that conv(Ai) consists of an ordered chain of

points (Pi1 ,...,Pim ), sorted with respect to their abscissæ. Let Pik be the point of

tangency of Li. The point Pik is then uniquely determined by two conditions:

if k > 1, then the point Pi k 1, directly preceding Pik in the chain, lies • − −  strictly above Li, i.e. det −−−−−→Pi 1Pik , −−−−−−−→Pi 1,Pik−1 > 0; − − i k < m, then the point Pik+1 , directly succeeding Pik in the chain, lies on •  or above Li, i.e. det −−−−−→Pi 1Pik , −−−−−−→Pi 1Pik+1 0. − − ≥

Build: January 28, 2021 CHAPTER 8

Parametric surfaces

Build: January 28, 2021

Bibliography

[1] Shreeram S. Abhyankar. Algebraic geometry for scientists and engineers, volume 35 of Math- ematical Surveys and Monographs. American Mathematical Society, Providence, RI, 1990. [2] Marcus Baker. A collection of formulae for the area of a plane triangle. Ann. of Math., 1(6):134–138, 1885. [3] Marcus Baker. A collection of formulae for the area of a plane triangle. Ann. of Math., 2(1):11–18, 1885. [4] Phillip J. Barry and Ronald N. Goldman. A recursive evaluation algorithm for a class of Catmull-Rom splines. Computer Graphics, 22(4):199–204, August 1988. [5] Mark de Berg, Otfried Cheong, Marc van Kreveld, and Mark Overmars. Computational Geometry: Algorithms and Applications. Springer-Verlag TELOS, Santa Clara, CA, USA, 3rd ed. edition, 2008. [6] Germund Dahlquist and Ake˚ Bj¨orck. Numerical mathematics and scientific computation. W przygotowaniu. [7] Tony DeRose. Three-dimensional computer graphics. a coordinate-free approach. Nie opub- likowana, 10 1992. [8] James D. Foley, Andries van Dam, Steven K. Feiner, and John F. Hughes. Computer graphics: principles and practice (2nd ed.). Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1990. [9] Christopher G. Gibson. Elementary geometry of algebraic curves: an undergraduate intro- duction. Cambridge University Press, Cambridge, 1998. [10] Ron Goldman. On the algebraic and geometric foundations of computer graphics. ACM Transactions on Graphics, 21(1):1–35, January 2002. [11] John D. Hobby. Smooth, easy to compute interpolating splines. Discrete Comput. Geom., 1(2):123–140, 1986. [12] W. V. D. Hodge and D. Pedoe. Methods of algebraic geometry. Vol. I. Cambridge Mathemat- ical Library. Cambridge University Press, Cambridge, 1994. Book I: Algebraic preliminaries, Book II: Projective space, Reprint of the 1947 original. [13] Bert J¨uttlerand Pavel Chalmoviansk´y.Approximate parameterization by planar rational curves. In SCCG ’04: Proceedings of the 20th spring conference on Computer graphics, pages 34–41, New York, NY, USA, 2004. ACM Press. [14] Anthony W. Knapp. Basic algebra. Cornerstones. Birkh¨auserBoston Inc., Boston, MA, 2006. Along with a companion volume ıt Advanced algebra. [15] Alexei I. Kostrikin and Yuri I. Manin. Linear algebra and geometry, volume 1 of Algebra, Logic and Applications. Gordon and Breach Science Publishers, Amsterdam, english edition, 1997. Translated from the second Russian (1986) edition by M. E. Alferieff. [16] Tsit-Yuen Lam. Introduction to quadratic forms over fields, volume 67 of Graduate Studies in Mathematics. American Mathematical Society, Providence, RI, 2005. [17] Serge Lang. Algebra, volume 211 of Graduate Texts in Mathematics. Springer-Verlag, New York, third edition, 2002. [18] E. T. Y. Lee. Choosing nodes in parametric curve interpolation. Comput. Aided Des., 21:363– 370, July 1989. [19] Dinesh Manocha and John Canny. Rational curves with polynomial parametrization. Com- puter Aided Design, 23(9):653–653, 1991. [20] Franco P. Preparata and Michael I. Shamos. Computational Geometry: An Introduction. Springer-Verlag, Berlin, Heidelberg, 1985.

Build: January 28, 2021 176 Bibliography

[21] Thomas W. Sederberg. Applications to computer aided geometric design. In Applications of computational algebraic geometry (San Diego, CA, 1997), volume 53 of Proc. Sympos. Appl. Math., pages 67–89. Amer. Math. Soc., Providence, RI, 1998. [22] Ken Shoemake and Tom Duff. Matrix animation and polar decomposition. In Proceedings of the conference on Graphics interface ’92, pages 258–264, San Francisco, CA, USA, 1992. Morgan Kaufmann Publishers Inc. [23] Jorge Stolfi. Primitives for computational geometry. Technical Report 36, Digital Equipment Corporation, jan 1989. [24] Maureen Stone and Tony DeRose. A geometric characterization of parametric cubic curves. ACM Trans. Graph., 8(3):147–163, 1989. [25] Bernd Sturmfels. Introduction to resultants. In Applications of computational algebraic ge- ometry (San Diego, CA, 1997), volume 53 of Proc. Sympos. Appl. Math., pages 25–39. Amer. Math. Soc., Providence, RI, 1998. [26] Kazimierz Szymiczek. Bilinear algebra, volume 7 of Algebra, Logic and Applications. Gordon and Breach Science Publishers, Amsterdam, 1997. [27] Stephen Vincent. Fast detection of the geometric form of two-dimensional cubic B´eziercurves. Journal of Graphics Tools: JGT, 7(3):43–51, 2002. [6]

Build: January 28, 2021