Vectors and Transforms

Size: px
Start display at page:

Download "Vectors and Transforms"

Transcription

1 Skämtbild om matte å KTH-animationskurs Vectors and Transforms In 3D Grahics

2 Change of Lecture Room Week 2: Wed 2/11: HC1 Fri 4/11: HA1 Thereafter HC1 all times excet: Week 5: Fri: HC3 Week 7: Fri: HC3

3 Course Info Real-Time Rendering, 3:rd edition Cremona Who still needs to buy the book? Simlea How many have tested it and made it work? Deartment of Comuter Engineering

4 Will start on Monday Rooms 4211/13/15/2 Schedule Mon to Fri: Tutorials Thurs + Friday, also: Deartment of Comuter Engineering Course assistants are available: Wednesdays: 17: - 19: Thursdays: 13: - 17: Fridays: 13: - 17: You can do the tutorials at home and just resent here when course assistants are available.

5 Deartment of Comuter Engineering Tutorial Grous Work alone or in airs In break if you do not already have lab-artner (or not working alone): Sign u list here at desk!

6 Quick Reetition of Vector Algebra

7 Reading instructions VERY IMPORTANT READ HOME PAGE in connection to each lecture COURSE HOME PAGE is located here: htt:// COURSE HOME PAGE

8 Why transforms? We want to be able to animate objects and the camera Translations Rotations Shears And more We want to be able to use rojection transforms Tomas Akenine-Mőller 22

9 How imlement transforms? Matrices! Can you really do everything with a matrix? Not everything, but a lot! We use 3x3 and 4x4 matrices x y z M m m m 1 2 m m m m m m Tomas Akenine-Mőller 22

10 Transformation Pieline v e r t e x object eye cli normalized device Modelview Matrix Projection Matrix Persective Division Viewort Transform window Modelview Modelview Projection other calculations here Color / normal er vertex olygon culling cliing OenGL Geometry stage done Ulf on Assarsson GPU 27

11 Model to World Matrix Model sace Word sace camera World to View Matrix ModelViewMtx = Model to View Matrix View sace Tomas Akenine-Mőller 22

12 The OenGL Pieline From htt://deltronslair.com/glie.html Tomas Akenine-Mőller 22

13 How do I use transforms ractically? Say you have a circle with origin at (,,) and with radius 1 unit circle Mtx4f m; m.translate(8,,); RenderCircle(m); v_transformed = t*s*v Mtx4f s,t; s.scale(2,2,2); t.translate(3,2,); RenderCircle(t*s); Tomas Akenine-Mőller 22

14 Cont d from revious slide A simle 2D examle A circle in model sace y scale(2,2,2); translate(3,2,); translate(8,,); x Tomas Akenine-Mőller 22

15 Cont d from revious slide A simle 2D examle A circle in model sace y translate(3,2,); scale(2,2,2); (i.e., m=s*t) x Tomas Akenine-Mőller 22

16 Moving an object Demo Tomas Akenine-Mőller 22

17 Rotation (2D) 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' y'??? x? y x = r cos f y = r sin f Answer: x =x cos q y sin q y = x sin q + y cos q

18 Tomas Akenine-Mőller 22 Derivation of rotation matrix in 2D T T y x T T y x i i i i r r n n r r ir r i i r e re e i r re i e )) cos sin sin (cos ), sin sin cos (cos ( ), ( ) sin, cos ( ), ( ) cos sin sin (cos ) sin sin cos (cos )] sin )(cos sin [(cos ) sin (cos ] mult by [rotation is f f f f f f f f f f f f f f f f n n R? n z n

19 Tomas Akenine-Mőller 22 Derivation 2D rotation, cont d + y x y x z z T T y x T T y x z n n r r n n r r R R R n n f f f f f f cos sin sin cos? what is )) sin cos cos (sin ), sin sin cos (cos ( ), ( ) sin, cos ( ), (

20 Tomas Akenine-Mőller 22 Rotations in 3D Same as in 2D for Z-rotations, but with a 3x3 matrix For X For Y cos sin 1 sin cos ) ( cos sin sin cos 1 ) ( 1 cos sin sin cos ) ( cos sin sin cos ) ( y x z z R R R R

21 Translations must be simle? Translation????????? + t Rotation n R Rotation is matrix mult, translation is add Would be nice if we could only use matrix multilications Turn to homogeneous coordinates Add a new comonent to each vector Tomas Akenine-Mőller 22

22 Tomas Akenine-Mőller 22 Homogeneous notation A oint: Translation becomes: A vector (direction): Translation of vector: Also allows for rojections (later) 1 1 ) ( z z y y x x z y x z y x t t t t t t t T ) T z y x 1 ) T z y x d d d d Td d

23 Rotations in 4x4 form Just add a row at the bottom, and a column at the right: R z ( ) cos sin sin cos 1 Similarly for X and Y det( R )=1 (for 3x3 matrices) Trace( R )=1+2cos(alha) (for any axis,3x3) 1 Tomas Akenine-Mőller 22

24 Change of Frames M model-to-world : 1 M world model-toz z z z y y y y x x x x o c b a o c b a o c b a (,5,,1) E.g.: world = M mw model = M mw (,5,) T = 5 b (+ o) b x y z c a o world sace model sace (Both coordinate systems are right-handed) 5 1 P=

25 More basic transforms Scaling Shear Rigid-body: rotation then translation X TR Concatenation of matrices Not commutative, i.e., RT TR X TR In, the rotation is done first Inverses and rotation about arbitrary axis: Rigid body: X -1 = X T Tomas Akenine-Mőller 22

26 Normal transforms Not so normal Cannot use same matrix to transform normals Use: N ) M 1 T instead of M M works for rotations and translations, though Tomas Akenine-Mőller 22

27 The Euler Transform Assume the view looks down the negative z-axis, with u in the y-direction, x to the right E( h,, r) R ( r) R ( ) R ( h) h=head =itch r=roll z Gimbal lock can occur looses one degree of freedom Examle: h=,=/2, then the z-rotation is the same as doing a revious rot around y-axis x y We should aly the rotation transforms to the rotation axes as well Tomas Akenine-Mőller 22

28 Quaternions qˆ ( q, q ) ( q, q, q, q ) v w iq x + jq y + kqz + qw Extension of imaginary numbers Avoids gimbal lock that the Euler could roduce Focus on unit quaternions: n(ˆ) q q 2 x + q 2 y + x q 2 z y + q z 2 w w 1 A unit quaternion is: qˆ (sinfu q,cos f) where u q 1 Tomas Akenine-Mőller 22

29 Unit quaternions are erfect for rotations! qˆ Comact (4 comonents) 1 Can show that qq ˆ ˆ ˆ reresents a rotation of 2f radians around uq of (sin fu q,cos That is: a unit quaternion reresent a rotation as a rotation axis and an angle rotate(ux,uy,uz,angle); Interolation from one quaternion to another is much simler, and gives otimal results f ) Tomas Akenine-Mőller 22

30 Projections Orthogonal (arallel) and Persective Tomas Akenine-Mőller 22

31 Tomas Akenine-Mőller 22 Orthogonal rojection Simle, just ski one coordinate Say, we re looking along the z-axis Then dro z, and render y x z y x ortho ortho M M z z

32 Orthogonal rojection Not invertible! (determinant is zero) For Z-buffering It is not sufficient to roject to a lane Rather, we need to roject to a box far image lane near Unit cube: [-1,-1,-1] to [1,1,1] eye Unit cube is also used for ersective roj. Simlifies cliing Tomas Akenine-Mőller 22

33 Orthogonal rojection The unitcube rojection is invertible Simle to derive Just a translation and scale to far left near right bottom Tomas Akenine-Mőller 22

34 What about those homogenenous coordinates? x y z ) T w w= for vectors, and w=1 for oints What if w is not 1 or? Solution is to divide all comonents by w / / / 1) T x w Gives a oint again! y w z w Can be used for rojections, as we will see Tomas Akenine-Mőller 22

35 Tomas Akenine-Mőller 22 Persective rojection z x x d q z x x q d z y y q d For y : d> 1/ d P

36 Tomas Akenine-Mőller 22 Persective rojection The arrow is the homogenization rocess 1/ d P? P 1 1/ z y x d P d z z y x / 1 / / 1 / / / d d d d d d z y z x z z z y z x q z x x q d z y y q d

