Vector and Affine Math Don Fussell Computer Science Department The University of Texas at Austin University of Texas at Austin CS354 - Computer Graphics Don Fussell Vectors A vector is a direction and a magnitude Does NOT includeVectors a point of reference Usually thought of as an arrow in space Vectors can be added together and multiplied by scalars Zero vector has no length or direction University of Texas at Austin CS354 - Computer Graphics Don Fussell Vector Spaces Set of vectors Closed under the following operations Vector addition: v1 + v2 = v3 Scalar multiplication: s v1 = v2 n a v v Linear combinations: ∑ i i = i=1 Scalars come from some field F e.g. real or complex numbers Linear independence Basis Dimension University of Texas at Austin CS354 - Computer Graphics Don Fussell Vector Space Axioms Vector addition is associative and commutative Vector addition has a (unique) identity element (the 0 vector) Each vector has an additive inverse So we can define vector subtraction as adding an inverse Scalar multiplication has an identity element (1) Scalar multiplication distributes over vector addition and field addition Multiplications are compatible (a(bv)=(ab)v) University of Texas at Austin CS354 - Computer Graphics Don Fussell Coordinate Representation Pick a basis, order the vectors in it, then all vectors in the space can be represented as sequences of coordinates, i.e. coefficients of the basis vectors, in order. Example: Cartesian 3-space Basis: [i j k] Linear combination: xi + yj + zk Coordinate representation: [x y z] a[x1 y1 z1]+ b[x2 y2 z2 ] = [ax1 + bx2 ay1 + by2 az1 + bz2 ] University of Texas at Austin CS354 - Computer Graphics Don Fussell Row and Column Vectors We can represent a vector, v = (x,y), in the plane as a column vector " x% $ ' # y& as a row vector x y € [ ] University€ of Texas at Austin CS354 - Computer Graphics Don Fussell Linear Transformations Given vector spaces V and W A function f : V → W is a linear map or linear transformation if f (a1v1 +... + amvm ) = a1 f (v1)+... + am f (vm ) University of Texas at Austin CS354 - Computer Graphics Don Fussell Transformation Representation We can represent a 2-D transformation M by a matrix "a b% M = $ ' #c d& If v is a column vector, M goes on the left: v' = Mv " x! % " a b %" x % € $ ' = $ '$ ' #$ y! &' # c d &#$ y &' If v is a row vector, MT goes on the right: v' = vMT " $ " $ " $ a c # x! y! % = # x y %& ' # b d % We will use column vectors. University of Texas at Austin CS354 - Computer Graphics Don Fussell Two-dimensional transformations Here's all you get with a 2 x 2 transformation matrix M: # x "& #a b& # x& % ( = % ( % ( $ y "' $c d' $ y' So: x " = ax + by € y " = cx + dy We will develop some intimacy with the elements a, b, c, d… € University of Texas at Austin CS354 - Computer Graphics Don Fussell Identity Suppose we choose a=d=1, b=c=0: Gives the identity matrix: "1 0% $ ' #0 1& Doesn't€ change anything University of Texas at Austin CS354 - Computer Graphics Don Fussell Scaling Suppose b=c=0, but let a and d take on any positive value: Gives a scaling matrix: "a 0% $ ' #0 d& Provides differential (non-uniform) scaling in x and y: y y € "2 0% x " = ax 2 2 $ ' #0 2& 1 1 y " = dy x x 12 12 y € "1 2 0% $ ' 2 # 0 2& 1 € x 12 University of Texas €at Austin CS354 - Computer Graphics Don Fussell Reflection Suppose b=c=0, but let either a or d go negative. Examples: y y x x y y #− 1 0& #1 0 & % ( % ( $ 0 1' x x $0 −1' € € University of Texas at Austin CS354 - Computer Graphics Don Fussell Shear Now leave a=d=1 and experiment with b The matrix "1 b% $ ' #0 1& gives: x " = x + by € y " = y y y "1 1% $ ' € 1 1 #0 1& x x 1 1 University of Texas at Austin CS354 - Computer€ Graphics Don Fussell Effect on unit square Let's see how a general 2 x 2 transformation M affects the unit square: "a b% $ ' [p q r s] = [p( q( r ( s( ] #c d& "a b% "0 1 1 0% "0 a a + b b% $ ' $ ' = $ ' #c d& #0 0 1 1& #0 c c + d d& y y € s r 1 p q x x 1 University of Texas at Austin CS354 - Computer Graphics Don Fussell Effect on unit square, cont. Observe: Origin invariant under M M can be determined just by knowing how the corners (1,0) and (0,1) are mapped a and d give x- and y-scaling b and c give x- and y-shearing University of Texas at Austin CS354 - Computer Graphics Don Fussell Rotation From our observations of the effect on the unit square, it should be easy to write down a matrix for “rotation about the origin”: y y "1 % "cos( θ)% $ ' → $ ' #0 & # sin(θ)& 1 "0 % "− sin(θ)% → $ ' $ ' x x #1 & # cos(θ) & 1 Thus $cos( € θ) −sin(θ)' MR = R(θ) = & ) % sin(θ) cos(θ) ( University of Texas at Austin CS354 - Computer Graphics Don Fussell € Linear transformations The unit square observations also tell us the 2x2 matrix transformation implies that we are representing a vector in a new coordinate system: v' = Mv ! a b $! x $ = # &# & " c d %"# y %& ! x $ = ! u w $# & " % "# y %& = x ⋅ u + y⋅ w where u=[a c]T and w=[b d]T are vectors that define a new basis for a linear space. The transformation to this new basis (a.k.a., change of basis) is a linear transformation. University of Texas at Austin CS354 - Computer Graphics Don Fussell Limitations of the 2 x 2 matrix A 2 x 2 linear transformation matrix allows Scaling Rotation Reflection Shearing Q: What important operation does that leave out? University of Texas at Austin CS354 - Computer Graphics Don Fussell Points A point is a location in space Cannot be added or multiplied together Subtract two points to get Pointsthe vector between them Points are not vectors •UniversityA point of Texas atis Austin a location CS354 - Computer in Graphics space Don Fussell • Cannot be added or multiplied together • Subtract two points to get the vector between them Affine transformations In order to incorporate the idea that both the basis and the origin can change, we augment the linear space u, w with an origin t. Note that while u and w are basis vectors, the origin t is a point. We call u, w, and t (basis and origin) a frame for an affine space. Then, we can represent a change of frame as: p! = x ⋅ u + y⋅ w + t This change of frame is also known as an affine transformation. How do we write an affine transformation with matrices? University of Texas at Austin CS354 - Computer Graphics Don Fussell Basic Vector Arithmetic ! r $ ! x $ ! r + x $ ! ax $ # & # & # & # & u = # s & v = # y & u + v = # s + y & av = # ay & # & # & # & # & " t % " z % " t + z % " az % v v = x2 + y2 + z2 norm(v) = v University of Texas at Austin CS354 - Computer Graphics Don Fussell Parametric line segment Or line, or ray, or just linear interpolation p = p0 + t(p1 − p0 ) = (1− t)p0 + tp1 ! $ ! $ ! $ ! x $ x0 x1 − x0 (1− t)x0 + tx1 # & # & # & # & # y & = # y0 &+ t# y1 − y0 & = # (1− t)y0 + ty1 & # & # & # & # z & z z z (1 t)z tz " % "# 0 %& "# 1 − 0 %& "# − 0 + 1 %& Line segment 0 ≤ t ≤1 Ray 0 ≤ t ≤ ∞ Line −∞ ≤ t ≤ ∞ University of Texas at Austin CS354 - Computer Graphics Don Fussell VectorDot dot product product u⋅ v = rx + sy + tz = u v cos(φ) • Formula: • Alternately: University of Texas at Austin CS354 - Computer Graphics Don Fussell • Where φ is the angle between the vectors ProjectionProjection / rejection u⋅ v Projection (u component parallel to v) w = v v ⋅ v • Projection: Rejection (u component orthogonal to v) u − w • W isParticularly the part useful of U when that vectors lies areon normalized V University of Texas at Austin CS354 - Computer Graphics Don Fussell • Rejection: Just U - W Cross product • Formula: Cross product • Creates a vector that is: i j k # sz − ty & • Perpendicular to the inputs% ( w = u × v = r s t = % tx − rz ( x y z % ry − sx ( • Length Cross$ product' intuition w is orthogonal to u and v • Right-hand w oriented= u v sin(φ) w area of parallelogram use right-hand rule u × v = −(v × u) (u × v)× w ≠ u ×(v × w) University of Texas at Austin CS354 - Computer Graphics Don Fussell • If U & V point along the same line, W = 0 • Useful for constructing local coordinate frames • Length of cross product is area of parallelogram spanned by U and V (divide by 2 for area of the triangle) Determinants a b = ad − bc c d a b c e f d f d e d e f = a − b + c = aei − afh + bfg − bdi + cdh − ceg h i g i g h g h i det(MT) = det(M) det(AB) = det(A)det(B) if det(M) = 0, M is singular, has no inverse University of Texas at Austin CS354 - Computer Graphics Don Fussell Plane equation Given normal vector N orthogonal to the plane and any point p in the plane N⋅ p + d = 0 ! x # ! #% & " a b c $% y Triangle&+ d = ax + by + cz + d =normals0 % & " z $ For a triangle N = norm((v1 − v0 )×(v2 − v0 )) Order matters, usually CCW University of Texas• atEvery Austin CS354 triangle - Computer lies Graphics in a Don plane Fussell • 2 choices of normal, pick one by convention • CCW winding is usually used • Formula: Homogeneous Coordinates To represent transformations among affine frames, we can loft the problem up into 3-space, adding a third component to every point: p! = Mp " % a b tx " x % $ '$ ' = $ c d ty '$ y ' $ '$ 1 ' #$ 0 0 1 &'# & " % x " %$ ' = # u w t &$ y ' $ 1 ' # & = x ⋅ u + y⋅ w +1⋅ t Note that [a c 0]T and [b d 0]T represent vectors and T T T [tx ty 1] , [x y 1] and [x' y' 1] represent points.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages43 Page
-
File Size-