CS 5500 Computer Graphics March 22 2007 Angel

  • Slides: 52
Download presentation
CS 5500 Computer Graphics March 22, 2007 Angel: Interactive Computer Graphics 3 E ©

CS 5500 Computer Graphics March 22, 2007 Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002

Coordinate-Free Geometry • • When we learned simple geometry, most of us started with

Coordinate-Free Geometry • • When we learned simple geometry, most of us started with a Cartesian approach Points were at locations in space p=(x, y, z) We derived results by algebraic manipulations involving these coordinates This approach was nonphysical Physically, points exist regardless of the location of an arbitrary coordinate system Most geometric results are independent of the coordinate system Euclidean geometry: two triangles are identical if two corresponding sides and the angle between them are identical Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 2

Scalars • Need three basic elements in geometry Scalars, Vectors, Points • • •

Scalars • Need three basic elements in geometry Scalars, Vectors, Points • • • Scalars can be defined as members of sets which can be combined by two operations (addition and multiplication) obeying some fundamental axioms (associativity, commutivity, inverses) Examples include the real and complex number under the ordinary rules with which we are familiar Scalars alone have no geometric properties Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 3

Vectors • Physical definition: a vector is a quantity with two attributes Direction Magnitude

Vectors • Physical definition: a vector is a quantity with two attributes Direction Magnitude • Examples include Force Velocity Directed line segments v • Most important example for graphics • Can map to other types Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 4

Vector Operations • • Every vector has an inverse Same magnitude but points in

Vector Operations • • Every vector has an inverse Same magnitude but points in opposite direction Every vector can be multiplied by a scalar There is a zero vector Zero magnitude, undefined orientation The sum of any two vectors is a vector Use head to tail axiom v -v v w v u Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 5

Linear Vector Spaces Mathematical system for manipulating vectors • Operations • Scalar vector multiplication

Linear Vector Spaces Mathematical system for manipulating vectors • Operations • Scalar vector multiplication u= v Vector vector addition: w=u+v • Expressions such as v=u+2 w-3 r Make sense in a vector space Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 6

Vectors Lack Position • These vectors are identical Same length and magnitude • Vectors

Vectors Lack Position • These vectors are identical Same length and magnitude • Vectors spaces insufficient for geometry Need points Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 7

Points Location in space • Operations allowed between points and vectors • Point point

Points Location in space • Operations allowed between points and vectors • Point point subtraction yields a vector Equivalent to point+vector addition v=P QS P=v+Q Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 8

Affine Spaces Point + a vector space • Operations • • Vector vector addition

Affine Spaces Point + a vector space • Operations • • Vector vector addition Scalar vector multiplication Point vector addition Scalar scalar operations For any point define 1 • P=P 0 • P = 0 (zero vector) Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 9

Planes • A plane be determined by a point and two vectors or by

Planes • A plane be determined by a point and two vectors or by three points P( , b)=R+ u+bv P( , b)=R+ (Q R)+b(P Q) Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 10

Normals • • Every plane has a vector n normal (perpendicular, orthogonal) to it

Normals • • Every plane has a vector n normal (perpendicular, orthogonal) to it From point two vector form P( , b)=R+ u+bv, we know we can use the cross product to find n = u v and the equivalent form (P( ) P) n=0 v P Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 u 11

Representation Until now we have been able to work with geometric entities without using

Representation Until now we have been able to work with geometric entities without using any frame of reference, such as a coordinate system • Need a frame of reference to relate points and objects to our physical world. • For example, where is a point? Can’t answer without a reference system World coordinates Camera coordinates Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 12

Coordinate Systems • • Consider a basis v 1, v 2, …. , vn

Coordinate Systems • • Consider a basis v 1, v 2, …. , vn A vector is written v= 1 v 1+ 2 v 2 +…. + nvn The list of scalars { 1, 2, …. n}is the representation of v with respect to the given basis We can write the representation as a row or column array of scalars a=[ 1 2 …. n]T= Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 13

Example V=2 v 1+3 v 2 4 v 3 • A=[2 3 – 4]