37 Persective rojection Again, the determinant is (not invertible) To make the rest of the ieline the same as for orhogonal rojection: roject into unit-cube Not much different from P Do not collase z-coord to a lane Tomas Akenine-Mőller 22

38 Tomas Akenine-Mőller 22 Understanding the rojection matrix Scaling Skew Kee z-info 1 1/ z y x z y x d c s b s a s P d c s b s a s z z z z y y z x x / ) / ( ' ) / ( ' ) / ( z z z y z x c d b d a d q

39 Persective rojection matrices See Från Värld till Skärm secion 4 for more details. BREAK... Tomas Akenine-Mőller 22

40 Quick Reetition of Vector Algebra Length of vector: x x + y + z ) Normalizing a vector: Normal: n (usualy needs to be normalized as well) Cross Product: Perendicular vector, Area va vb sin α: sin = Dot roduct: xˆ v v ) v ) 1 2 v v a cos v a b va v v v b b x x x + y + z ) x v a v b ( a xbx + ayby + azbz )

41 Ray/Plane Intersections Ray: r(t)=o+td n Plane: n x + d = ; d=-n Set x=r(t): n (o+td) d = n o+t(n d) d = t = (d n o) / (n d) o d Vec3f rayplaneintersect(vec3f o,dir, n, d) { float t=(d-n.dot(o)) / (n.dot(dir)); return o + d*t; } Ulf Assarsson 211

42 Ray/Plane Intersections Ray: r(t)=o+td n Plane: n x + d = ; d=-n Set x=r(t): n (o+td) d = n o+t(n d) d = t = (d n o) / (n d) o d Note: for t to be the distance exressed in the used unit, d must be of unit length. Ulf Assarsson 211

43 Line/Line intersection in 2D r 1 (s) = o 1 +sd 1 r 2 (t) = o 2 +td 2 r 1 (s) = r 2 (t) (1) o 1 +sd 1 = o 2 +td 2 (2) noting that d d =, [d=(a,b) d =(b,-a)] sd 1 d 2 = (o 2 -o 1 ) d 2 td 2 d 1 = (o 1 -o 2 ) d 1 s (o o ) d (d 1 d 2 ) t (o 1 o 2 ) d 1 (d 2 d 1 ) Ulf Assarsson 26

44 Line/Line intersection in 3D r 1 (s) = o 1 +sd 1 r 2 (t) = o 2 +td 2 r 1 (s) = r 2 (t) (1) o 1 +sd 1 = o 2 +td 2 (2) noting that d x d= ( d d 1 2) 2 = means arallel lines sd 1 x d 2 = (o 2 -o 1 ) x d 2 td 2 x d 1 = (o 1 -o 2 ) x d 1 s, t corresond to closest oints s (d 1 x d 2 ) (d 1 x d 2 ) = ((o 2 -o 1 ) x d 2 ) (d 1 x d 2 ) t (d 2 x d 1 ) (d 2 x d 1 ) = ((o 1 -o 2 ) x d 1 ) (d 2 x d 1 ) det( o o, d, d d ) det( o s t 2 2 ( d1 d2) ( d1 d2) Ulf Assarsson 26 o, d, d d )

45 Area and Perimeter v 2 v For olygon, 1... n Perimeter = omkrets = sum of length of each edge in 2D and 3D: O n1 i n1 2 2 x x ) + y y ) + z z ) i+ 1 i i+ 1 i i+ 1 i i+ 1 i i 2 Area in 2D: A 1 1 n 2 i1 x i y i+ 1 x i+ 1 y i We can understand the formula from using Greens theorem: integrating over border to get area Choose arbitrary oint to integrate from, e.g. Origin (,,) Works for non-convex olygons as well A triangle 1 2 v v ) Ulf Assarsson

46 Ulf Assarsson 26

47 Volume in 3D The same trick for comuting area in 2D can be used to easily comute the volume in 3D for triangulated objects Again, choose arbitrary oint-of-integration, e.g. Origin (,,) With resect to oint-of-integration For all backfacing triangles, add volume For all frontfacing triangles, subtract volume Works for non-convex olygons as well V tetrahedro n V object 1 3! 1 a 3! n i1 a 1 3! bc) det( a, b, c) bc) where a = 1 -origin b = 2 -origin c = 3 -origin The sign of the determinant will automatically handle ositive and negative contribution Ulf Assarsson 26

48 Scan Conversion of Line Segments Start with line segment in window coordinates with integer values for endoints Assume imlementation has a write_ixel function y = kx + m k y x

49 DDA Algorithm Digital Differential Analyzer DDA was a mechanical device for numerical solution of differential equations Line y=kx+ m satisfies differential equation dy/dx = k = y/x = y 2 -y 1 /x 2 -x 1 Along scan line x = 1 y=y1; For(x=x1; x<=x2,ix++) { write_ixel(x, round(y), line_color) y+=k; }

50 Problem DDA = for each x lot ixel at closest y Problems for stee lines

51 Using Symmetry Use for 1 k For k > 1, swa role of x and y For each y, lot closest x

52 The roblem with DDA is that it uses floats which was slow in the old days Bresenhams algorithm only uses integers

53 Bresenham s line drawing algorithm The line is drawn between two oints (x, y ) and (x 1, y 1 ) k ( y ( x Sloe 1 (y = kx + m) 1 y x ) ) Each time we ste 1 in x-direction, we should increment y with k. Otherwise the error in y increases with k. If the error surasses.5, the line has become closer to the next y- value, so we add 1 to y simultaneously decreasing the error by 1 function line(x, x1, y, y1) int deltax := abs(x1 - x) int deltay := abs(y1 - y) real error := real deltaerr := deltay / deltax int y := y for x from x to x1 lot(x,y) error := error + deltaerr if error.5 y := y + 1 error := error - 1. See also htt://en.wikiedia.org/wiki/bresenham's_line_algorithm Ulf Assarsson 26

54 Bresenham s line drawing algorithm Now, convert algorithm to only using integer comutations The trick we use is to multily the fractional numbers above by (x 1 - x ), which enables us to exress them as integers. The only roblem remaining is the constant.5 to deal with this, we multily both sides of the inequality by 2 Old float version: function line(x, x1, y, y1) int deltax := abs(x1 - x) int deltay := abs(y1 - y) real error := real deltaerr := deltay / deltax int y := y for x from x to x1 lot(x,y) error := error + deltaerr if error.5 y := y + 1 error := error - 1. New integer version: function line(x, x1, y, y1) int deltax := abs(x1 - x) int deltay := abs(y1 - y) real error := real deltaerr := deltay int y := y for x from x to x1 lot(x,y) error := error + deltaerr if 2*error deltax y := y + 1 error := error - deltax Ulf Assarsson 26

55 Comlete Bresenham s line drawing algorithm function line(x, x1, y, y1) boolean stee := abs(y1 - y) > abs(x1 - x) if stee then swa(x, y) swa(x1, y1) if x > x1 then swa(x, x1) swa(y, y1) int deltax := x1 - x int deltay := abs(y1 - y) int error := int yste int y := y if y < y1 then yste := 1 else yste := -1 for x from x to x1 if stee then lot(y,x) else lot(x,y) error := error + deltay if 2 error deltax y := y + yste error := error - deltax The first case is allowing us to draw lines that still sloe downwards, but head in the oosite direction. I.e., swaing the initial oints if x > x1. To draw lines that go u, we check if y >= y1; if so, we ste y by -1 instead of 1. To be able to draw lines with a sloe less than one, we take advantage of the fact that a stee line can be reflected across the line y=x to obtain a line with a small sloe. The effect is to switch the x and y variables. Ulf Assarsson 26

56 You need to know How to create a simle Scaling matrix, rotation matrix, translation matrix and orthogonal rojection matrix Change of frames (creating model-to-view matrix) Understand how quaternions are used Understanding of Euler transforms + gimbal lock DDA line drawing algorithm Understand what is good with Bresenhams line drawing algorithm How to do line/line intersection test

57 The following slides are simly extra noncomulsory material that exlains the content of the lecture in a different way. Most of the following slides are from Ed Angel Professor of Comuter Science, Electrical and Comuter Engineering, and Media Arts University of New Mexico

