1 of 17

��� Chapter II�Mathematics: Basics

All class materials including this PowerPoint file are available at

https://github.com/medialab-ku/openGLESbook

Introduction to Computer Graphics with OpenGL ES (J. Han)

2 of 17

Matrices and Vectors

2-2

  • This chapter delivers an explicit presentation of the basic mathematical techniques, which are necessary throughout this book.
  • m×n matrix

  • If m = n, the matrix is called square.
  • Matrix-matrix multiplication

  • If A’s dimension is l×m and B’s dimension is m×n, AB is an l×n matrix.

Introduction to Computer Graphics with OpenGL ES (J. Han)

3 of 17

Matrices and Vectors (cont’d)

2-3

  • The typical representation of a 2D vector, (x,y), or a 3D vector, (x,y,z), is called a row vector. Instead, we can use a column vector:
  • Matrix-vector multiplication

  • Transpose denoted by MT

  • A different way of matrix-vector multiplication

  • For matrix-vector multiplication, OpenGL uses the column vectors and the vector-on-the-right representation. In contrast, Direct3D uses the row vectors and the vector-on-the-left representation.

(AB)T = BTAT

Introduction to Computer Graphics with OpenGL ES (J. Han)

4 of 17

Matrices and Vectors (cont’d)

2-4

  • Identity matrix denoted by I

  • For any matrix M, MI = IM = M.

  • If two square matrices A and B are multiplied to return an identity matrix, i.e., AB = I, B is called the inverse of A and is denoted by A-1. By the same token, A is the inverse of B.
  • Theorems
    • (AB)-1 = B-1A-1 🡨
    • (AB)T = BTAT (Revisit Mv and vTMT presented in the previous page.)

Introduction to Computer Graphics with OpenGL ES (J. Han)

5 of 17

Matrices and Vectors (cont’d)

2-5

  • Consider the coordinates of a 2D or 3D vector, v:

  • Its length denoted by ||v||

  • Dividing a vector by its length is called normalization.

  • Such a normalized vector is called the unit vector since its length is 1.

Introduction to Computer Graphics with OpenGL ES (J. Han)

6 of 17

Coordinate System and Basis

2-6

  • Coordinate system = origin + basis. Throughout this book, we use two terms, coordinate system and space, interchangeably.
  • An orthonormal basis is an orthogonal set of unit vectors. The representative is the standard basis, {e1, e2}.
  • In the 2D space, every vector can be defined as a linear combination of basis vectors. Consider (3,5) for the following three examples.

standard

(orthonormal)

non-standard

non-orthonormal

non-standard

orthonormal

Introduction to Computer Graphics with OpenGL ES (J. Han)

7 of 17

Coordinate System and Basis (cont’d)

2-7

  • 3D standard basis, {e1, e2, e3}, where e1=(1,0,0), e2=(0,1,0), and e3=(0,0,1).

  • It is also orthonormal.
  • Of course, we can consider non-standard orthonormal bases in 3D space. You will see soon.

  • All 2D and 3D bases presented from now on will be orthonormal by default.

Introduction to Computer Graphics with OpenGL ES (J. Han)

8 of 17

Dot Product

2-8

  • Given two n-dimensional vectors, a and b, whose coordinates are (a1, a2, .. , an) and (b1, b2, .. , bn), respectively, their dot product ab is defined to be a1b1+a2b2+ .. +anbn. It is also called inner product.
  • Geometric interpretation of the algebraic formula: When the angle between a and b is denoted as θ, ab can be also defined as ‖a‖‖b‖cosθ.
    • If a and b are perpendicular to each other, ab = 0.
    • If θ is an acute angle, ab > 0.
    • If θ is an obtuse angle, ab < 0.

  • The smaller θ is, i.e., the more similar a and b are, the larger ab is.

Introduction to Computer Graphics with OpenGL ES (J. Han)

9 of 17

Dot Product (cont’d)