Example V=2 v 1+3 v 2 4 v 3 • A=[2 3 – 4] • Note that this representation is with respect to a particular basis • For example, in Open. GL we start by representing vectors using the world basis but later the system needs a representation in terms of the camera or eye basis • Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 14

Coordinate Systems • Which is correct? v v • Both are because vectors have

Coordinate Systems • Which is correct? v v • Both are because vectors have no fixed location Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 15

Frames Coordinate System is insufficient to present points • If we work in an

Frames Coordinate System is insufficient to present points • If we work in an affine space we can add a single point, the origin, to the basis vectors to form a frame • v 2 P 0 v 1 v 3 Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 16

Frame determined by (P 0, v 1, v 2, v 3) • Within this

Frame determined by (P 0, v 1, v 2, v 3) • Within this frame, every vector can be written as v= 1 v 1+ 2 v 2 +…. + nvn • Every point can be written as P = P 0 + b 1 v 1+ b 2 v 2 +…. +bnvn • Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 17

Confusing Points and Vectors Consider the point and the vector P = P 0

Confusing Points and Vectors Consider the point and the vector P = P 0 + b 1 v 1+ b 2 v 2 +…. +bnvn v= 1 v 1+ 2 v 2 +…. + nvn They appear to have the similar representations p=[b 1 b 2 b 3] v=[ 1 2 3] v which confuse the point with the vector p A vector has no position v can place anywhere fixed Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 18

A Single Representation If we define 0 • P = 0 and 1 •

A Single Representation If we define 0 • P = 0 and 1 • P =P then we can write v= 1 v 1+ 2 v 2 + 3 v 3 = [ 1 2 3 0 ] [v 1 v 2 v 3 P 0] T P = P 0 + b 1 v 1+ b 2 v 2 +b 3 v 3= [b 1 b 2 b 3 1 ] [v 1 v 2 v 3 P 0] T Thus we obtain the four dimensional homogeneous coordinate representation v = [ 1 2 3 0 ] T T p = [b 1 b 2 b 3 1 ] Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 19

