Vector and Affine Math

Similar documents
Reading. 4. Affine transformations. Required: Watt, Section 1.1. Further reading:

Affine transformations

Affine transformations

Affine transformations. Brian Curless CSE 557 Fall 2014

CS 378: Computer Game Technology

CS 354R: Computer Game Technology

Reading. Affine transformations. Vector representation. Geometric transformations. x y z. x y. Required: Angel 4.1, Further reading:

Affine transformations

2D Geometric Transformations. (Chapter 5 in FVD)

CS 4300 Computer Graphics. Prof. Harriet Fell Fall 2011 Lecture 11 September 29, 2011

Computer Graphics: 2D Transformations. Course Website:

Linear and affine transformations

Chapter 8. Rigid transformations

Graphics Example: Type Setting

Some linear transformations on R 2 Math 130 Linear Algebra D Joyce, Fall 2013

Math 416, Spring 2010 More on Algebraic and Geometric Properties January 21, 2010 MORE ON ALGEBRAIC AND GEOMETRIC PROPERTIES

M. Matrices and Linear Algebra

Lecture 5. Equations of Lines and Planes. Dan Nichols MATH 233, Spring 2018 University of Massachusetts.

we must pay attention to the role of the coordinate system w.r.t. which we perform a tform

4.1 Distance and Length

CS 335 Graphics and Multimedia. 2D Graphics Primitives and Transformation

Introduction to 3D Game Programming with DirectX 9.0c: A Shader Approach

Mathematical Foundations: Intro

Introduction to Vector Spaces Linear Algebra, Spring 2011

ES.1803 Topic 16 Notes Jeremy Orloff

LESSON 35: EIGENVALUES AND EIGENVECTORS APRIL 21, (1) We might also write v as v. Both notations refer to a vector.

we must pay attention to the role of the coordinate system w.r.t. which we perform a tform

Math Linear Algebra Final Exam Review Sheet

A Primer on Solving Systems of Linear Equations

Vector Geometry. Chapter 5

Two conventions for coordinate systems. Left-Hand vs Right-Hand. x z. Which is which?

Physically Based Rendering ( ) Geometry and Transformations

( ) ( ) ( ) ( ) TNM046: Datorgrafik. Transformations. Linear Algebra. Linear Algebra. Sasan Gooran VT Transposition. Scalar (dot) product:

CSC 470 Introduction to Computer Graphics. Mathematical Foundations Part 2

(arrows denote positive direction)

Mathematics 309 Conic sections and their applicationsn. Chapter 2. Quadric figures. ai,j x i x j + b i x i + c =0. 1. Coordinate changes

Review of Coordinate Systems

COMP 175 COMPUTER GRAPHICS. Lecture 04: Transform 1. COMP 175: Computer Graphics February 9, Erik Anderson 04 Transform 1

REVISION SHEET FP2 (MEI) CALCULUS. x x 0.5. x x 1.5. π π. Standard Calculus of Inverse Trig and Hyperbolic Trig Functions = + = + arcsin x = +

Vectors and Matrices

k is a product of elementary matrices.

Lecture 5 3D polygonal modeling Part 1: Vector graphics Yong-Jin Liu.

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

Vectors and matrices: matrices (Version 2) This is a very brief summary of my lecture notes.

ENR202 Mechanics of Materials Lecture 12B Slides and Notes

CSE 167: Introduction to Computer Graphics Lecture #2: Linear Algebra Primer

15. Eigenvalues, Eigenvectors

Rigid Body Transforms-3D. J.C. Dill transforms3d 27Jan99

Lecture 8: Coordinate Frames. CITS3003 Graphics & Animation

Linear Algebra Homework and Study Guide

CSE 167: Introduction to Computer Graphics Lecture #2: Linear Algebra Primer

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

Notes on multivariable calculus

CHAPTER 4 VECTORS. Before we go any further, we must talk about vectors. They are such a useful tool for

Vectors Year 12 Term 1

Mathematics for 3D Graphics

11.4 Polar Coordinates

GEOMETRY AND VECTORS

The Force Table Introduction: Theory:

Introduction. Introduction (2) Easy Problems for Vectors 7/13/2011. Chapter 4. Vector Tools for Graphics

Section 10.7 The Cross Product

Matrices. Ellen Kulinsky

