Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part I
2 Topics l Why Vectors? l Vector 101 l Coordinate Systems l Inner Product l Cross Product
3 Why Vectors? l Solving geometric problems easily l Describing objects in computer graphics l Projection l Ray Tracing l Representing coordinate system l Etc…
4 Sample Vector Problems
5 Vector 101 l Definition zAn object that has length and direction l BUT, no inherent location l Displacement in space, force, velocity l Representation z2D: (x, y) z3D: (x, y, z) : zmD: (a 1, a 2, …, a m )
6 Vector 101 l Representation of vector and point zVector: boldface lowercase letter, e.g., v, a, n zPoint: Italic uppercase letter, e.g., A, B, P l Example zP = (1, 3) and Q = (4, 1), then vector v = Q – P = (4-1, 1-3) = (3, -2) y x P Q v v v
7 Basic Operations If a=(a x, a y ) and b=(b x, b y ) are vectors l Addition za + b = (a x + b x, a y + b y ) b a a+ba+b Displacement RuleParallelogram Rule b a a+ba+b
8 Basic Operations l Scaling zs a = (s a x, s a y ), where s is a scalar l Subtraction za - b = a + (- b) = (a x - b x, a y - b y ) b a a - b b a -b-b a -a-a 1.2 a
9 Linear Combination l Definition zThe linear combination of m vectors v 1, v 2, …, v m is a vector of the form w = a 1 v 1 + a 2 v 2 + … + a m v m, where a 1, a 2, …, a m are scalars l Affine combination zIf a 1 + a 2 + … + a m = 1 zE.g., 3a + 2b – 4c ? 3a + b – 4c ? zFor two vectors a and b, affine combination v = (1 – t) a + t b
10 Linear Combination l Convex combination zIf a 1 + a 2 + … + a m = 1 AND a i 0, for i = 1, …, m zIt implies that 1 a i 0, for i = 1, …, m (why?) zE.g.,.3a +.7b ? 1.8a -.8b ?
11 Set of Convex Combination l Of two vectors v 1 and v 2 : v = (1 - a)v 1 + a v 2 v = v 1 + a (v 2 - v 1 ) As a varies from 0 to 1, v “moves” from v 1 to v 2 along (v 2 - v 1 ) v1v1 v2v2 v a ( v 2 - v 1 )
12 Set of Convex Combination l Of three vectors v 1,v 2, and v 3 : v = a 1 v 1 + a 2 v 2 + (1 - a 1 - a 2 )v 3 v1v1 v2v2 v v3v3
13 Magnitude of Vectors l Magnitude (length, or size) of vector w = (w 1, w 2, …, w m ), denoted |w|, |w| = l E.g., w = (4, -2), |w| = ? w = (1, -3, 2), |w| = ? l If w = B – A, |w| = distance between points A and B
14 Unit Vector l Vector with unity length l Given a vector v, a unit vector having the same direction of v, denoted, can be obtained by normalization, (Are you sure | | = 1?)
15 Coordinate Systems l 2D l Right-handed 3D l Left-handed 3D Right-handed x z y x z y Left-handed
16 Coordinate Systems l Standard unit vectors in 3D z i = (1, 0, 0), j = (0, 1, 0), and k = (0, 0, 1) l Any 3D vector (a, b, c) can be represented by a i + b j + c k Right-handed x z y x z y Left-handed i j k i j k
17 Dot Product l Inner product l Definition v = (v 1, v 2, …, v m ) and w = (w 1, w 2, …, w m ), the dot product d = v w l E.g., a = (3, 4), b = (1, 6) d = a b = 3x1 + 4x6 = 27 l Result of dot product is a scalar
18 Properties of Dot Product l Symmetry: a b = b a l Linearity: (a + c) b = a b + c b l Homogeneity: (s a) b = s (a b) l |b| 2 = b b, i.e., |b| = b b
19 Angle Between Two Vectors l Let = c - b, = ? b = (|b|cos b, |b|sin b ) c = (|c|cos c, |c|sin c ) b c = |b|cos b x |c|cos c + |b|sin b x |c|sin c = |b||c|(cos b x cos c + sin b x sin c ) = |b||c|(cos( b - c )) = |b||c|(cos ) cos = cos is the dot product of the normalized vectors b c bb cc
20 Angle Between Two Vectors l 0 l = 90 o, if b c = 0 l > 90 o, if b c < 0 l Definition Vectors b and c are perpendicular (orthogonal, or normal) if b c = 0
21 2D Perpendicular Vector l Definition Let a = (a x, a y ) then a = (-a y, a x ) is the counterclockwise perpendicular to a l a a = 0 ?? l |a| = |a | ?? l Perpendicular of a 3D vector? l Examples a aa -a-a a aa
22 Vector Resolution l A vector can be resolved into 2 vectors l We are interested in resolving into 2 perpendicular vectors zGiven a vector c and a vector v, we want to resolve c into two vectors Kv and Mv zM=? K=? v MvMv vv c KvKv c = Kv + Mv
23 Vector Resolution l c = Kv + Mv c v = Kv v + Mv v = Kv v c v = Kv v + Mv v = Mv v
24 Distance from Point to Line l Distance d from point C to line through point A in direction v = ? l Example: zC=(6,4) and line through (1,1) and (4,9) d = ? v MvMv vv c KvKv C A
25 Orthogonal Projection l Orthogonal projection of c onto v is l Example zc = (6, 4) and a =(1, 2) zthe orthogonal projection of c onto a = ? v MvMv vv c KvKv C A
26 Applications of Projection - Reflection l Reflection zr = ? zm + e = a e + (-m) = r 2m = a - r r = a - 2m n (known) a (known) r (unknown) r n a m -m-m ee
27 Reflection l m is the orthogonal projection of a onto n l Example za = (4, -2), n = (0, 3) r = ? r n a m -m-m ee
28 Cross Product l Defined for 3D vectors l Definition a = (a x, a y, a z ), b = (b x, b y, b z ), the cross product of a and b is a b = (a y b z - a z b y ) i + (a z b x - a x b z ) j + (a x b y - a y b x ) k or ijk a b = a x a y a z (determinant) b x b y b z
29 Properties of Cross Product l i j = k l j k = i l k i = j l a b = - a b l a (b + c) = a b + a c l (s a) b = s (a b) l Why is it useful? zGiven two 3D vectors, find a 3D vector perpendicular to them
30 Geometrical Interpretation of Cross Product l a b is perpendicular to both a and b l |a b|=|a||b|sin , where is the angle between a and b that is less than 180 o l Area of parallelogram = |a b| a b a ba b
31 Applications of Cross Product l Finding the normal of a plane zGiven three points P 1, P 2, P 3 that are not collinear (do not lie in a in a straight line) zFind the normal n of the plane determined by P 1, P 2, P 3 l Let a = P 2 - P 1 and b = P 3 - P 1, then n = a b l Example zFind the normal to the plane passes through (1,0,2), (2,3,0), and (1,2,4) x z y P1P1 P3P3 P2P2 a b