58 Scalars Need three basic elements in geometry Scalars, Vectors, Points Scalars can be defined as members of sets which can be combined by two oerations (addition and multilication) obeying some fundamental axioms (associativity, commutivity, inverses) Examles include the real and comlex number systems under the ordinary rules with which we are familiar Scalars alone have no geometric roerties

59 Vector Oerations Physical definition: a vector is a quantity with two attributes Direction Magnitude Examles include Force Velocity Directed line segments Most imortant examle for grahics Can ma to other tyes. Every vector can be multilied by a scalar. There is a zero vector Zero magnitude, undefined orientation The sum of any two vectors is a vector v -v v v u w

60 Vectors Lack Position These vectors are identical Same length and magnitude Vectors insufficient for geometry Need oints

61 Location in sace Points Oerations allowed between oints and vectors Point-oint subtraction yields a vector Equivalent to oint-vector addition v=p-q P=v+Q

62 Affine Saces Point + a vector sace Oerations Vector-vector addition Scalar-vector multilication Point-vector addition Scalar-scalar oerations For any oint define 1 P = P P = (zero vector)

63 Lines Consider all oints of the form P()=P + d Set of all oints that ass through P in the direction of the vector d

64 Parametric Form This form is known as the arametric form of the line More robust and general than other forms Extends to curves and surfaces Two-dimensional forms Exlicit: y = kx + m Imlicit: ax + by +c = Parametric: x() = x + (1-)x 1 y() = y + (1-)y 1

65 Rays and Line Segments If >=, then P() is the ray leaving P in the direction d If we use two oints to define v, then P( ) = Q + (R-Q)=Q+v =R + (1-)Q For <=<=1 we get all the oints on the line segment joining R and Q

66 Planes A lane can be defined by a oint and two vectors or by three oints P v R u R Q P(,b)=R+u+bv P(,b)=R+(Q-R)+b(P-Q)

67 Triangles convex sum of S() and R convex sum of P and Q for <=,b<=1, we get all oints in triangle

68 Normals Every lane has a vector n normal (erendicular, orthogonal) to it From oint/vector form P(,b)=R+u+bv we know we can use the cross roduct to find n = u v Plane equation: n x d =, where d = -n and is any oint in the lane v P u

69 Normal for Triangle lane n ( - ) = n 2 n = ( 2 - ) ( 1 - ) normalize n n/ n 1 Note that right-hand rule determines outward face

70 Convexity An object is convex iff for any two oints in the object all oints on the line segment between these oints are also in the object P P Q Q convex not convex

71 Affine Sums Consider the sum P= 1 P P n P n Can show by induction that this sum makes sense iff n =1 in which case we have the affine sum of the oints P 1,P 2,..P n If, in addition, i >=, we have the convex hull of P 1,P 2,..P n

72 Convex Hull Consider the linear combination P= 1 P P n P n If n =1 (in which case we have the affine sum of the oints P 1,P 2,..P n ) and if i >=, we have the convex hull of P 1,P 2,..P n Smallest convex object containing P 1,P 2,..P n

73 Frames A coordinate system is insufficient to reresent oints If we work in an affine sace we can add a single oint, the origin, to the basis vectors to form a frame v 2 P v 1 v 3

74 Reresenting one basis in terms of another Each of the basis vectors, u1,u2, u3, are vectors that can be reresented 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

75 Matrix Form The coefficients define a 3 x 3 matrix M = g g g and the bases can be related by g g g a=m T b g g g 33

76 Translation Move (translate, dislace) a oint to a new P location P d Dislacement determined by a vector d Three degrees of freedom P =P+d

77 How many ways? Although we can move a oint to a new location in infinite ways, when we move many oints there is usually only one way object translation: every oint dislaced by same vector

78 Translation Using Reresentations Using the homogeneous coordinate reresentation in some frame =[ x y z 1] T =[x y z 1] T d=[dx dy dz ] T Hence = + d or x =x+d x y =y+d y z =z+d z note that this exression is in four dimensions and exresses oint = vector + oint

79 Translation Matrix We can also exress translation using a 4 x 4 matrix T in homogeneous coordinates =T where 1 dx 1 d y 1 dz T = T(d x, d y, d z ) = 1 This form is better for imlementation because all affine transformations can be exressed this way and multile transformations can be concatenated together

80 Homogeneous Coordinates The homogeneous coordinates form for a three dimensional oint [x y z] is given as =[x y z w] T =[wx wy wz w] T We return to a three dimensional oint (for w) by xx /w yy /w zz /w If w=, the reresentation is that of a vector Note that homogeneous coordinates relaces oints in three dimensions by lines through the origin in four dimensions For w=1, the reresentation of a oint is [x y z 1]

81 Homogeneous Coordinates and Comuter Grahics Homogeneous coordinates are key to all comuter grahics systems All standard transformations (rotation, translation, scaling) can be imlemented with matrix multilications using 4 x 4 matrices Hardware ieline works with 4 dimensional reresentations For orthograhic viewing, we can maintain w= for vectors and w=1 for oints For ersective we need a ersective division

82 Rotation about the z axis Rotation about z axis in three dimensions leaves all oints with the same z Equivalent to rotation in two dimensions in lanes of constant z x =x cos q y sin q y = x sin q + y cos q z =z or in homogeneous coordinates =R z (q)

83 Rotation Matrix R = R z (q) = cos sin q q sin q cos q 1 1

84 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 = R x (q) = R = R y (q) = q q q q 1 cos sin - sin cos 1 q q q q 1 cos - sin 1 sin cos

85 Scaling 1 z y x s s s S = S(s x, s y, s z ) = x =s x x y =s y x z =s z x =S Exand or contract along each axis (fixed oint of origin)

86 Reflection corresonds to negative scale factors s x = -1 s y = 1 original s x = -1 s y = -1 s x = 1 s y = -1

87 Inverses Although we could comute inverse matrices by general formulas, we can use simle geometric observations Translation: T -1 (d x, d y, d z ) = T(-d x, -d y, -d z ) 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 (s x, s y, s z ) = S(1/s x, 1/s y, 1/s z )

88 Concatenation We can form arbitrary affine transformation matrices by multilying together rotation, translation, and scaling matrices Because the same transformation is alied to many vertices, the cost of forming a matrix M=ABCD is not significant comared to the cost of comuting M for many vertices The difficult art is how to form a desired transformation from the secifications in the alication

89 Order of Transformations Note that matrix on the right is the first alied Mathematically, the following are equivalent = ABC = A(B(C)) Note many references use column matrices to reresent oints. In terms of column matrices T = T C T B T A T

90 General Rotation About the Origin A rotation by q about an arbitrary axis can be decomosed into the concatenation of rotations about the x, y, and z axes R(q) = R z (q z ) R y (q y ) R x (q x ) q x q y q z are called the Euler angles y q v Note that rotations do not commute We can use rotations in another order but with different angles z x

91 Rotation About a Fixed Point other than the Origin Move fixed oint to origin Rotate Move fixed oint back M = T( f ) R(q) T(- f )

92 Instancing In modeling, we often start with a simle object centered at the origin, oriented with the axis, and at a standard size We aly an instance transformation to its vertices to Scale Orient Locate

93 Shear Helful to add one more basic transformation Equivalent to ulling faces in oosite directions

94 Shear Matrix Consider simle shear along x axis x = x + y cot q y = y z = z q cot 1 H(q) =

95 OenGL Transformations

96 Objectives Learn how to carry out transformations in OenGL Rotation Translation Scaling Introduce OenGL matrix modes Model-view Projection

97 Clarification (by Ulf) Note that the following slides exlain the old derecated (before OenGL 3.) way to modify the modelview matrix and rojection matrix in OenGL. These were fixed function built in OenGL-matrices. Today, we instead send the modelview and rojection matrix ourselves to the vertex shader. But the rinciles of the following slides still aly. We just have to create and send the matrices to the shaders manually instead of having them built in.

98 OenGL Matrices In OenGL matrices are art of the state Multile tyes Model-View (GL_MODELVIEW) Projection (GL_PROJECTION) Texture (GL_TEXTURE) (ignore for now) Color(GL_COLOR) (ignore for now) Single set of functions for maniulation Select which to maniulated by glmatrixmode(gl_modelview); glmatrixmode(gl_projection);

99 Current Transformation Matrix (CTM) Concetually there is a 4 x 4 homogeneous coordinate matrix, the current transformation matrix (CTM) that is art of the state and is alied to all vertices that ass down the ieline The CTM is defined in the user rogram and loaded into a transformation unit vertices C CTM =C vertices

