Slide 1

Slide 1 text

jgs SER332 Introduction to Graphics and Game Development Lecture 13: Linear Algebra Javier Gonzalez-Sanchez [email protected] PERALTA 230U Office Hours: By appointment

Slide 2

Slide 2 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 1 jgs Announcement § Project 2 is Posted Due by March 21, 11:59PM

Slide 3

Slide 3 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 2 jgs Goal

Slide 4

Slide 4 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 3 jgs Goal

Slide 5

Slide 5 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 4 jgs Goal 3D Maze ( IJKS 1982)

Slide 6

Slide 6 text

jgs Points, Vector, Angles Linear Algebra

Slide 7

Slide 7 text

jgs Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 6 Points Specify locations in space (or in the plane) Points and Vectors Vector have a magnitude and direction (4,2) (1,3) v ⍬

Slide 8

Slide 8 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 7 jgs Vectors § Vector v = (v1 , v2 ) § Magnitude or Length ||v|| = sqrt( v1 2 + v2 2) § Orientation (angle) ⍬ = tan -1 ( v2 / v1 ) § Unit vector ||v|| = 1 § Zero vector v = (0,0)

Slide 9

Slide 9 text

jgs Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 8 u - v = (u1 ,u2 ) - (v1 ,v2 ) = (u1 -v1 , u2 -v2 ) u + v = (u1 ,u2 ) + (v1 ,v2 ) = (u1 +v1 , u2 +v2 ) Addition and Subtraction v u u+v v u v-u

Slide 10

Slide 10 text

jgs Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 9 a * v = a * (v1 ,v2 ) = (a*v1 , a*v2 ) Multiplication with a Scalar v av

Slide 11

Slide 11 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 10 jgs Test yourself § Point + Vector = ? § Point – Point = ? § Vector + Vector = ? § Point + Point = ?

Slide 12

Slide 12 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 11 jgs Test yourself § Point + Vector = Point § Point – Point = Vector § Vector + Vector = Vector § Point + Point = ? v u u-v v u v-u

Slide 13

Slide 13 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 12 jgs Angles

Slide 14

Slide 14 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 13 jgs Uses // mouse motion callback function void motion(int x, int y) { if (mouse_button == GLUT_LEFT_BUTTON) { y_angle += (float(x - mouse_x) / width) *360.0; x_angle += (float(y - mouse_y) / height)*360.0; } if (mouse_button == GLUT_RIGHT_BUTTON) { scale += (y - mouse_y) / 100.0; if (scale < 0.1) scale = 0.1; if (scale > 7) scale = 7; } mouse_x = x; mouse_y = y; glutPostRedisplay(); }

Slide 15

Slide 15 text

jgs Dot product

Slide 16

Slide 16 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 15 jgs § The dot product or inner product measures to what degree two vectors are aligned u · v = (u1 ,u2 ) · (v1 ,v2 ) = u1 * v1 + u2 * v2 v * u = (5*7) + (5*3) = 50 v * w = (5*5) + (5*0) = 25 u * w = (7*5) + (3*0) = 35 u * u = (7*7) + (3*3) = 58 t * w = (0*5) + (5*0) = 0 Dot Product q v=[5,5] u=[7,3] w=[5,0] t=[0,5]

Slide 17

Slide 17 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 16 jgs § Two vectors v and w are perpendicular or normal iff u · v = 0 § Geometric Interpretation: § cos(a) = l / ||w|| = u · v / ||v|| * ||w|| Dot Product w v a l

Slide 18

Slide 18 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 17 jgs v * u = (5*7) + (5*3) = 50 v * w = (5*5) + (5*0) = 25 u * w = (7*5) + (3*0) = 35 u * u = (7*7) + (3*3) = 58 t * w = (0*5) + (5*0) = 0 |t| = 5.0 |v| = 7.07 |u| = 7.61 |w| = 5.0 § cos(a) = u · v / ||v|| * ||w|| q = cos-1 (25 / 7.07 * 5.0) = 45º Dot Product q v=[5,5] u=[7,3] w=[5,0] t=[0,5]

