Presentation is loading. Please wait.

Presentation is loading. Please wait.

Outline for Today More math… Finish linear algebra: Matrix composition

Similar presentations


Presentation on theme: "Outline for Today More math… Finish linear algebra: Matrix composition"— Presentation transcript:

0 #2: Geometry & Homogeneous Coordinates
CSE167: Computer Graphics Instructor: Ronen Barzel UCSD, Winter 2006

1 Outline for Today More math… Finish linear algebra: Matrix composition
Points, Vectors, and Coordinate Frames Homogeneous Coordinates

2 Matrix Multiplication
Each entry is dot product of row of M with column of N

3 Matrix Multiplication

4 Multiple Transformations
If we have a vector v, and an x-axis rotation matrix Rx, we can generate a rotated vector v′: If we wanted to then rotate that vector around the y-axis, we could multiply by another matrix:

5 Multiple Transformations
We can extend this to the concept of applying any sequence of transformations: Because matrix algebra obeys the associative law, we can regroup this as: This allows us to compose them into a single matrix:

6 Order matters! Matrix multiplication does NOT commute:
(unless one or the other is a uniform scale) Try this: rotate 90 degrees about x then 90 degrees about z, versus rotate 90 degrees about z then 90 degrees about x. Matrix composition works right-to-left. Compose: Then apply it to a vector: It first applies C to v, then applies B to the result, then applies A to the result of that.

7 Quick Matrix algebra summary

8 What good is this? Composition of transformations, by matrix multiplication, is a basic technique Used all the time You’ll probably use it for Project 1 All linear operations on vectors can be expressed as composition of rotation and scale (even “shear”) But there’s a limit to what we can do only having linear operations on vectors….

9 Outline for Today Finish linear algebra: Matrix composition
Points, Vectors and Coordinate Frames Homogeneous Coordinates

10 Geometric objects Interesting Objects Points Vectors Transformations
Coordinate Frames Also: Lines, Rays, Planes, Normals, …

11 Points and vectors You know linear algebra, vector spaces
Why am I talking about this? Emphasize differences: between a point and a vector between a point or vector and the representation of a point or vector

12 Points and vectors in R3, can represent point as 3 numbers
in R3, can represent vector as 3 numbers Easy to think they’re the same thing… …but they’re not! different operations, different behaviors many program libraries make this mistake easy to have bugs in programs

13 In 1D, consider time point in time: a class meets at 2PM
duration of time: a class lasts 2 hours operations: class at 2PM + class at 3PM ≠ class at 5PM !! 2 hour class + 3 hour class = 5 hours of classes class ends at 5PM – starts at 2PM = 3 hour class class starts at 2PM + lasts 3 hours = ends at 5PM 2 classes at 3PM ≠ one class at 6PM !! 2 classes last 3 hours = 6 hours of classes Class from 2PM to 10PM, half done at

14 “Coordinate Systems” for time
Knowing just the hour number doesn’t tell you everything… AM vs. PM (or use 8h00 vs 20h00) Time zones: same point, many representations 10 (Paris) == 9 (London) to remove ambiguity, often use GMT If always staying in local time zone, not important if scheduling globally, must be careful. convert from one time zone to another. (Also, hours only good within one day need to specify date & time UNIX time: seconds since 01/01/1970, 00h00 GMT) Notice: time durations are unaffected by all this!

15 Geometry, analogously Point describes a location in space
can subtract points to get a vector can take weighted average of points to get a point Vector describes a displacement in space has a magnitude and direction can add, subtract, scale vectors can add vector to a point to get a point To represent them as three numbers, you must specify which coordinate system

16 Vector and point arithmetic
C++ classes can support these operations

17 Coordinate Frames Origin point, and 3 orthonormal vectors for x,y,z axes (right-handed) In CG, often work with many different frames simultaneously c b x y z O a h P g f Q