SECTION 6.3: VECTORS IN THE PLANE

18.02 Multivariable Calculus Fall 2007

Honors Advanced Mathematics Determinants page 1

Definition: A vector is a directed line segment which represents a displacement from one point P to another point Q.

Welcome to IB Math - Standard Level Year 2

Math 3108: Linear Algebra

Transformations. Chapter D Transformations Translation

IMPORTANT DEFINITIONS AND THEOREMS REFERENCE SHEET

Vector Basics, with Exercises

MATH 221: SOLUTIONS TO SELECTED HOMEWORK PROBLEMS

Eigenvectors and Eigenvalues 1

12.1 Systems of Linear equations: Substitution and Elimination

1.1 Single Variable Calculus versus Multivariable Calculus Rectangular Coordinate Systems... 4

Vectors. Vector Practice Problems: Odd-numbered problems from

CS-184: Computer Graphics. Today

14.1 Systems of Linear Equations in Two Variables

MATRIX TRANSFORMATIONS

ENGI 9420 Lecture Notes 2 - Matrix Algebra Page Matrix operations can render the solution of a linear system much more efficient.

How to rotate a vector using a rotation matrix

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Linear Algebra /34

Matrices. VCE Maths Methods - Unit 2 - Matrices

Euclidean Spaces. Euclidean Spaces. Chapter 10 -S&B

IMPORTANT DEFINITIONS AND THEOREMS REFERENCE SHEET

1 Last time: determinants

11.1 Vectors in the plane

Linear Algebra & Geometry why is linear algebra useful in computer vision?

Review Solutions for Exam 1

Demonstrate solution methods for systems of linear equations. Show that a system of equations can be represented in matrix-vector form.

Section 1.2: A Catalog of Functions

Lecture 2: Vector-Vector Operations

Solutions to Selected Questions from Denis Sevee s Vector Geometry. (Updated )

Linear Algebra & Geometry why is linear algebra useful in computer vision?

Vector Calculus Review

Unit 12 Study Notes 1 Systems of Equations

SINGLE MATHEMATICS B : Vectors Summary Notes

Linear Equations in Linear Algebra

6. Linear transformations. Consider the function. f : R 2 R 2 which sends (x, y) (x, y)

9.1 VECTORS. A Geometric View of Vectors LEARNING OBJECTIVES. = a, b

Transcription:

Vector and Affine Math Computer Science Department The Universit of Teas at Austin

Vectors A vector is a direction and a magnitude Does NOT include a point of reference Usuall thought of as an arrow in space Vectors can be added together and multiplied b scalars Zero vector has no length or direction

Vector Spaces Set of vectors Closed under the following operations Vector addition: v + v 2 = v 3 Scalar multiplication: s v = v 2 Linear combinations: Scalars come from some field F e.g. real or comple numbers Linear independence Basis Dimension n i= a i v = v i

Vector Space Aioms Vector addition is associative and commutative Vector addition has a unique) identit element the 0 vector) Each vector has an additive inverse So we can define vector subtraction as adding an inverse Scalar multiplication has an identit element ) Scalar multiplication distributes over vector addition and field addition Multiplications are compatible abv)=ab)v)

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. Eample: Cartesian 3-space Basis: [i j k] Linear combination: i + j + zk Coordinate representation: [ z] a [ z] + b[ 2 2 z2] = [ a + b2 a + b2 az + bz2]

Row and Column Vectors We can represent a vector, v =,), in the plane as a column vector as a row vector [ ]

Linear Transformations Given vector spaces V and W A function f :V W is a linear map or linear transformation if f a v +... + a m v m ) = a f v )+... + a m f v m )

Transformation Representation We can represent a 2-D transformation M b a matri M = a b c d If v is a column vector, M goes on the left: If v is a row vector, M T goes on the right: We will use column vectors.!!!! v = Mv = a b c d v = vm T = a b c d

Two-dimensional transformations Heres all ou get with a 2 2 transformation matri M: = a b c d So: = a + b = c + d We will develop some intimac with the elements a, b, c, d

Identit Suppose we choose a=d=, b=c=0: Gives the identit matri: 0 0 Doesnt change anthing

Scaling Suppose b=c=0, but let a and d take on an positive value: Gives a scaling matri: a 0 0 d 2 2 Provides differential non-uniform) scaling in and : 2 2 2 0 0 2 = a = d 2 2 2 0 0 2