100 CTM oerations The CTM can be altered either by loading a new CTM or by ostmutilication Load an identity matrix: C I Load an arbitrary matrix: C M Load a translation matrix: C T Load a rotation matrix: C R Load a scaling matrix: C S Postmultily by an arbitrary matrix: C CM Postmultily by a translation matrix: C CT Postmultily by a rotation matrix: C C R Postmultily by a scaling matrix: C C S

101 Rotation about a Fixed Point Start with identity matrix: C I Move fixed oint to origin: C CT Rotate: C CR Move fixed oint back: C CT -1 Result: C = TR T 1 which is backwards. This result is a consequence of doing ostmultilications. Let s try again.

102 Reversing the Order We want C = T 1 R T so we must do the oerations in the following order C I C CT -1 C CR C CT Each oeration corresonds to one function call in the rogram. Note that the last oeration secified is the first executed in the rogram

103 CTM in OenGL OenGL has a model-view and a rojection matrix in the ieline which are concatenated together to form the CTM Can maniulate each by first setting the correct matrix mode

104 Rotation, Translation, Scaling Load an identity matrix: glloadidentity() Multily on right: glrotatef(theta, vx, vy, vz) theta in degrees, (vx, vy, vz) define axis of rotation gltranslatef(dx, dy, dz) glscalef( sx, sy, sz) Each has a float (f) and double (d) format (glscaled)

105 Examle Rotation about z axis by 3 degrees with a fixed oint of (1., 2., 3.) glmatrixmode(gl_modelview); glloadidentity(); gltranslatef(1., 2., 3.); glrotatef(3.,.,., 1.); gltranslatef(-1., -2., -3.); Remember that last matrix secified in the rogram is the first alied

106 Arbitrary Matrices Can load and multily by matrices defined in the alication rogram glloadmatrixf(m) glmultmatrixf(m) The matrix m is a one dimension array of 16 elements which are the comonents of the desired 4 x 4 matrix stored by columns In glmultmatrixf, m multilies the existing matrix on the right

107 Matrix Stacks In many situations we want to save transformation matrices for use later Traversing hierarchical data structures (Chater 1) Avoiding state changes when executing dislay lists OenGL maintains stacks for each tye of matrix Access resent tye (as set by glmatrixmode) by glpushmatrix() glpomatrix()

108 Reading Back Matrices Can also access matrices (and other arts of the state) by query functions glgetintegerv glgetfloatv glgetbooleanv glgetdoublev glisenabled For matrices, we use as double m[16]; glgetfloatv(gl_modelview, m);

109 Using the Model-view Matrix In OenGL the model-view matrix is used to Position the camera Can be done by rotations and translations but is often easier to use glulookat Build models of objects The rojection matrix is used to define the view volume and to select a camera lens

110 Quaternions Extension of imaginary numbers from two to three dimensions Requires one real and three imaginary comonents i, j, k q=q +q 1 i+q 2 j+q 3 k Quaternions can exress rotations on shere smoothly and efficiently. Process: Model-view matrix quaternion Carry out oerations with quaternions Quaternion Model-view matrix

111 Comuter Viewing Ed Angel Professor of Comuter Science, Electrical and Comuter Engineering, and Media Arts University of New Mexico

112 Objectives Introduce the mathematics of rojection Introduce OenGL viewing functions Look at alternate viewing APIs

113 Comuter Viewing There are three asects of the viewing rocess, all of which are imlemented in the ieline, Positioning the camera Setting the model-view matrix Selecting a lens Setting the rojection matrix Cliing Setting the view volume (default is unit cube, R 3, [-1,1])

114 Default Projection Default rojection is orthogonal 2 clied out z=

115 Moving the Camera Frame If we want to visualize object with both ositive and negative z values we can either Move the camera in the ositive z direction Translate the camera frame Move the objects in the negative z direction Translate the world frame Both of these views are equivalent and are determined by the model-view matrix Want a translation (gltranslatef(.,.,-d);) d >

116 Moving the Camera We can move the camera to any desired osition by a sequence of rotations and translations Examle: side view Rotate the camera Move it away from origin Model-view matrix C = TR

117 OenGL code Remember that last transformation secified is first to be alied glmatrixmode(gl_modelview) glloadidentity(); gltranslatef(.,., -d); glrotatef(9.,., 1.,.);

118 The LookAt Function The GLU library contains the function glulookat to form the required modelview matrix through a simle interface Note the need for setting an u direction Still need to initialize Can concatenate with modeling transformations Examle: isometric view of cube aligned with axes glmatrixmode(gl_modelview): glloadidentity(); glulookat(1., 1., 1.,.,.,.,., 1...);

119 glulookat gllookat(eyex, eyey, eyez, atx, aty, atz, ux, uy, uz)

120 Other Viewing APIs The LookAt function is only one ossible API for ositioning the camera Others include View reference oint, view lane normal, view u (PHIGS, GKS-3D) Yaw, itch, roll Elevation, azimuth, twist Direction angles

121 OenGL Orthogonal Viewing glortho(left,right,bottom,to,near,far) near and far measured from camera

122 OenGL Persective glfrustum(left,right,bottom,to,near,far )

123 Using Field of View With glfrustum it is often difficult to get the desired view gluperective(fovy, asect, near, far) often rovides a better interface front lane asect = w/h

124 Projections exlained differently Read the following slides about orthogonal and ersective rojections by your selves They resent the same thing, but exlained differently

125 Projections and Normalization The default rojection in the eye (camera) frame is orthogonal For oints within the default view volume x = x y = y z = Most grahics systems use view normalization All other views are converted to the default view by transformations that determine the rojection matrix Allows use of the same ieline for all views

126 Homogeneous Coordinate Reresentation default orthograhic rojection x = x y = y z = w = 1 M = = M In ractice, we can let M = I and set the z term to zero later

127 Simle Persective Center of rojection at the origin Projection lane z = d, d <

128 Persective Equations Consider to and side views x z / d x = z x / d y = z y / d z = d

129 Homogeneous Coordinate Form M = 1/ d consider q = M where 1 z y x d z z y x / q = =

130 Persective Division However w 1, so we must divide by w to return from homogeneous coordinates This ersective division yields x = z x / d y = z y / d z = d the desired ersective equations We will consider the corresonding cliing volume with the OenGL functions

131 Normalization Rather than derive a different rojection matrix for each tye of rojection, we can convert all rojections to orthogonal rojections with the default view volume This strategy allows us to use standard transformations in the ieline and makes for efficient cliing

132 Pieline View modelview transformation nonsingular rojection transformation ersective division 4D 3D cliing against default cube rojection 3D 2D

133 Notes We stay in four-dimensional homogeneous coordinates through both the modelview and rojection transformations Both these transformations are nonsingular Default to identity matrices (orthogonal view) Normalization lets us cli against simle cube regardless of tye of rojection Delay final rojection until end Imortant for hidden-surface removal to retain deth information as long as ossible

134 Orthogonal Normalization glortho(left,right,bottom,to,near,far) normalization find transformation to convert secified cliing volume to default

135 Two stes Orthogonal Matrix Move center to origin T(-(left+right)/2, -(bottom+to)/2,(near+far)/2)) Scale to have sides of length 2 S(2/(left-right),2/(to-bottom),2/(near-far)) P = ST = 2 right left 2 to bottom 2 near far right left right left to + bottom to bottom far + near far near 1

136 Final Projection Set z = Equivalent to the homogeneous coordinate transformation Hence, general orthogonal rojection in 4D is M orth = P = M orth ST

137 General Shear to view side view

138 Shear Matrix xy shear (z values unchanged) H(q,f) = Projection matrix General case: 1 cot θ 1 cot φ 1 1 P = M orth H(q,f) P = M orth STH(q,f)

139 Effect on Cliing The rojection matrix P = STH transforms the original cliing volume to the default cliing volume object to view z = 1 DOP cliing volume near lane far lane x = -1 z = -1 DOP x = 1 distorted object (rojects correctly)

140 Simle Persective Consider a simle ersective with the COP (=center of rojection) at the origin, the near cliing lane at z = -1, and a 9 degree field of view determined by the lanes x = z, y = z

141 Persective Matrices Simle rojection matrix in homogeneous coordinates M = Note that this matrix is indeendent of the far cliing lane