Homogeneous Coordinates The general form of four dimensional homogeneous coordinates is p=[x y z

Homogeneous Coordinates The general form of four dimensional homogeneous coordinates is p=[x y z w] T We return to a three dimensional point (for w 0) by x x/w y y/w z z/w If w=0, the representation is that of a vector Note that homogeneous coordinates replaces points in three dimensions by lines through the origin in four dimensions Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 20

Homogeneous Coordinates and Computer Graphics • Homogeneous coordinates are key to all computer graphics

Homogeneous Coordinates and Computer Graphics • Homogeneous coordinates are key to all computer graphics systems All standard transformations (rotation, translation, scaling) can be implemented by matrix multiplications with 4 x 4 matrices Hardware pipeline works with 4 dimensional representations For orthographic viewing, we can maintain w=0 for vectors and w=1 for points For perspective we need a perspective division Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 21

Change of Coordinate Systems • Consider two representations of a the same vector with

Change of Coordinate Systems • Consider two representations of a the same vector with respect to two different bases. The representations are a=[ 1 2 3 ] b=[b 1 b 2 b 3] where v= 1 v 1+ 2 v 2 + 3 v 3 = [ 1 2 3] [v 1 v 2 v 3] T =b u +b u = [b b b ] [u u u ] T 1 1 2 2 3 3 1 2 3 Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 1 2 3 22

Representing second basis in terms of first Each of the basis vectors, u 1,

Representing second basis in terms of first Each of the basis vectors, u 1, u 2, u 3, are vectors that can be represented in terms of the first basis v u 1 = g 11 v 1+g 12 v 2+g 13 v 3 u 2 = g 21 v 1+g 22 v 2+g 23 v 3 u 3 = g 31 v 1+g 32 v 2+g 33 v 3 Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 23

Matrix Form The coefficients define a 3 x 3 matrix M= and the basis

Matrix Form The coefficients define a 3 x 3 matrix M= and the basis can be related by a=MTb see text for numerical examples Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 24

Change of Frames • • We can apply a similar process in homogeneous coordinates

Change of Frames • • We can apply a similar process in homogeneous coordinates to the representations of both points anduvectors 1 v 2 Consider two frames (P 0, v 1, v 2, v 3) (Q 0, u 1, u 2, u 3) P 0 v 3 • u 2 Q 0 v 1 u 3 Any point or vector can be represented in each Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 25

Representing One Frame in Terms of the Other Extending what we did with change

Representing One Frame in Terms of the Other Extending what we did with change of bases u 1 = g 11 v 1+g 12 v 2+g 13 v 3 u 2 = g 21 v 1+g 22 v 2+g 23 v 3 u 3 = g 31 v 1+g 32 v 2+g 33 v 3 Q 0 = g 41 v 1+g 42 v 2+g 43 v 3 +g 44 P 0 defining a 4 x 4 matrix M= Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 26

Working with Representations Within the two frames any point or vector has a representation

Working with Representations Within the two frames any point or vector has a representation of the same form a=[ 1 2 3 4 ] in the first frame b=[b 1 b 2 b 3 b 4 ] in the second frame where 4 = b 4 = 1 for points and 4 = b 4 = 0 for vectors and a=MTb The matrix M is 4 x 4 and specifies an affine transformation in homogeneous coordinates Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 27

Affine Transformations Every linear transformation is equivalent to a change in frames • Every

Affine Transformations Every linear transformation is equivalent to a change in frames • Every affine transformation preserves lines • However, an affine transformation has only 12 degrees of freedom because 4 of the elements in the matrix are fixed and are a subset of all possible 4 x 4 linear transformations • Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 28

The World and Camera Frames • • • When we work with representations, we

The World and Camera Frames • • • When we work with representations, we work with n tuples or arrays of scalars Changes in frame are then defined by 4 x 4 matrices In. Open. GL, the base frame that we start with is the world frame Eventually we represent entities in the camera frame by changing the world representation using the model view matrix Initially these frames are the same (M=I) Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 29

Moving the Camera If objects are on both sides of z=0, we must move

Moving the Camera If objects are on both sides of z=0, we must move camera frame M= Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 30

General Transformations • A transformation maps points to other points and/or vectors to other

General Transformations • A transformation maps points to other points and/or vectors to other vectors v=T(u) Q=T(P) Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 31

Affine Transformations Line preserving • Characteristic of many physically important transformations • Rigid body

Affine Transformations Line preserving • Characteristic of many physically important transformations • Rigid body transformations: rotation, translation Scaling, shear • Importance in graphics is that we need only transform endpoints of line segments and let implementation draw line segment between the transformed endpoints Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 32

Pipeline Implementation T (from application program) u T(u) transformation v rasterizer frame buffer T(v)

Pipeline Implementation T (from application program) u T(u) transformation v rasterizer frame buffer T(v) v u vertices T(u) vertices Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 T(u) pixels 33

Notation We will be working with both coordinate free representations of transformations and representations

Notation We will be working with both coordinate free representations of transformations and representations within a particular frame P, Q, R: points in an affine space u, v, w: vectors in an affine space , b, g: scalars p, q, r: representations of points array of 4 scalars in homogeneous coordinates u, v, w: representations of points array of 4 scalars in homogeneous coordinates Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 34

Translation • Move (translate, displace) a point to a new location P’ d P

Translation • Move (translate, displace) a point to a new location P’ d P • Displacement determined by a vector d Three degrees of freedom P’=P+d Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 35

How many ways? Although we can move a point to a new location in

How many ways? Although we can move a point to a new location in infinite ways, when we move many points there is usually one way object translation: every point displaced by same vector Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 36

Translation Using Representations Using the homogeneous coordinate representation in some frame p=[ x y

Translation Using Representations Using the homogeneous coordinate representation in some frame p=[ x y z 1]T p’=[x’ y’ z’ 1]T d=[dx dy dz 0]T Hence p’ = p + d or note that this expression is in x’=x+dx four dimensions and expresses y’=y+dy that point = vector + point z’=z+dz Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 37

Translation Matrix We can also express translation using a 4 x 4 matrix T

Translation Matrix We can also express translation using a 4 x 4 matrix T in homogeneous coordinates p’=Tp where T = T(dx, dy, dz) = This form is better for implementation because all affine transformations can be expressed this way and multiple transformations can be concatenated together Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 38

Rotation (2 D) • Consider rotation about the origin by q degrees radius stays

Rotation (2 D) • Consider rotation about the origin by q degrees radius stays the same, angle increases by q x = r cos (f + q) y = r sin (f + q) x’=x cos q –y sin q y’ = x sin q + y cos q x = r cos f y = r sin f Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 39

Rotation about the z axis • Rotation about z axis in three dimensions leaves

Rotation about the z axis • Rotation about z axis in three dimensions leaves all points with the same z Equivalent to rotation in two dimensions in planes of constant z x’=x cos q –y sin q y’ = x sin q + y cos q z’ =z or in homogeneous coordinates p’=Rz(q)p Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 40

Rotation Matrix R = Rz(q) = Angel: Interactive Computer Graphics 3 E © Addison

Rotation Matrix R = Rz(q) = Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 41

Rotation about x and y axes • Same argument as for rotation about z

Rotation about x and y axes • Same argument as for rotation about z axis For rotation about x axis, x is unchanged For rotation about y axis, y is unchanged R = Rx(q) = Ry(q) = Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 42

Scaling Expand or contract along each axis (fixed point of origin) x’=sxx y’=syx z’=szx

Scaling Expand or contract along each axis (fixed point of origin) x’=sxx y’=syx z’=szx p’=Sp S = S(sx, sy, sz) = Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 43

Reflection corresponds to negative scale factors sx = 1 sy = 1 original sx

Reflection corresponds to negative scale factors sx = 1 sy = 1 original sx = 1 sy = 1 Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 44

Inverses • Although we could compute inverse matrices by general formulas, we can use

Inverses • Although we could compute inverse matrices by general formulas, we can use simple geometric observations Translation: T 1(dx, dy, dz) = T( dx, dy, dz) Rotation: R 1(q) = R( q) • Holds for any rotation matrix • Note that since cos( q) = cos(q) and sin( q)= sin(q) R 1(q) = R T(q) Scaling: S 1(sx, sy, sz) = S(1/sx, 1/sy, 1/sz) Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 45

Concatenation • • • We can form arbitrary affine transformation matrices by multiplying together

Concatenation • • • We can form arbitrary affine transformation matrices by multiplying together rotation, translation, and scaling matrices Because the same transformation is applied to many vertices, the cost of forming a matrix M=ABCD is not significant compared to the cost of computing Mp for many vertices p The difficult part is how to form a desired transformation from the specifications in the application Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 46

Order of Transformations Note that matrix on the right is the first applied •

Order of Transformations Note that matrix on the right is the first applied • Mathematically, the following are equivalent p’ = ABCp = A(B(Cp)) • Note many references use column matrices to present points. In terms of column matrices p. T ’ = p. T CT B T AT • Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 47

General Rotation About the Origin A rotation by q about an arbitrary axis can

General Rotation About the Origin A rotation by q about an arbitrary axis can be decomposed into the concatenation of rotations about the x, y, and z axes R(q) = Rz(qz) Ry(qy) Rx(qx) y qx qy qz are called the Euler angles Note that rotations do not commute We can use rotations in another order but with different angles q v x z Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 48

Rotation About a Fixed Point other than the Origin Move fixed point to origin

Rotation About a Fixed Point other than the Origin Move fixed point to origin Rotate Move fixed point back M = T( pf) R(q) T(pf) Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 49

Instancing In modeling, we often start with a simple object centered at the origin,

Instancing In modeling, we often start with a simple object centered at the origin, oriented with the axis, and at a standard size • We apply an instance transformation to its vertices to • Scale Orient Locate Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 50

Shear • • Helpful to add one more basic transformation Equivalent to pulling faces

Shear • • Helpful to add one more basic transformation Equivalent to pulling faces in opposite directions Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 51

Shear Matrix Consider simple shear along x axis x’ = x + y cot

Shear Matrix Consider simple shear along x axis x’ = x + y cot q y’ = y z’ = z H(q) = Angel: Interactive Computer Graphics 3 E © Addison Wesley 2002 52