Reflection Suppose b=c=0, but let either a or d go negative. Eamples: 0 0 0 0

Shear Now leave a=d= and eperiment with b The matri b 0 gives: = + b = 0

Effect on unit square Lets see how a general 2 2 transformation M affects the unit square: a c b p q r s d [ ] = [ p q r s ] a b 0 0 = 0 a a + b b c d 0 0 0 c c + d d s r p q

Effect on unit square, cont. Observe: Origin invariant under M M can be determined just b knowing how the corners,0) and 0,) are mapped a and d give - and -scaling b and c give - and -shearing

Rotation From our observations of the effect on the unit square, it should be eas to write down a matri for rotation about the origin : cosθ) 0 sinθ) 0 sinθ) cosθ) Thus M R = Rθ) = cosθ) sinθ) sinθ) ) cosθ)

Linear transformations The unit square observations also tell us the 22 matri transformation implies that we are representing a vector in a new coordinate sstem: v = Mv! = a b c d =! u 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.!! = u + w

Limitations of the 2 2 matri A 2 2 linear transformation matri allows Scaling Rotation Reflection Shearing Q: What important operation does that leave out?

Points A point is a location in space Cannot be added or multiplied together Subtract two points to get the vector between them Points are not vectors

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! = u + w + t This change of frame is also known as an affine transformation. How do we write an affine transformation with matrices?

Basic Vector Arithmetic! u = r s t! v = z! u + v = r + s + t + z! av = a a az v = 2 + 2 + z 2 normv) = v v

Parametric line segment Or line, or ra, or just linear interpolation p = p 0 + tp p 0 ) = t)p 0 + tp! z! = 0 0 z 0! + t 0 0 z z 0! = t) 0 + t t) 0 + t t)z 0 + tz Line segment Ra Line 0 t 0 t t

Vector dot product u v = r + s + tz = u v cosφ)

Projection Projection u component parallel to v) w = u v v v v Rejection u component orthogonal to v) u w Particularl useful when vectors are normalized

Cross product w = u v = i j k r s t z w is orthogonal to u and v w = u v sinφ) w area of parallelogram use right-hand rule u v = v u) = u v) w u v w) sz t t rz r s

Determinants a b c d = ad bc a b c d e f g h i = a e f h i b d f g i + c d e g h = aei afh + bfg bdi + cdh ceg detm T ) = detm) detab) = deta)detb) if detm) = 0, M is singular, has no inverse

Plane equation Given normal vector N orthogonal to the plane and an point p in the plane N p + d = 0! a b c For a triangle! N = normv 2 v 0 ) v v 0 )) Order matters, usuall CCW z + d = a + b + cz + d = 0

Homogeneous Coordinates To represent transformations among affine frames, we can loft the problem up into 3-space, adding a third component to ever point: p! = Mp = a b t c d t 0 0 = u w t = u + w + t Note that [a c 0] T and [b d 0] T represent vectors and [t t ] T, [ ] T and [ ] T represent points.

Homogeneous coordinates This allows us to perform translation as well as the linear transformations as a matri operation: p = M T p 0 t = 0 t 0 0 = + t = + t 0 0 2 0 0

Rotation about arbitrar points Until now, we have onl considered rotation about the origin. With homogeneous coordinates, ou can specif a rotation, R q, about an point q = [q q ] T with a matri: q θ. Translate q to origin 2. Rotate 3. Translate back Line up the matrices for these step in right to left order and multipl. Note: Transformation order is important!!

Points and vectors From now on, we can represent points as have an additional coordinate of w=. Vectors have an additional coordinate of w=0. Thus, a change of origin has no effect on vectors. Q: What happens if we multipl a matri b a vector? These representations reflect some of the rules of affine operations on points and vectors: vector + vector vector vector point point point + vector point + point One useful combination of affine operations is: pt) = p 0 + tv Q: What does this describe?

Barcentric coordinates A set of points can be used to create an affine frame. Consider a triangle ABC and a point p: A p C B We can form a frame with an origin C and the vectors from C to the other vertices: u = A C v = B C t = C We can then write P in this coordinate frame p = αu + βv + t The coordinates α, β, γ) are called the barcentric coordinates of p relative to A, B, and C.

