1 / 52

Linear Algebra Review

Linear Algebra Review. CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005. Coordinate Systems. Right handed coordinate system. Vector Arithmetic. Vector Magnitude. The magnitude (length) of a vector is: Unit vector (magnitude=1.0). Dot Product.

adora
Download Presentation

Linear Algebra Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linear Algebra Review CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005

  2. Coordinate Systems • Right handed coordinate system

  3. Vector Arithmetic

  4. Vector Magnitude • The magnitude (length) of a vector is: • Unit vector (magnitude=1.0)

  5. Dot Product

  6. Example: Angle Between Vectors • How do you find the angle θ between vectors a and b? b θ a

  7. Example: Angle Between Vectors b θ a

  8. Dot Products with Unit Vectors 0 <a·b < 1 a·b = 0 a·b = 1 b θ a -1 < a·b < 0 a·b a·b = -1

  9. Dot Products with Non-Unit Vectors • If a and b are arbitrary (non-unit) vectors, then the following are still true: • If θ < 90º then a·b > 0 • If θ = 90º then a·b = 0 • If θ > 90º then a·b < 0

  10. Dot Products with One Unit Vector • If |u|=1.0 then a·u is the length of the projection of a onto u a u a·u

  11. • x n p • Example: Distance to Plane • A plane is described by a point p on the plane and a unit normal n. Find the distance from point x to the plane

  12. • x n p • Example: Distance to Plane • The distance is the length of the projection of x-p onto n: x-p

  13. Cross Product

  14. Properties of the Cross Product area of parallelogram ab if a and b are parallel is perpendicular to both a and b, in the direction defined by the right hand rule

  15. Example: Area of a Triangle • Find the area of the triangle defined by 3D points a, b, and c c b a

  16. Example: Area of a Triangle c c-a b a b-a

  17. Example: Alignment to Target • An object is at position p with a unit length heading of h. We want to rotate it so that the heading is facing some target t. Find a unit axis a and an angle θ to rotate around. t • • p h

  18. Example: Alignment to Target a t t-p • θ • p h

  19. Trigonometry cos2θ+ sin2θ= 1 1.0 sin θ θ cos θ

  20. Laws of Sines and Cosines • Law of Sines: • Law of Cosines: b α γ c a β

  21. Matrices • Computer graphics apps commonly use 4x4 homogeneous matrices • A rigid 4x4 matrix transformation looks like this: • Where a, b, & c are orthogonal unit length vectors representing orientation, and d is a vector representing position

  22. Matrices • The right hand column can cause a projection, which we won’t use in character animation, so we leave it as 0,0,0,1 • Some books store their matrices in a transposed form. This is fine as long as you remember that: (A·B)T = BT·AT

  23. Example: Target ‘Lock On’ • For an airplane to get a missile locked on, the target must be within a 10 degree cone in front of the plane. If the plane’s matrix is M and the target position is t, find an expression that determines if the plane can get a lock on. b • t d c a

  24. Example: Target ‘Lock On’ • We want to check the angle between the heading vector (-c) and the vector from d to t: • We can speed that up by comparing the cosine instead ( cos(10°)=.985 )

  25. Example: Target ‘Lock On’ • We can even speed that up further by removing the division and the square root in the magnitude computation:

  26. Orthonormality • If all row vectors and all column vectors of a matrix are unit length, that matrix is said to be orthonormal • This also implies that all vectors are perpendicular to each other • Orthonormal matrices have some useful mathematical properties, such as: • M-1 = MT

  27. Orthonormality • If a 4x4 matrix represents a rigid transformation, then the upper 3x3 portion will be orthonormal

  28. Determinants • The determinant of a 4x4 matrix with no projection is equal to the determinant of the upper 3x3 portion

  29. Determinants • The determinant is a scalar value that represents the volume change that the transformation will cause • An orthonormal matrix will have a determinant of 1, but non-orthonormal volume preserving matrices will have a determinant of 1 also • A flattened or degenerate matrix has a determinant of 0 • A matrix that has been mirrored will have a negative determinant

  30. Transformations • To transform a vector v by matrix M: v’=v·M • If we want to apply several transformations, we can just multiply by several matrices: v’=(((v·M1)·M2)·M3)·M4… • Or we can concatenate the transformations into a single matrix: Mtotal=M1·M2·M3·M4… v’=v·Mtotal

  31. Matrix Transformations • We usually transform vertices from some local space where they are defined into a world space v’ = v·W • Once in world space, we can perform operations that require everything to be in the same space (collision detection, high quality lighting…) • Then, they are transformed into a camera’s space, and then projected into 2D v’’ = v’·C-1·P • In simple situations, we can do this all in one step: v’’ = v·W·C-1·P

  32. Inversion • If M transforms v into world space, then M-1 transforms v’ back into local space

  33. Vector Dot Vector

  34. Vector Dot Matrix

  35. Matrix Dot Matrix

  36. Homogeneous Vectors • Technically, homogeneous vectors are 4D vectors that get projected into the 3D w=1 space

  37. Homogeneous Vectors • Vectors representing a position in 3D space can just be written as: • Vectors representing direction are written: • The only time the w coordinate will be something other than 0 or 1 is in the projection phase of rendering, which is not our problem

  38. Position Vector Dot Matrix

  39. Position Vector Dot Matrix y v=(.5,.5,0,1) x (0,0,0) Local Space

  40. Position Vector Dot Matrix b Matrix M y y d a v=(.5,.5,0,1) x x (0,0,0) (0,0,0) Local Space World Space

  41. Position Vector Dot Matrix b v’ y y d a v=(.5,.5,0,1) x x (0,0,0) (0,0,0) Local Space World Space

  42. Direction Vector Dot Matrix

  43. Matrix Dot Matrix (4x4) • The row vectors of M’ are the row vectors of M transformed by matrix N • Notice that a, b, and c transform as direction vectors and d transforms as a position

  44. Identity • Take one more look at the identity matrix • It’s a axis lines up with x, b lines up with y, and c lines up with z • Position d is at the origin • Therefore, it represents a transformation with no rotation or translation

  45. Camera Matrix • Think of the camera just like any other object. Just as a chair model has a matrix W that transforms it into world space, the camera matrix C would transform a camera model into world space. • We don’t want to transform the camera into world space. Instead, we want to transform the world into the camera’s space, so we use the inverse of C.

  46. Example: Camera ‘Look At’ • Our eye is located at position e and we want to look at a target at position t. Generate an appropriate camera matrix M.

  47. Example: Camera ‘Look At’ • Our eye is located at position e and we want to look at a target at position t. Generate an appropriate camera matrix M. • Two possible approaches include: • Measure angles and rotate matrix into place • Construct a,b,c, & d vectors of M directly

  48. Example: Camera ‘Look At’Method 1: Measure Angles & Rotate • Measure Angles: • Tilt angle • Heading angle • Position • Construct matrix by starting with the identity, then apply tilt and heading rotations

  49. Example: Camera ‘Look At’Method 2: Build Matrix Directly • The d vector is just the position of the camera, which is e: • The c vector is a unit length vector that points directly behind the viewer:

  50. Example: Camera ‘Look At’Method 2: Build Matrix Directly • The a vector is a unit length vector that points to the right of the viewer. It is perpendicular to the c axis. To keep the camera from rolling, we also want the a vector to lay flat in the xz-plane, perpendicular to the y-axis. • Note that a cross product with the y-axis can be optimized as follows:

More Related