Game Engineering: 2D

Similar documents
Basic Linear Algebra in MATLAB

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Linear Algebra 1/33

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Linear Algebra /34

Linear Equations in Linear Algebra

Matrix Operations. Linear Combination Vector Algebra Angle Between Vectors Projections and Reflections Equality of matrices, Augmented Matrix

Dot Products. K. Behrend. April 3, Abstract A short review of some basic facts on the dot product. Projections. The spectral theorem.

Chapter 2. Matrix Arithmetic. Chapter 2

Lecture 3: Matrix and Matrix Operations

Matrices. Chapter What is a Matrix? We review the basic matrix operations. An array of numbers a a 1n A = a m1...

Chapter 2 Notes, Linear Algebra 5e Lay

Topics. Vectors (column matrices): Vector addition and scalar multiplication The matrix of a linear function y Ax The elements of a matrix A : A ij

Linear Algebra Homework and Study Guide

Matrices and Linear Algebra

MATH 12 CLASS 2 NOTES, SEP Contents. 2. Dot product: determining the angle between two vectors 2

Math 54 Homework 3 Solutions 9/

(arrows denote positive direction)

Lecture 3 Linear Algebra Background

Matrices and Vectors

1 Matrices and matrix algebra

Elementary maths for GMT

Stat 206: Linear algebra

Vector Geometry. Chapter 5

Final Review Sheet. B = (1, 1 + 3x, 1 + x 2 ) then 2 + 3x + 6x 2

Lecture 3: Linear Algebra Review, Part II

4.1 Distance and Length

CS 246 Review of Linear Algebra 01/17/19

Linear Algebra V = T = ( 4 3 ).

Vectors and Matrices Statistics with Vectors and Matrices

ICS 6N Computational Linear Algebra Matrix Algebra

Inverses and Elementary Matrices