142 Generalization N = 1 1 α β 1 after ersective division, the oint (x, y, z, 1) goes to x = x/z y = y/z Z = -(+b/z) which rojects orthogonally to the desired oint regardless of and b

143 Picking and b If we ick = b = near + far far near 2near far near far the near lane is maed to z = -1 the far lane is maed to z =1 and the sides are maed to x = 1, y = 1 Hence the new cliing volume is the default cliing volume

144 Normalization Transformation distorted object rojects correctly original cliing volume original object new cliing volume

145 Normalization and Hidden-Surface Removal Although our selection of the form of the ersective matrices may aear somewhat arbitrary, it was chosen so that if z 1 > z 2 in the original cliing volume then the for the transformed oints z 1 > z 2 Thus hidden surface removal works if we first aly the normalization transformation However, the formula z = -(+b/z) imlies that the distances are distorted by the normalization which can cause numerical roblems esecially if the near distance is small

146 OenGL Persective glfrustum allows for an unsymmetric viewing frustum (although glupersective does not)

147 OenGL Persective Matrix The normalization in glfrustum requires an initial shear to form a right viewing yramid, followed by a scaling to get the normalized ersective volume. Finally, the ersective matrix results in needing only a final orthogonal transformation P = NSH our reviously defined ersective matrix shear and scale

148 Why do we do it this way? Normalization allows for a single ieline for both ersective and orthogonal viewing We stay in four dimensional homogeneous coordinates as long as ossible to retain three-dimensional information needed for hidden-surface removal and shading We simlify cliing

Vectors and Transforms

Vectors and Transforms Skämtbild om matte å KTH-animationskurs Vectors and Transforms In 3D Grahics MAP Reetition of the Rendering Pieline Geometry - er vertex: Lighting (colors) Screen sace ositions light blue Geometry red

More information

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization Overview Viewing and perspectives Classical views Computer viewing Perspective normalization Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection surface

More information

CS 4204 Computer Graphics

CS 4204 Computer Graphics CS 424 Computer Graphics 2D Transformations Yong Cao Virginia Tech References: Introduction to Computer Graphics course notes by Doug Bowman Interactive Computer Graphics, Fourth Edition, Ed Angle Transformations

More information

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

Three-Dimensional Graphics III. Guoying Zhao 1 / 67 Computer Graphics Three-Dimensional Graphics III Guoying Zhao 1 / 67 Classical Viewing Guoying Zhao 2 / 67 Objectives Introduce the classical views Compare and contrast image formation by computer with

More information

Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science Computer Viewing CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science 1 Objectives Introduce the mathematics of projection Introduce OpenGL viewing functions Look at

More information

Basic Elements. Geometry is the study of the relationships among objects in an n-dimensional space

Basic Elements. Geometry is the study of the relationships among objects in an n-dimensional space Basic Elements Geometry is the study of the relationships among objects in an n-dimensional space In computer graphics, we are interested in objects that exist in three dimensions We want a minimum set

More information

CS 428: Fall Introduction to. Geometric Transformations. Andrew Nealen, Rutgers, /15/2010 1

CS 428: Fall Introduction to. Geometric Transformations. Andrew Nealen, Rutgers, /15/2010 1 CS 428: Fall 21 Introduction to Comuter Grahics Geometric Transformations Andrew Nealen, Rutgers, 21 9/15/21 1 Toic overview Image formation and OenGL (last week) Modeling the image formation rocess OenGL

More information

Computer Viewing Computer Graphics I, Fall 2008

Computer Viewing Computer Graphics I, Fall 2008 Computer Viewing 1 Objectives Introduce mathematics of projection Introduce OpenGL viewing functions Look at alternate viewing APIs 2 Computer Viewing Three aspects of viewing process All implemented in

More information

Computer Viewing and Projection. Overview. Computer Viewing. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E.

Computer Viewing and Projection. Overview. Computer Viewing. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E. INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Computer Viewing and Projection David Carr Fundamentals of Computer Graphics Spring 24 Based on Slides by E. Angel Projection 1 L Overview Computer

More information

Transformations. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Transformations. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Transformations Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive Computer Graphics 4E Addison-Wesley 25 1 Objectives

More information

Fundamental Types of Viewing

Fundamental Types of Viewing Viewings Fundamental Types of Viewing Perspective views finite COP (center of projection) Parallel views COP at infinity DOP (direction of projection) perspective view parallel view Classical Viewing Specific

More information

CS452/552; EE465/505. Geometry Transformations