2-9

  • Note that if v is a unit vector, v·v = 1.
  • Every orthonormal basis has an interesting and useful feature. See two examples.
    • 2D standard basis, {e1, e2}
      • e1·e1=1 and e2·e2=1
      • e1·e2=0 and e2·e1=0.

    • 3D standard basis, {e1, e2, e3}
      • If i=j, ei·ej=1.
      • Otherwise, ei·ej=0.

  • This feature applies to non-standard orthonormal bases.

Introduction to Computer Graphics with OpenGL ES (J. Han)

10 of 17

Cross Product

2-10

  • The cross product takes as input two 3D vectors, a and b, and returns another 3D vector which is perpendicular to both a and b. It’s denoted by a×b and its direction is defined by the right-hand rule.

  • The length of a×b equals the area of the parallelogram that a and b span: ‖a‖‖b‖sinθ.
  • If a=b, a×b returns the zero vector, often denoted as 0.
  • The right-hand rule implies that the direction of b×a is opposite to that of a×b, i.e., b×a = -a×b, but their lengths are the same.

Introduction to Computer Graphics with OpenGL ES (J. Han)

11 of 17

Cross Product (cont’d)

2-11

  • In the book, [Note: Derivation of cross product] shows how the coordinates of a×b are derived from those of a and b. See below for an intuitive derivation.
  • If a=(ax, ay, az) and b=(bx, by, bz), a×b=(aybz-azby, azbx-axbz, axby-aybx).

Introduction to Computer Graphics with OpenGL ES (J. Han)

12 of 17

Line, Ray and Line Segment

2-12

  • An infinite line is defined by two end points, p0 and p1: p(t) = p0 + t(p1 - p0). In this parametric equation, p1 - p0 is a vector and the parameter t is in [-∞,∞] so that the vector, p1 - p0, is scaled by t.

  • If [0,∞], p(t) is a ray, which starts from p0 and is infinitely extended along p1 - p0 .
  • If [0,1], p(t) represents a line segment.

Introduction to Computer Graphics with OpenGL ES (J. Han)

13 of 17

Linear Interpolation

2-13

  • Note that p(t) = p0 + t(p1 - p0) = (1-t)p0 + tp1.

    • Conceptually, p(t) divides the line segment into two parts.
    • p(t) is the weighted sum of p0 and p1, where t is the weight of p1, which is located “on the opposite side.” Similarly, 1-t is the weight of p0, which is also located “on the opposite side.”
    • Conceptually, each weight pushes p(t) toward the vertex associated with it. For example, t pushes p(t) toward p1; the larger t is, the closer p(t) is to p1. Similarly, the larger 1-t is, the closer p(t) is to p0.
    • The sum of weights is one, i.e., t + (1-t) = 1.
  • If t is in [0,1], p(t) defined as (1-t)p0 + tp1 is called the linear interpolation of p0 and p1.

Introduction to Computer Graphics with OpenGL ES (J. Han)

14 of 17

Linear Interpolation (cont’d)

2-14

  • The x-, y- and z-coordinates of p(t) are defined independently by linear interpolation.

  • Whatever attributes are associated with the end points, they can be linearly interpolated. Suppose that the endpoints are associated with colors c0 and c1, respectively, where c0 = (R0, G0, B0) and c1 = (R1, G1, B1). Then, the color c(t) is defined as follows:

c0 = (255, 0, 0)

🡨 c1 = (0, 0, 255)

🡨

 

 

Introduction to Computer Graphics with OpenGL ES (J. Han)

15 of 17

Barycentric Coordinates

2-15

 

 

 

 

 

p

 

u

v

w

 

 

 

 

 

Introduction to Computer Graphics with OpenGL ES (J. Han)

16 of 17

Barycentric Coordinates (cont’d)

2-16

 

 

 

 

 

u

v

w

u

v

w

u

v

w

v

w

 

 

 

 

 

 

 

 

 

 

 

 

p

u

v

w

 

 

 

 

p

p

p

p

Introduction to Computer Graphics with OpenGL ES (J. Han)

17 of 17

Barycentric Coordinates (cont’d)

2-17

 

p

 

u

v

w

 

 

 

p

u

v

w

 

 

 

 

Introduction to Computer Graphics with OpenGL ES (J. Han)