Slide 19

Slide 19 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 18 jgs Dot Product ||v|| = sqrt (v · v) = sqrt (v1 * v1 + v2 * v2 )

Slide 20

Slide 20 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 19 jgs Dot Product | Uses § Calculate the angle between 2 vectors

Slide 21

Slide 21 text

jgs Cross product

Slide 22

Slide 22 text

jgs Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 21 • Notation: u = v x w • The cross product is a vector • ||u|| proportional to the sine of the angle between v and w ||u|| = ||v||*||w||*sin(a) • u is perpendicular to v and w • The direction of u follows the right hand rule Cross Product w v a u

Slide 23

Slide 23 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 22 jgs Cross Product u = v x w = ! " ! # ! $ x % " % # % $ = & ' ( ! " ! # ! $ % " % # % $ = ! # ∗ % $ − % # ∗ ! $ ! $ ∗ % " − % $ ∗ ! " ! " ∗ % # − % " ∗ ! #

Slide 24

Slide 24 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 23 jgs Cross Product | Uses § Calculate the area of a triangle § Calculate distance from a line to a dot § Calculate normals

Slide 25

Slide 25 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 24 jgs Cross Product | Triangle Area § The cross product is related to the area of a triangle § (parallelogram)area = ||u|| = ||v x w|| = ||v||*||w||*sin(a) § (triangle)area = ||u|| / 2 = ||v x w|| / 2 = ... Q R P w v

Slide 26

Slide 26 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 25 jgs Test Yourself Given a Triangle with P=(0,0,0), Q=(0,3,0) and R=(3,3,0) What is the area? Q R P

Slide 27

Slide 27 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 26 jgs Test Yourself § area (triangle) = (0,3,0) x (3,3,0) = ||(0,0,-9)|| / 2 = 9/2 = 4.5 § area (parallelogram) = 9 § area (parallelogram) = (3)(4.24) sin (45) = (3)(4.24...)(0.70...) = 9 Q R P

Slide 28

Slide 28 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 27 jgs Cross Product | Distance point to line // compute the distance from AB to C double lineToPointDistance2D (double[] pA, double[] pB, double[] pC) { double dist = cross(pA-pB, pA-pC) / (pA - pB); return Math.abs(dist); } pA pC pB

Slide 29

Slide 29 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 28 jgs Cross Product | Distance point to line

Slide 30

Slide 30 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 29 jgs Cross Product | Normal calculation (lighting)

Slide 31

Slide 31 text

jgs Matrices Linear Algebra

Slide 32

Slide 32 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 31 jgs Matrix § A matrix is a set of elements, organized into rows and columns § addition: ! " # $ + & ' ( ℎ = ! + & " + ' # + ( $ + ℎ § subtraction: ! " # $ − & ' ( ℎ = ! − & " − ' # − ( $ − ℎ § multiplication: ! " # $ − & ' ( ℎ = !& + "( !' + "ℎ #& + $( #' + $ℎ

Slide 33

Slide 33 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 32 jgs Matrix Multiplication § Cn x p = A n x m B m x p § Examples 2 5 3 1 ∗ 6 2 1 5 = 17 29 19 11 6 2 1 5 ∗ 2 5 3 1 = 18 32 17 10

Slide 34

Slide 34 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 33 jgs Usage: transformations

Slide 35

Slide 35 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 34 jgs Usage: transformations

Slide 36

Slide 36 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 35 jgs Usage: transformations

Slide 37

Slide 37 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 36 jgs Homework Review Linear Algebra

Slide 38

Slide 38 text

jgs SER332 Introduction to Graphics Javier Gonzalez-Sanchez [email protected] Spring 2018 Disclaimer. These slides can only be used as study material for the class SER332 at ASU. They cannot be distributed or used for another purpose.