[ Here 21 is the dot product of (3, 1, 2, 5) with (2, 3, 1, 2), and 31 is the dot product of

Phys 201. Matrices and Determinants

2.1 Matrices. 3 5 Solve for the variables in the following matrix equation.

Linear Algebra. 1.1 Introduction to vectors 1.2 Lengths and dot products. January 28th, 2013 Math 301. Monday, January 28, 13

Review: Linear and Vector Algebra

CS 143 Linear Algebra Review

4 Linear Algebra Review

Finite Mathematics Chapter 2. where a, b, c, d, h, and k are real numbers and neither a and b nor c and d are both zero.

(c)

Essential Mathematics for Computer Graphics

Introduction to Matrix Algebra

Orthogonality. Orthonormal Bases, Orthogonal Matrices. Orthogonality

Linear Algebra Section 2.6 : LU Decomposition Section 2.7 : Permutations and transposes Wednesday, February 13th Math 301 Week #4

Solutions to Exam I MATH 304, section 6

MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra

Math for ML: review. ML and knowledge of other fields

STEP Support Programme. STEP 2 Matrices Topic Notes

MATH 221: SOLUTIONS TO SELECTED HOMEWORK PROBLEMS

3 a 21 a a 2N. 3 a 21 a a 2M

Basic Math Review for CS4830

Matrix Multiplication

MAT2342 : Introduction to Applied Linear Algebra Mike Newman, fall Projections. introduction

10. Linear Systems of ODEs, Matrix multiplication, superposition principle (parts of sections )

Matrix Algebra 2.1 MATRIX OPERATIONS Pearson Education, Inc.

Matrices Gaussian elimination Determinants. Graphics 2009/2010, period 1. Lecture 4: matrices

Math Linear Algebra Final Exam Review Sheet

x + 2y + 3z = 8 x + 3y = 7 x + 2z = 3

Mon Feb Matrix algebra and matrix inverses. Announcements: Warm-up Exercise:

n n matrices The system of m linear equations in n variables x 1, x 2,..., x n can be written as a matrix equation by Ax = b, or in full

Math 344 Lecture # Linear Systems

Math 51, Homework-2. Section numbers are from the course textbook.

The geometry of least squares

UMA Putnam Talk LINEAR ALGEBRA TRICKS FOR THE PUTNAM

Chapter 12 Review Vector. MATH 126 (Section 9.5) Vector and Scalar The University of Kansas 1 / 30

Review of Basic Concepts in Linear Algebra

Vectors and Matrices

A = 3 B = A 1 1 matrix is the same as a number or scalar, 3 = [3].

Math for ML: review. CS 1675 Introduction to ML. Administration. Lecture 2. Milos Hauskrecht 5329 Sennott Square, x4-8845

Mathematics for Graphics and Vision

Announcements Monday, October 02

Review Solutions for Exam 1

Announcements Wednesday, October 10

Knowledge Discovery and Data Mining 1 (VO) ( )

A VERY BRIEF LINEAR ALGEBRA REVIEW for MAP 5485 Introduction to Mathematical Biophysics Fall 2010

1 GSW Sets of Systems

4.4 Energy in multiple dimensions, dot product

A primer on matrices

Omm Al-Qura University Dr. Abdulsalam Ai LECTURE OUTLINE CHAPTER 3. Vectors in Physics

CS100: DISCRETE STRUCTURES. Lecture 3 Matrices Ch 3 Pages:

Review of Coordinate Systems

IMPORTANT DEFINITIONS AND THEOREMS REFERENCE SHEET

Worksheet 3: Matrix-Vector Products ( 1.3)

MAC Module 5 Vectors in 2-Space and 3-Space II

Math 54 HW 4 solutions

Information About Ellipses

Give a geometric description of the set of points in space whose coordinates satisfy the given pair of equations.

x 1 x 2. x 1, x 2,..., x n R. x n

Matrix Arithmetic. (Multidimensional Math) Institute for Advanced Analytics. Shaina Race, PhD

MATH 20F: LINEAR ALGEBRA LECTURE B00 (T. KEMP)

Chapter 2. Ma 322 Fall Ma 322. Sept 23-27

1 Last time: determinants

22A-2 SUMMER 2014 LECTURE Agenda

MATRICES The numbers or letters in any given matrix are called its entries or elements

Vectors and Matrices Lecture 2

Answers in blue. If you have questions or spot an error, let me know. 1. Find all matrices that commute with A =. 4 3

Basic Math Matrices & Transformations

University of Sheffield. PHY120 - Vectors. Dr Emiliano Cancellieri

Chapter 5: Matrices. Daniel Chan. Semester UNSW. Daniel Chan (UNSW) Chapter 5: Matrices Semester / 33

Math 360 Linear Algebra Fall Class Notes. a a a a a a. a a a

Extra Problems for Math 2050 Linear Algebra I

Transcription:

Game Engineering: 2D CS420-2010F-06 2D Math David Galles Department of Computer Science University of San Francisco

06-0: Back to Basics A Vector is a displacement Vector has both direction and length Can also think of a vector as a position (really a displacement from the origin) Can be written as a row or column vector Differnence can be important for multiplication

06-1: Vector Operations Multiplying by a scalar To multiply a vector v by a scalar s, multiply each component of the vector by s Effect is scaling the vector multiplying by 2 maintains the direction of the vector, but makes the length twice as long

06-2: Vector Operations Multiplying by a scalar Multiplying a vector by -1 flips the direction of the vector Multiplying a vector by -2 both flips the direction, and scales the vector

06-3: Scaling a Vector V 2V -V (1/2)V

06-4: Length Vector has both direction and length Length Direction

06-5: Length Vector v = [v x,v y ] Length of v: v = v 2 x + v 2 y 2 2 a + b b a

06-6: Normalizing a Vector Normalize a vector by setting its length to 1, but maintining its direction. Multiply by 1/length v norm = v v Of course, v can t be the zero vector Zero vector is the only vector without a direction

06-7: Vector Addition Add two vectors by adding their components [u x,u y ] + [v x,v y ] = [u x + v x,u y + v y ] v2 v1+v2 v2 v1 v1

06-8: Vector Subtraction Vector subtraction is the same as multiplying by -1 and adding v 1 v 2 is the displacement from the point at v 2 to the point at v 1 not the displacement from v 1 to v 2

06-9: Vector Subtraction v2 v1 v1 v1-v2 -v2 v2 v1-v2 v1

06-10: Point Distance We can use subtraction and length to find the distance between two points Represent points as vectors displacement from the origin Distance from v to u is v u = u v Where v is the length of the vector v.

06-11: Point Distance Point p 1 : [1, 7] Point p 2 : [4, 3] Distance between p 1 and p 2?

06-12: Point Distance p 1 p 2 = [1, 7] Point p 2 : [4, 3] Distance between p 1 and p 2 [1, 7] [4, 3] = [ 3, 4] ( 3)2 + 4 2 = 5

06-13: Dot Product a = [a x,a y ] b = [b x,b y ] a b = a x b x + a y b y

06-14: Dot Product a b = a b cosθ a θ b

06-15: Dot Product θ = arccos If a and b are unit vectors: ( ) a b a b θ = arccos (a b)

06-16: Dot Product If we don t need the exact angle, we can just use the sign If θ < 90, cosθ > 0 If θ = 90, cosθ = 0 If 90 < θ < 180, cos θ < 0 Since a b = a b cosθ: If a b > 0, θ < 90( π 2 ) If a b = 0, θ = 90( π) 2 If a b < 0, 90 < θ < 180 π < θ < π 2

06-17: Projecting Vectors v n

06-18: Projecting Vectors v n

06-19: Projecting Vectors v v proj

06-20: Projecting Vectors v Θ cos Θ = length of projection v length of projection

06-21: Projecting Vectors Given a vector v, and a unit vector n, find the projection of v onto n length of projection l: cos θ = l v l = cos θ v = cos θ v n = v n Since n is a unit vector, projection = length * n (v n) n

06-22: Projecting Vectors Given vectors v and n, we want to decompose v into two vectors, v and v v is parallel to n v is perpendicular to n v = v + v

06-23: Projecting Vectors v v n n v v v

06-24: Projecting Vectors v is just the projection of v onto n v = (v n) n (if n is not a unit vector, then we will need to normalize) n v = (v n ) = v n n 2n n n

06-25: Projecting Vectors Once we have v, finding v is easy, since v = v + v v + v v v = v = v v = v n v n n 2

06-26: Projecting Vectors Sanity Check: What happens if we try to find the componets of the vector [v 1,v 2 ] that are parallel and perpendicular to the x-axis and y-axis what should we get?

06-27: Projecting Vectors Sanity Check: What happens if we try to find the componets of the vector [v x,v y ] that are parallel and perpendicular to the x-axis and y-axis what should we get? [v x, 0] and [0,v y ] Let s make sure that s what we get! Start with the component parallel to x-axis

06-28: Projecting Vectors Component of [v x,v y ] that is parallel to the x-axis: Length of component parallel to x-axis: v n = [v x,v y ] [1, 0] = v x 1 + v y 0 = v x Component parallel to x-axis: (v n) n = v x [1, 0] = [v x, 0]

06-29: Projecting Vectors Component of [v x,v y ] that is perpendicular to the x-axis: v = v v v = [v x,v y ] [v x, 0] v = [0,v y ]

06-30: Matrices A 2x2 matrix M: M = [ m11 m 12 m 21 m 22 ]

06-31: Matrices A diagonal matrix is a square matrix with non-diagonal elements equal to zero M = [ m11 0 0 m 22 ]

06-32: Matrices The Identity Matrix is a diagonal matrix with all diagonal elements = 1 I 3 = 1 0 0 0 1 0 0 0 1

06-33: Matrices Matrices and vectors Vectors are a special case of matrices Row vectors (as we ve seen so far) [x,y] [ ] x Column vectors : y

06-34: Matrices Transpose Written M T Exchange rows and colums [ a b c d ] T = [ a c b d ]

06-35: Transpose The transpose of a row vector is a column vector For any matrix M, (M T ) T = M For a diagonal matrix D, D T =?

06-36: Matrix Multiplication Multiplying a Matrix by a scalar Multiply each element in the Matrix by the scalar Just like multiplying a vector by a scalar km = k [ m11 m 12 m 21 m 22 ] = [ km11 km 12 km 21 km 22 ]

06-37: Matrix Multiplication a a 11 12 b b 11 12 c c 11 12 a a 21 22 b b 21 22 = c c 21 22

06-38: Matrix Multiplication a a 11 12 b b 11 12 c c 11 12 a a 21 22 b b 21 22 = c c 21 22 c a 11 = b + a b 11 11 12 21

06-39: Matrix Multiplication a a 11 12 b b 11 12 c c 11 12 a a 21 22 b b 21 22 = c c 21 22 c a 21 = b + a b 21 11 22 21

06-40: Matrix Multiplication a a 11 12 b b 11 12 c c 11 12 a a 21 22 b b 21 22 = c c 21 22 c a 12 = b + a b 11 12 12 22

06-41: Matrix Multiplication a a 11 12 b b 11 12 c c 11 12 a a 21 22 b b 21 22 = c c 21 22 c a 22 = b + a b 21 12 22 22

06-42: Matrix Multiplication Vectors are special cases of matrices Multiplying a vector and a matrix is just like multiplying two matrices h x y i 2 4 m 11 m 12 m 21 m 22 3 5 = h xm 11 + ym 21 xm 12 + ym 22 i

06-43: Matrix Multiplication Vectors are special cases of matrices Multiplying a vector and a matrix is just like multiplying two matrices 2 3 2 3 2 3 4 m 11 m 12 m 21 m 22 5 4 x y 5 = 4 xm 11 + ym 12 xm 21 + ym 22 5

06-44: Matrix Multiplication Note that the following multiplications are not legal: 2 4 x y 3 2 5 4 m 11 m 12 m 21 m 22 3 5 2 4 m 11 m 12 m 21 m 22 3 5 h x y i

06-45: Matrix Multiplication Matrix Multiplicaton is not commutative: AB BA (at least not for all A and B is it true for at least one A and B?) Matrix Multiplication is associative: (AB)C = A(BC) Transposing product is the same as the product of the transpose, in reverse order: (AB) T = B T A T 2 4 m 11 m 12 m 21 m 22 3 2 5 4 x y 3 5 h x y i 2 4 m 11 m 12 m 21 m 22 3 5

06-46: Matrix Multiplication Identity Matrix I: AI = A (for appropriate I) IA = A (for appropriate I) 2 4 m 11 m 21 m 12 m 22 3 2 5 4 1 0 0 1 3 5 2 4 1 0 0 1 3 2 5 4 m 11 m 21 m 12 m 22 3 5

06-47: Matrix Multiplication Identity Matrix I: AI = A (for appropriate I) IA = A (for appropriate I) h x y i 2 4 1 0 0 1 3 5 = h x y i

06-48: Matrix Multiplication Identity Matrix I: AI = A (for appropriate I) IA = A (for appropriate I) 2 4 1 0 0 1 3 2 5 4 x y 3 5 = 2 4 x y 3 5

06-49: Row vs. Column Vectors A vector can be reresented as a row vector or a column vector This makes a difference when using matrices Row: va, Column Av It gets even more fun when using matrices to do several transformations of a vector: Row vabc, Column CBAv (note that to get the same transformation, you need to take the transpose of A, B, and C when swapping between row and column vectors

06-50: Row vs. Column Vectors h x y i 2 4 a c b d 3 2 5 4 e f g h 3 5 = h xa + yc xb + yd i 2 4 e g f h 3 5 = h (xa + yc)e + (xb + yd)g (xa + yc)f + (xb + yd)h i 2 4 e g f h 3 2 5 4 a c b d 3 2 5 4 x y 3 5 = 2 4 e f g h 3 2 5 4 ax + cy bx + dy 3 5 = 2 4 e(ax + cy) + g(ax + cy) f(ax + cy) + h(ax + yd) 3 5