Computing barcentric coordinates For the triangle eample we can compute the barcentric coordinates of P: α Cramer s rule gives the solution: A B C p * * * α A + βb + γc = A B C * β * = p * )* γ )* )* p B C A p C A B p α = p B C A B C β = A p C A B C γ = A B p A B C A B C A B C A B C Computing the determinant of the denominator gives: B C B C + A C A C + A B A B

Cross products Consider the cross-product of two vectors, u and v. What is the geometric interpretation of this cross-product? A cross-product can be computed as: u v = i j k u u u z v v v z = u v z u z v )i + u z v u v z )j + u v u v )k u v z u z v ) = u z v u v z ) u v u v ) What happens when u and v lie in the - plane? What is the area of the triangle the span?

Barcentric coords from area ratios Now, let s rearrange the equation from two slides ago: B C B C + A C A C + A B A B = B A )C A ) B A )C A ) The determinant is then just the z-component of B-A) C-A), which is two times the area of triangle ABC! Thus, we find: α = SAreapBC) SAreaABC) β = SAreaApC) SAreaABC) γ = SAreaABp) SAreaABC) Where SAreaRST) is the signed area of a triangle, which can be computed with cross-products.

Affine and conve combinations Note that we seem to have added points together, which we said was illegal, but as long as the have coefficients that sum to one, it s ok. We call this an affine combination. More generall is a proper affine combination if: n i= α = i p = α p + + α n p n Note that if the α i s are all positive, the result is more specificall called a conve combination. Q: Wh is it called a conve combination?

Basic 3-D transformations: scaling Some of the 3-D transformations are just like the 2-D ones. For eample, scaling: z z z = s 0 0 0 0 s 0 0 0 0 s z 0 0 0 0 z

Translation in 3D z z z = 0 0 t 0 0 t 0 0 t z 0 0 0 z

Rotation in 3D Rotation now has more possibilities in 3D: 0 0 0 ) 0 cosθ) sinθ) 0 R θ) = ) 0 sinθ) cosθ) 0) ) 0 0 0 cosθ) 0 sinθ) 0 ) 0 0 0 R θ) = ) sinθ) 0 cosθ) 0) ) 0 0 0 cosθ) sinθ) 0 0 ) sinθ) cosθ) 0 0 R z θ) = ) 0 0 0) ) 0 0 0 z R z R R Use right hand rule

Shearing in 3D Shearing is also more complicated. Here is one eample: We call this a shear with respect to the -z plane. z z z = b 0 0 0 0 0 0 0 0 0 0 0 z

Preservation of affine combinations A transformation F is an affine transformation if it preserves affine combinations: where the p i are points, and: Fα p + + α n p n ) = α Fp ) + + α n Fp n ) i= = Clearl, the matri form of F has this propert. One special eample is a matri that drops a dimension. For eample: This transformation, known as an orthographic projection, is an affine transformation. We ll use this fact later n α 0 0 0 = 0 0 0 z 0 0 0 i

Properties of affine transformations Here are some useful properties of affine transformations: Lines map to lines Parallel lines remain parallel Midpoints map to midpoints in fact, ratios are alwas preserved) s p : t q r s p q : t r! ratio = pq qr = s t = p q q r

Net Lecture More Math and Transforms

Programming tips 3D graphics, whether OpenGL or Direct3D or an other API, can be frustrating You write a bunch of code and the result is Nothing but black window; where did our rendering go??

Things to Tr Set our clear color to something other than black! It is eas to draw things black accidentall so don t make black the clear color But black is the initial clear color Did ou draw something for one frame, but the net frame draws nothing? Are ou using depth buffering? Did ou forget to clear the depth buffer? Remember there are near and far clip planes so clipping in Z, not just X Y Have ou checked for glgeterror? Call glgeterror once per frame while debugging so ou can see errors that occur For release code, take out the glgeterror calls Not sure what state ou are in? Use glgetintegerv or glgetfloatv or other quer functions to make sure that OpenGL s state is what ou think it is Use glutswapbuffers to flush our rendering and show to the visible window Likewise glfinish makes sure all pending commands have finished Tr reading http://www.slideshare.net/mark_kilgard/avoiding-9-common-opengl-pitfalls This is well worth the time wasted debugging a problem that could be avoided

Thanks Material for these slides provided b Christian Miller