#2: Geometry &Homogeneous CoordinatesCSE167: Computer GraphicsInstructor: Ronen BarzelUCSD, Winter 20061Outline for TodayMore math…n Finish linear algebra: Matrix composition1. Points, Vectors, and Coordinate Frames2. Homogeneous Coordinates2Matrix Multiplication Each entry is dot product of row of M with column of NM =mxxmxymxzmyxmyymyzmzxmzymzz!"###$%&&&!!!!!!N =nxxnxynxznyxnyynyznzxnzynzz!"###$%&&&L = M!Nlxxlxylxzlyxlyylyzlzxlzylzz!"###$%&&&=mxxmxymxzmyxmyymyzmzxmzymzz!"###$%&&&'nxxnxynxznyxnyynyznzxnzynzz!"###$%&&&lxy= mxxnxy+ mxynyy+ mxznzy3Matrix MultiplicationM =mxxmxymxzmyxmyymyzmzxmzymzz!"###$%&&&!!!!!!!!!!!!!!!!N =nxxnxynxznyxnyynyznzxnzynzz!"###$%&&&!!!!!MN( )ij= miknkj'MN =mxknkx'mxknky'mxknkz'myknkx'myknky'myknkz'mzknkx'mzknky'mzknkz'!"###$%&&&MN =mxxnxx+ mxynyx+ mxznzx( )mxxnxy+ mxynyy+ mxznzy( )mxxnxz+ mxynyz+ mxznzz( )myxnxx+ myynyx+ myznzx( )myxnxy+ myynyy+ myznzy( )myxnxz+ myynyz+ myznzz( )mzxnxx+ mzynyx+ mzznzx( )mzxnxy+ mzynyy+ mzznzy( )mzxnxz+ mzynyz+ mzznzz( )!"####$%&&&&4Multiple Transformations If we have a vector v, and an x-axis rotation matrix Rx, we cangenerate a rotated vector v′: If we wanted to then rotate that vector around the y-axis, we couldmultiply by another matrix:!v = Rx"( )!v!!v = Ry"( )!!v!!v = Ry"( )! Rx#( )!v( )5 We can extend this to the concept of applying any sequence oftransformations: Because matrix algebra obeys the associative law, we can regroup this as: This allows us to compose them into a single matrix:Multiple Transformations!v = M4! M3! M2! M1!v( )( )( )!v = M4!M3!M2!M1( )!vMtotal= M4!M3!M2!M1!v = Mtotal!v6Order 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, versusrotate 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.M!N ! N!M!v = M!v!v = A!B!C( )!v!v = A! B! C!v( )( )M = A!B!C7Quick Matrix algebra summarylinearity:M!(sb) = s M!b( )M! a + b( )= M!a( )+ M!b( )M!1 is inverse of M : (when it exists)M!1M!a( )= aM!1M = IMM!1= IMPQ( )!1= Q!1P!1M!1for a rotation:!R!1= RTdeterminant M :!!!!M > 1!!!!!!!!!!!!!scales upM = 1!!!!!!!!!!!!!pure rotation0< M < 1!!!!scales downM = 0!!!!!!!!!!!!!"flattens": singular matrix,!no inverseM < 0!!!!!!!!!!!!reflects"#$$$%$$$M!1=1M8What 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 compositionof rotation and scale (even “shear”) But there’s a limit to what we can do only having linearoperations on vectors….9Outline for Today1. Finish linear algebra: Matrix composition2. Points, Vectors and Coordinate Frames3. Homogeneous Coordinates10Geometric objects Interesting ObjectsPointsVectors Transformations Coordinate Frames Also: Lines, Rays, Planes, Normals, …11Points 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 ofa point or vector12Points 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 programs13In 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 5P M !! 2 hour class + 3 hour class = 5 hours of classes class ends at 5P M – starts at 2PM = 3 hour class class starts at 2P M + 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 122PM( )+126PM( )!=!4PM("affine combination")! "#### $####14“Coordinate Systems” for timeKnowing 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!15Geometry, analogouslyPoint describes a location in space can subtract points to get a vector can take weighted average of points to get a pointVector 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 specifywhich coordinate system16Vector and point arithmetic C++ classes can support these operations !w =!u +!v!!!!!!!!!! vector+vector ! vector!v =!w "!u!!!!!!!!!! vector-vector ! vector!u = s!!v!!!!!!!!!!!!!!!scale a vectorq = p +!v!!!!!!!!! point+vector ! point!v = q " p!!!!!!!!! point-point ! vectorr =14p +34q!!! weighted average of points ! point17Coordinate FramesOrigin point, and 3 orthonormal vectors for x,y,z axes (right-handed) In CG, often work with many different frames simultaneouslyfghabcxyzOPQ o,!x,!y,!z p,!a,!b,!c q,!f,!g,!h18Coordinates 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 vectorCoordinates 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 tobe 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 axes361!"###$%&&&!!!!or!!!!!9'25!"###$%&&& p = o + 3!x + 6!y +!z!v =!!!!!!9!x ! 2!y + 5!z o,!x,!y,!z19Coordinates of a Frame Suppose you have a frame In world coordinates, might have But in itself always have coordinates: p,!a,!b,!c p
View Full Document