18 Coordinates If you have coordinate triples such as:
Then, with frame such as you can construct a point or vector: Same coordinates, different frame  different point or vector Coordinates have no real meaning without a frame CG programs often have lots of frames--you have to keep track! (It’s possible to write C++ classes that keep track of frames. But it’s hard for them to be time- and memory-efficient, so it’s rarely done in practice.) Typically have “World Coordinates” as implicit base frame Notice: vectors don’t depend on the origin of the frame, only the axes

19 Coordinates of a Frame Suppose you have a frame
In world coordinates, might have But in itself always have coordinates:

20 Coordinate equivalences
Given a frame: Can have a point with some coords: Can have a vector with same coords: Formally, we have: Informally, p and v look and act about the same People often sloppy, don’t distinguish point from vector Can only get away with it if you stay in same frame! And even then need to be careful… O

21 Outline for Today Finish linear algebra: Matrix composition
Points, Vectors and Coordinate Frames Homogeneous Coordinates But first: transforming points

22 Linear Transformations
Matrix-vector multiplication Matrix-point multiplication M Rotation matrix Rotates vector direction Moves point by rotating about origin of frame Scale matrix Scales vector magnitude Moves point towards or away from origin of frame

23 Rotating an object Object defined as collection of points
Apply rotation matrix to every point: Rotates object about origin of frame Also rotates all vectors in object:

24 Scaling an object Apply scale matrix to every point:
Scale object about origin of frame Also scales all vectors in object

25 Moving an object Add displacement vector to each point:
Translates the object: Vectors don’t change: d

26 General Object Transformation
Some matrix M and displacement d: Math note: the transformation for p isn’t linear It’s an affine transformation Points and their transforms form an affine space Not a vector space

27 But it’s very inconvenient
Different rule for points vs. vectors Hard to compose transformations: Hard to invert, etc. …so introduce Homogeneous Coordinates

28 Homogeneous coordinates
Basic: a trick to unify/simplify computations. Deeper: projective geometry Interesting mathematical properties Good to know, but less immediately practical We will use some aspect of this when we do perspective projection (in a few weeks)

29 Homogeneous coordinates
Add an extra component. 1 for a point, 0 for a vector: combine M and d into single 4x4 matrix: And see what happens when we multiply…

30 Homogeneous point transform
Transform a point: Top three rows are the affine transform! Bottom row stays 1

31 Homogeneous vector transform
Transform a vector: Top three rows are the linear transform Displacement d is properly ignored Bottom row stays 0

32 Homogeneous arithmetic
Legal operations always end in 0 or 1!

33 Homogeneous Transforms
Rotation, Scale, and Translation of points and vectors unified in a single matrix transformation: Matrix has the form: Last row always 0,0,0,1 Transforms compose by matrix multiplication! Same caveat: order of operations is important Same note: Transforms operate right-to-left

34 Primitive Transforms

35 Programming in practice
Everyone uses homogeneous matrices. built into low-level software, hardware In practice, almost never explicitly use 4th component of vector or point. Waste of memory & computation Instead, keep track of points vs. vectors explicitly E.g. by C++ classes Separate matrix methods “transform point” and “transform vector” that implicitly use the 1 or 0.

36 More Coordinate Equivalences
Translate an object by d  Translate the coordinate frame by -d Either way, get the same coordinates out Rotate object about the frame’s origin  Rotate the frame oppositely out its own origin Duality: Matrix transforms objects vs. changes coordinates Either can be handy (we’ll talk about next class) Can be confusing, make sure you know which you want…

37 Transformation as coordinate frame
Build matrix from vectors a, b, c, point d Notice effect on coordinate frame: Any transform M describes change of frame: If a,b,c are right-handed orthonormal, transformation is rigid Pure rotation, pure translation, or mix of rotation and translation No scale

38 Useful tidbit: Rotate about a “pivot”
Q: How to rotate about arbitrary pivot? Rotation matrix always rotates about origin! A: Sequence of operations: This is a handy “primitive” to implement Food for thought: what’s the structure of the resulting matrix?

39 Next class: Hierarchical Transformations Geometric Calculations


Download ppt "Outline for Today More math… Finish linear algebra: Matrix composition"

Similar presentations


Ads by Google