CS452/552; EE465/505. Geometry Transformations CS452/552; EE465/505 Geometry Transformations 1-26-15 Outline! Geometry: scalars, points & vectors! Transformations Read: Angel, Chapter 4 (study cube.html/cube.js example) Appendix B: Spaces (vector,

More information

3D Viewing. With acknowledge to: Ed Angel. Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

3D Viewing. With acknowledge to: Ed Angel. Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 3D Viewing With acknowledge to: Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 1 Classical Viewing Viewing plane projectors Classical

More information

Transformations. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Transformations. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science Transformations CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science 1 Objectives Introduce standard transformations - Rotation - Translation - Scaling - Shear Derive

More information

BASIC ELEMENTS. Geometry is the study of the relationships among objects in an n-dimensional space

BASIC ELEMENTS. Geometry is the study of the relationships among objects in an n-dimensional space GEOMETRY 1 OBJECTIVES Introduce the elements of geometry Scalars Vectors Points Look at the mathematical operations among them Define basic primitives Line segments Polygons Look at some uses for these

More information

521493S Computer Graphics Exercise 3 (Chapters 6-8)

521493S Computer Graphics Exercise 3 (Chapters 6-8) 521493S Comuter Grahics Exercise 3 (Chaters 6-8) 1 Most grahics systems and APIs use the simle lighting and reflection models that we introduced for olygon rendering Describe the ways in which each of

More information

Lecture 4: Transformations and Matrices. CSE Computer Graphics (Fall 2010)

Lecture 4: Transformations and Matrices. CSE Computer Graphics (Fall 2010) Lecture 4: Transformations and Matrices CSE 40166 Computer Graphics (Fall 2010) Overall Objective Define object in object frame Move object to world/scene frame Bring object into camera/eye frame Instancing!

More information

Objectives. transformation. General Transformations. Affine Transformations. Notation. Pipeline Implementation. Introduce standard transformations

Objectives. transformation. General Transformations. Affine Transformations. Notation. Pipeline Implementation. Introduce standard transformations Objectives Transformations CS Interactive Computer Graphics Prof. David E. Breen Department of Computer Science Introduce standard transformations - Rotation - Translation - Scaling - Shear Derive homogeneous

More information

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1 Transformations 1-1 Transformations are used within the entire viewing pipeline: Projection from world to view coordinate system View modifications: Panning Zooming Rotation 1-2 Transformations can also

More information

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics I. Guoying Zhao 1 / 52

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics I. Guoying Zhao 1 / 52 Computer Graphics Three-Dimensional Graphics I Guoying Zhao 1 / 52 Geometry Guoying Zhao 2 / 52 Objectives Introduce the elements of geometry Scalars Vectors Points Develop mathematical operations among

More information

CS D Transformation. Junqiao Zhao 赵君峤

CS D Transformation. Junqiao Zhao 赵君峤 CS10101001 3D Transformation Junqiao Zhao 赵君峤 Department of Computer Science and Technology College of Electronics and Information Engineering Tongji University Review Translation Linear transformation

More information

Introduction to Computer Graphics with WebGL

Introduction to Computer Graphics with WebGL Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science Laboratory University of New Mexico WebGL Transformations

More information

Clipping. Administrative. Assignment 1 Gallery. Questions about previous lectures? Overview of graphics pipeline? Assignment 2

Clipping. Administrative. Assignment 1 Gallery. Questions about previous lectures? Overview of graphics pipeline? Assignment 2 Cliing MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy of Leonard McMillan MIT EECS 6.837, Teller and Durand 1 MIT EECS 6.837, Teller and Durand 2 Administrative Assignment

More information

Transformations. Overview. Standard Transformations. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E.

Transformations. Overview. Standard Transformations. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E. INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Transformations David Carr Fundamentals of Computer Graphics Spring 24 Based on Slides by E. Angel Feb-1-4 SMD159, Transformations 1 L Overview

More information

Order of Transformations

Order of Transformations Order of Transformations 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 Note

More information

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015 Orthogonal Projection Matrices 1 Objectives Derive the projection matrices used for standard orthogonal projections Introduce oblique projections Introduce projection normalization 2 Normalization Rather

More information

To Do. Computer Graphics (Fall 2004) Course Outline. Course Outline. Motivation. Motivation

To Do. Computer Graphics (Fall 2004) Course Outline. Course Outline. Motivation. Motivation Comuter Grahics (Fall 24) COMS 416, Lecture 3: ransformations 1 htt://www.cs.columbia.edu/~cs416 o Do Start (thinking about) assignment 1 Much of information ou need is in this lecture (slides) Ask A NOW

More information

Transformations. Standard Transformations. David Carr Virtual Environments, Fundamentals Spring 2005 Based on Slides by E. Angel

Transformations. Standard Transformations. David Carr Virtual Environments, Fundamentals Spring 2005 Based on Slides by E. Angel INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Transformations David Carr Virtual Environments, Fundamentals Spring 25 Based on Slides by E. Angel Jan-27-5 SMM9, Transformations 1 L Overview

More information

MAP. Vectors and Transforms. Reading instructions Quick Repetition of Vector Algebra. In 3D Graphics. Repetition of the Rendering Pipeline

MAP. Vectors and Transforms. Reading instructions Quick Repetition of Vector Algebra. In 3D Graphics. Repetition of the Rendering Pipeline 79 MAP Skämtbil om matte å KTHanimationskurs Vectors an Transforms In 3D Grahics Reetition of the Renering Pieline Geometr er verte: Lighting (colors) Screen sace ositions Reetition of the Renering Pieline

More information

Geometry. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Geometry. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Geometry Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 1 Objectives Introduce the elements of geometry - Scalars - Vectors - Points

More information

CSE4421/5324: Introduction to Robotics

CSE4421/5324: Introduction to Robotics CSE442/5324: Introduction to Robotics Contact Information Burton Ma Lassonde 246 burton@cse.yorku.ca EECS442/5324 lectures Monday, Wednesday, Friday :3-2:3PM (SLH C) Lab Thursday 2:3-2:3, Prism 4 Lab 2

More information

Introduction to Computer Graphics 4. Viewing in 3D

Introduction to Computer Graphics 4. Viewing in 3D Introduction to Computer Graphics 4. Viewing in 3D National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor Textbook: E.Angel, Interactive Computer Graphics, 5 th Ed., Addison Wesley Ref: Hearn

More information

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York Computer Viewing Prof. George Wolberg Dept. of Computer Science City College of New York Objectives Introduce the mathematics of projection Introduce OpenGL viewing functions Look at alternate viewing

More information

Geometry. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Geometry. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science Geometry CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012. 1 Objectives Introduce

More information

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Objectives Learn how to implement transformations

More information

CS354 Computer Graphics Viewing and Modeling

CS354 Computer Graphics Viewing and Modeling Slide Credit: Donald S. Fussell CS354 Computer Graphics Viewing and Modeling Qixing Huang February 21th 2018 Computer Viewing There are three aspects of the viewing process, all of which are implemented

More information

part 3 Martin Samuelčík Room I4

part 3 Martin Samuelčík  Room I4 art 3 Martin Sauelčík htt://www.sccg.sk/~sauelcik Roo I4 Vertex coordinates Fro inut coordinates to window coordinates Coordinates are always related to coordinates syste, sace, frae Transforing vertex

More information

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics. Bing-Yu Chen National Taiwan University Computer Graphics Bing-Yu Chen National Taiwan University Introduction to OpenGL General OpenGL Introduction An Example OpenGL Program Drawing with OpenGL Transformations Animation and Depth Buffering

More information

Transformations. CSCI 420 Computer Graphics Lecture 4

Transformations. CSCI 420 Computer Graphics Lecture 4 CSCI 420 Computer Graphics Lecture 4 Transformations Jernej Barbic University of Southern California Vector Spaces Euclidean Spaces Frames Homogeneous Coordinates Transformation Matrices [Angel, Ch. 4]

More information

CS452/552; EE465/505. Transformations

CS452/552; EE465/505. Transformations CS452/552; EE465/55 Transformations 1-29-15 Outline! Transformations Read: Angel, Chapter 4 (study cube.html/cube.js example) Helpful links: Linear Algebra: Khan Academy Lab1 is posted on github, due:

More information

Cross products. p 2 p. p p1 p2. p 1. Line segments The convex combination of two distinct points p1 ( x1, such that for some real number with 0 1,

Cross products. p 2 p. p p1 p2. p 1. Line segments The convex combination of two distinct points p1 ( x1, such that for some real number with 0 1, CHAPTER 33 Comutational Geometry Is the branch of comuter science that studies algorithms for solving geometric roblems. Has alications in many fields, including comuter grahics robotics, VLSI design comuter

More information

Lecture 3: Geometric Algorithms(Convex sets, Divide & Conquer Algo.)

Lecture 3: Geometric Algorithms(Convex sets, Divide & Conquer Algo.) Advanced Algorithms Fall 2015 Lecture 3: Geometric Algorithms(Convex sets, Divide & Conuer Algo.) Faculty: K.R. Chowdhary : Professor of CS Disclaimer: These notes have not been subjected to the usual

More information

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI) Computer Graphics (CS 47) Lecture : Implementing Transformations Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Objectives Learn how to implement transformations in OpenGL

More information

CSC 470 Computer Graphics

CSC 470 Computer Graphics CSC 470 Computer Graphics Transformations of Objects CSC 470 Computer Graphics, Dr.N. Georgieva, CSI/CUNY 1 Transformations of objects - 2D CSC 470 Computer Graphics, Dr.N. Georgieva, CSI/CUNY 2 Using

More information

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera UNIT - 6 7 hrs VIEWING Classical and computer viewing Viewing with a computer Positioning of the camera Simple projections Projections in OpenGL Hiddensurface removal Interactive mesh displays Parallelprojection

More information

Fall CSCI 420: Computer Graphics. 2.2 Transformations. Hao Li.

Fall CSCI 420: Computer Graphics. 2.2 Transformations. Hao Li. Fall 2017 CSCI 420: Computer Graphics 2.2 Transformations Hao Li http://cs420.hao-li.com 1 OpenGL Transformations Matrices Model-view matrix (4x4 matrix) Projection matrix (4x4 matrix) vertices in 3D Model-view

More information

Introduction to Computer Graphics with WebGL

Introduction to Computer Graphics with WebGL Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science Laboratory University of New Mexico 1 Computer Viewing

More information

Dr Pavan Chakraborty IIIT-Allahabad

Dr Pavan Chakraborty IIIT-Allahabad GVC-43 Lecture - 5 Ref: Donald Hearn & M. Pauline Baker, Comuter Grahics Foley, van Dam, Feiner & Hughes, Comuter Grahics Princiles & Practice Dr Pavan Chakraborty IIIT-Allahabad Summary of line drawing

More information

CS335 Fall 2007 Graphics and Multimedia. 2D Drawings: Lines

CS335 Fall 2007 Graphics and Multimedia. 2D Drawings: Lines CS335 Fall 007 Grahics and Multimedia D Drawings: Lines Primitive Drawing Oerations Digital Concets of Drawing in Raster Arras PIXEL is a single arra element at x, - No smaller drawing unit exists Px,

More information

Transformations Computer Graphics I Lecture 4

Transformations Computer Graphics I Lecture 4 15-462 Computer Graphics I Lecture 4 Transformations Vector Spaces Affine and Euclidean Spaces Frames Homogeneous Coordinates Transformation Matrices January 23, 2003 [Angel, Ch. 4] Frank Pfenning Carnegie

More information

Illumination Model. The governing principles for computing the. Apply the lighting model at a set of points across the entire surface.

Illumination Model. The governing principles for computing the. Apply the lighting model at a set of points across the entire surface. Illumination and Shading Illumination (ighting) Model the interaction of light with surface oints to determine their final color and brightness OenG comutes illumination at vertices illumination Shading

More information

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益 Modeling Transform Chapter 4 Geometric Transformations 李同益 Specify transformation for objects Allow definitions of objects in own coordinate systems Allow use of object definition multiple times in a scene

More information

Transformations. CSCI 420 Computer Graphics Lecture 5

Transformations. CSCI 420 Computer Graphics Lecture 5 CSCI 420 Computer Graphics Lecture 5 Transformations Jernej Barbic University of Southern California Vector Spaces Euclidean Spaces Frames Homogeneous Coordinates Transformation Matrices [Angel, Ch. 3]

More information

CMSC 425: Lecture 16 Motion Planning: Basic Concepts

CMSC 425: Lecture 16 Motion Planning: Basic Concepts : Lecture 16 Motion lanning: Basic Concets eading: Today s material comes from various sources, including AI Game rogramming Wisdom 2 by S. abin and lanning Algorithms by S. M. LaValle (Chats. 4 and 5).

More information

Transformations. OpenGL Transformations. 4x4 Model-view Matrix (this lecture) OpenGL Transformation Matrices. 4x4 Projection Matrix (next lecture)

Transformations. OpenGL Transformations. 4x4 Model-view Matrix (this lecture) OpenGL Transformation Matrices. 4x4 Projection Matrix (next lecture) CSCI 420 Computer Graphics Lecture 5 OpenGL Transformations Transformations Vector Spaces Euclidean Spaces Frames Homogeneous Coordinates Transformation Matrices Jernej Barbic [Angel, Ch. 3] University

More information

Last week. Machiraju/Zhang/Möller/Fuhrmann

Last week. Machiraju/Zhang/Möller/Fuhrmann Last week Machiraju/Zhang/Möller/Fuhrmann 1 Geometry basics Scalar, point, and vector Vector space and affine space Basic point and vector operations Sided-ness test Lines, planes, and triangles Linear

More information

Graphics and Interaction Transformation geometry and homogeneous coordinates

Graphics and Interaction Transformation geometry and homogeneous coordinates 433-324 Graphics and Interaction Transformation geometry and homogeneous coordinates Department of Computer Science and Software Engineering The Lecture outline Introduction Vectors and matrices Translation

More information

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates Department of Computer Science and Software Engineering The Lecture outline Introduction Vectors and matrices Translation

More information

Course no. DIS4566 National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor

Course no. DIS4566 National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor Computer Graphics 3. Viewing in 3D (b) Course no. DIS4566 National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor Textbook: E.Angel, Interactive Computer Graphics, 4 th Ed., Addison Wesley

More information

Convex Hulls. Helen Cameron. Helen Cameron Convex Hulls 1/101

Convex Hulls. Helen Cameron. Helen Cameron Convex Hulls 1/101 Convex Hulls Helen Cameron Helen Cameron Convex Hulls 1/101 What Is a Convex Hull? Starting Point: Points in 2D y x Helen Cameron Convex Hulls 3/101 Convex Hull: Informally Imagine that the x, y-lane is

More information

Shuigeng Zhou. May 18, 2016 School of Computer Science Fudan University

Shuigeng Zhou. May 18, 2016 School of Computer Science Fudan University Query Processing Shuigeng Zhou May 18, 2016 School of Comuter Science Fudan University Overview Outline Measures of Query Cost Selection Oeration Sorting Join Oeration Other Oerations Evaluation of Exressions

More information

Chapter 3: Graphics Output Primitives. OpenGL Line Functions. OpenGL Point Functions. Line Drawing Algorithms

Chapter 3: Graphics Output Primitives. OpenGL Line Functions. OpenGL Point Functions. Line Drawing Algorithms Chater : Grahics Outut Primitives Primitives: functions in grahics acage that we use to describe icture element Points and straight lines are the simlest rimitives Some acages include circles, conic sections,

More information

Computer Graphics Geometric Transformations

Computer Graphics Geometric Transformations Computer Graphics 2016 6. Geometric Transformations Hongxin Zhang State Key Lab of CAD&CG, Zhejiang University 2016-10-31 Contents Transformations Homogeneous Co-ordinates Matrix Representations of Transformations

More information

Transformations Computer Graphics I Lecture 4

Transformations Computer Graphics I Lecture 4 15-462 Computer Graphics I Lecture 4 Transformations Vector Spaces Affine and Euclidean Spaces Frames Homogeneous Coordinates Transformation Matrices January 24, 2002 [Angel, Ch. 4] Frank Pfenning Carnegie

More information

Computer Graphics. Chapter 5 Geometric Transformations. Somsak Walairacht, Computer Engineering, KMITL

Computer Graphics. Chapter 5 Geometric Transformations. Somsak Walairacht, Computer Engineering, KMITL Chapter 5 Geometric Transformations Somsak Walairacht, Computer Engineering, KMITL 1 Outline Basic Two-Dimensional Geometric Transformations Matrix Representations and Homogeneous Coordinates Inverse Transformations

More information

CS 450: COMPUTER GRAPHICS 2D TRANSFORMATIONS SPRING 2016 DR. MICHAEL J. REALE

CS 450: COMPUTER GRAPHICS 2D TRANSFORMATIONS SPRING 2016 DR. MICHAEL J. REALE CS 45: COMUTER GRAHICS 2D TRANSFORMATIONS SRING 26 DR. MICHAEL J. REALE INTRODUCTION Now that we hae some linear algebra under our resectie belts, we can start ug it in grahics! So far, for each rimitie,

More information

Viewing and Modeling

Viewing and Modeling Viewing and Modeling Computer Science Department The Universit of Texas at Austin A Simplified Graphics ipeline Application Vertex batching & assembl Triangle assembl Triangle clipping NDC to window space

More information

CS 432 Interactive Computer Graphics

CS 432 Interactive Computer Graphics CS 432 Interactive Computer Graphics Lecture 4 3D Viewing Matt Burlick - Drexel University - CS 432 1 Reading Angel Chapters 3-4 Red Book Chapter 5, Appendix E Matt Burlick - Drexel University - CS 432

More information

Lecture 7: Objects (Chapter 15) CS 1110 Introduction to Computing Using Python

Lecture 7: Objects (Chapter 15) CS 1110 Introduction to Computing Using Python htt://www.cs.cornell.edu/courses/cs1110/2018s Lecture 7: Objects (Chater 15) CS 1110 Introduction to Comuting Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]

More information

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley Computer Viewing CITS3003 Graphics & Animation E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012 1 Objectives Introduce the mathematics of projection Introduce OpenGL viewing

More information

Last week. Machiraju/Zhang/Möller

Last week. Machiraju/Zhang/Möller Last week Machiraju/Zhang/Möller 1 Overview of a graphics system Output device Input devices Image formed and stored in frame buffer Machiraju/Zhang/Möller 2 Introduction to CG Torsten Möller 3 Ray tracing:

More information

COT5405: GEOMETRIC ALGORITHMS

COT5405: GEOMETRIC ALGORITHMS COT5405: GEOMETRIC ALGORITHMS Objects: Points in, Segments, Lines, Circles, Triangles Polygons, Polyhedra R n Alications Vision, Grahics, Visualizations, Databases, Data mining, Networks, GIS Scientific

More information

Computer Graphics. Computer Graphics. Lecture 3 Line & Circle Drawing

Computer Graphics. Computer Graphics. Lecture 3 Line & Circle Drawing Comuter Grahics Comuter Grahics Lecture 3 Line & Circle Drawing Comuter Grahics Towards the Ideal Line We can onl do a discrete aroimation Illuminate iels as close to the true ath as ossible, consider

More information

Lecture 9: Transformations. CITS3003 Graphics & Animation

Lecture 9: Transformations. CITS3003 Graphics & Animation Lecture 9: Transformations CITS33 Graphics & Animation E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 212 Objectives Introduce standard transformations Rotation Translation Scaling

More information

Realtime 3D Computer Graphics Virtual Reality

Realtime 3D Computer Graphics Virtual Reality Realtime 3D Comuter Grahics Virtual Realit Viewing an rojection Classical an General Viewing Transformation Pieline CPU CPU Pol. Pol. DL DL Piel Piel Per Per Verte Verte Teture Teture Raster Raster Frag

More information

3D Viewing. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

3D Viewing. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller 3D Viewing CMPT 361 Introduction to Computer Graphics Torsten Möller Reading Chapter 4 of Angel Chapter 6 of Foley, van Dam, 2 Objectives What kind of camera we use? (pinhole) What projections make sense

More information

Computer Graphics. Chapter 7 2D Geometric Transformations

Computer Graphics. Chapter 7 2D Geometric Transformations Computer Graphics Chapter 7 2D Geometric Transformations Chapter 7 Two-Dimensional Geometric Transformations Part III. OpenGL Functions for Two-Dimensional Geometric Transformations OpenGL Geometric Transformation

More information

Geometry. Prof. George Wolberg Dept. of Computer Science City College of New York

Geometry. Prof. George Wolberg Dept. of Computer Science City College of New York Geometry Prof. George Wolberg Dept. of Computer Science City College of New York Objectives Introduce the elements of geometry -Scalars - Vectors - Points Develop mathematical operations among them in

More information

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI) Computer Graphics (CS 47) Lecture : Implementing Transformations Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Objectives Learn how to implement transformations in OpenGL

More information

3D Viewing. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

3D Viewing. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller 3D Viewing Introduction to Computer Graphics Torsten Möller Machiraju/Zhang/Möller Reading Chapter 4 of Angel Chapter 13 of Hughes, van Dam, Chapter 7 of Shirley+Marschner Machiraju/Zhang/Möller 2 Objectives

More information

Introduction to Computer Graphics with WebGL

Introduction to Computer Graphics with WebGL 1 Introduction to Computer Graphics with WebGL Ed Angel Transformations General Transformations A transformation maps points to other points and/or vectors to other vectors v=t(u) Q=T(P) 2 Affine Transformations

More information

To Do. Outline. Translation. Homogeneous Coordinates. Foundations of Computer Graphics. Representation of Points (4-Vectors) Start doing HW 1

To Do. Outline. Translation. Homogeneous Coordinates. Foundations of Computer Graphics. Representation of Points (4-Vectors) Start doing HW 1 Foundations of Computer Graphics Homogeneous Coordinates Start doing HW 1 To Do Specifics of HW 1 Last lecture covered basic material on transformations in 2D Likely need this lecture to understand full

More information

Virtual Cameras & Their Matrices

Virtual Cameras & Their Matrices Virtual Cameras & Their Matrices J.Tumblin-Modified, highly edited SLIDES from: Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 What is Projection? Any operation that reduces

More information

Trigonometric Functions

Trigonometric Functions Similar Right-Angled Triangles Trigonometric Functions We lan to introduce trigonometric functions as certain ratios determined by similar right-angled triangles. By de nition, two given geometric gures

More information

Computer Graphics. Viewing. Fundamental Types of Viewing. Perspective views. Parallel views. October 12, finite COP (center of projection)

Computer Graphics. Viewing. Fundamental Types of Viewing. Perspective views. Parallel views. October 12, finite COP (center of projection) Comuter Grahics Viewing October 2, 25 htt://www.hallm.ac.kr/~sunkim/teach/25/cga Funamental Tes of Viewing Persective views finite COP (center of rojection) Parallel views COP at infinit DOP (irection

More information

Vectors and Transforms

Vectors and Transforms Skätbild o atte å KTH-aniationskurs Vectors and Transfors In 3D Grahics Course Structure 14 lectures Book is the verbal forat / ore eticulous elanations Lecture slides are onl short suar Perhas not enough

More information

GEOMETRIC CONSTRAINT SOLVING IN < 2 AND < 3. Department of Computer Sciences, Purdue University. and PAMELA J. VERMEER

GEOMETRIC CONSTRAINT SOLVING IN < 2 AND < 3. Department of Computer Sciences, Purdue University. and PAMELA J. VERMEER GEOMETRIC CONSTRAINT SOLVING IN < AND < 3 CHRISTOPH M. HOFFMANN Deartment of Comuter Sciences, Purdue University West Lafayette, Indiana 47907-1398, USA and PAMELA J. VERMEER Deartment of Comuter Sciences,

More information

Affine Transformations in 3D

Affine Transformations in 3D Affine Transformations in 3D 1 Affine Transformations in 3D 1 Affine Transformations in 3D General form 2 Translation Elementary 3D Affine Transformations 3 Scaling Around the Origin 4 Along x-axis Shear

More information

Translation. 3D Transformations. Rotation about z axis. Scaling. CS 4620 Lecture 8. 3 Cornell CS4620 Fall 2009!Lecture 8

Translation. 3D Transformations. Rotation about z axis. Scaling. CS 4620 Lecture 8. 3 Cornell CS4620 Fall 2009!Lecture 8 Translation 3D Transformations CS 4620 Lecture 8 1 2 Scaling Rotation about z axis 3 4 Rotation about x axis Rotation about y axis 5 6 Transformations in OpenGL Stack-based manipulation of model-view transformation,

More information

COMP3421. Introduction to 3D Graphics

COMP3421. Introduction to 3D Graphics COMP3421 Introduction to 3D Graphics 3D coodinates Moving to 3D is simply a matter of adding an extra dimension to our points and vectors: 3D coordinates 3D coordinate systems can be left or right handed.

More information

CS452/552; EE465/505. Intro to Lighting

CS452/552; EE465/505. Intro to Lighting CS452/552; EE465/505 Intro to Lighting 2-10 15 Outline! Projection Normalization! Introduction to Lighting (and Shading) Read: Angel Chapter 5., sections 5.4-5.7 Parallel Projections Chapter 6, sections

More information

Representations and Transformations. Objectives

Representations and Transformations. Objectives Repreentation and Tranformation Objective Derive homogeneou coordinate tranformation matrice Introduce tandard tranformation - Rotation - Tranlation - Scaling - Shear Scalar, Point, Vector Three baic element

More information

Objectives. Geometry. Basic Elements. Coordinate-Free Geometry. Transformations to Change Coordinate Systems. Scalars

Objectives. Geometry. Basic Elements. Coordinate-Free Geometry. Transformations to Change Coordinate Systems. Scalars Objecties Geometry CS 432 Interactie Computer Graphics Prof. Daid E. Breen Department of Computer Science Introduce the elements of geometry - Scalars - Vectors - Points Deelop mathematical operations

More information

xy plane was set to coincide with the dorsal surface of the pronotum. (4) The locust coordinate

xy plane was set to coincide with the dorsal surface of the pronotum. (4) The locust coordinate 4 5 6 7 8 9 0 4 5 6 7 8 9 0 Sulementary text Coordinate systems and kinematic analysis. Four coordinate systems were defined in order to analyse data obtained from the video (Fig. S): () the video coordinate

More information

We will then introduce the DT, discuss some of its fundamental properties and show how to compute a DT directly from a given set of points.

We will then introduce the DT, discuss some of its fundamental properties and show how to compute a DT directly from a given set of points. Voronoi Diagram and Delaunay Triangulation 1 Introduction The Voronoi Diagram (VD, for short) is a ubiquitious structure that aears in a variety of discilines - biology, geograhy, ecology, crystallograhy,

More information

Cross products Line segments The convex combination of two distinct points p

Cross products Line segments The convex combination of two distinct points p CHAPTER Comutational Geometry Is the branch of comuter science that studies algorithms for solving geometric roblems. Has alications in many fields, including comuter grahics robotics, VLSI design comuter

More information

Objectives. Geometry. Coordinate-Free Geometry. Basic Elements. Transformations to Change Coordinate Systems. Scalars

Objectives. Geometry. Coordinate-Free Geometry. Basic Elements. Transformations to Change Coordinate Systems. Scalars Objecties Geometry CS Interactie Computer Graphics Prof. Daid E. Breen Department of Computer Science Introduce the elements of geometry - Scalars - Vectors - Points Deelop mathematical operations among

More information

5.8.3 Oblique Projections

5.8.3 Oblique Projections 278 Chapter 5 Viewing y (, y, ) ( p, y p, p ) Figure 537 Oblique projection P = 2 left right 0 0 left+right left right 0 2 top bottom 0 top+bottom top bottom far+near far near 0 0 far near 2 0 0 0 1 Because

More information

Jorg s Graphics Lecture Notes Coordinate Spaces 1

Jorg s Graphics Lecture Notes Coordinate Spaces 1 Jorg s Graphics Lecture Notes Coordinate Spaces Coordinate Spaces Computer Graphics: Objects are rendered in the Euclidean Plane. However, the computational space is better viewed as one of Affine Space

More information

Rasterization, Depth Sorting and Culling

Rasterization, Depth Sorting and Culling Rasterization, Depth Sorting and Culling Rastrerzation How can we determine which pixels to fill? Reading Material These slides OH 17-26, OH 65-79 and OH 281-282, by Magnus Bondesson You may also read

More information