CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.

Slides:



Advertisements
Similar presentations
Computer Graphics: 3D Transformations
Advertisements

CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
David Breen, William Regli and Maxim Peysakhov
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
Chapter 7: Vectors and the Geometry of Space
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Chapter 4.1 Mathematical Concepts
CS 376 Introduction to Computer Graphics 02 / 07 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 24 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 09 / 2007 Instructor: Michael Eckmann.
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
CS 376b Introduction to Computer Vision 04 / 11 / 2008 Instructor: Michael Eckmann.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Two Dimensional Viewing Dr. Eng. Farag Elnagahy
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
CS 376 Introduction to Computer Graphics 02 / 26 / 2007 Instructor: Michael Eckmann.
CS 376b Introduction to Computer Vision 04 / 15 / 2008 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann.
CS 376b Introduction to Computer Vision 03 / 04 / 2008 Instructor: Michael Eckmann.
CS 376b Introduction to Computer Vision 03 / 04 / 2008 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 04 / 2007 Instructor: Michael Eckmann.
11 Analytic Geometry in Three Dimensions
Chapter 7: Vectors and the Geometry of Space
Vectors and the Geometry of Space
Chapter 3 Vectors.
Mathematical Fundamentals
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
Chapter 6 ADDITIONAL TOPICS IN TRIGONOMETRY. 6.1 Law of Sines Objectives –Use the Law of Sines to solve oblique triangles –Use the Law of Sines to solve,
ME 2304: 3D Geometry & Vector Calculus
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Transformation of Graphics
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Two-Dimensional Viewing
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
Dx = 2 dy = 3 Y X D Translation A translation is applied to an object by repositioning it along a straight-line path.
CS 325 Introduction to Computer Graphics 02 / 17 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 26 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
©Larry F. Hodges (modified by Amos Johnson) 1 3-D Mathematical Preliminaries & Transformations.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 22 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 26 / 2010 Instructor: Michael Eckmann.
Chapter 3 Vectors. Vector quantities  Physical quantities that have both numerical and directional properties Mathematical operations of vectors in this.
CS 551 / 645: Introductory Computer Graphics Mathematical Foundations.
EEL Introduction to Computer Graphics
Geometric Transformations
12/24/2015 A.Aruna/Assistant professor/IT/SNSCE 1.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
CSCI 425/ D Mathematical Preliminaries. CSCI 425/525 2 Coordinate Systems Z X Y Y X Z Right-handed coordinate system Left-handed coordinate system.
CSCE 552 Fall 2012 Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
Vectors and the Geometry of Space Section 10.4 Lines and Planes in Space 2015.
Ta: Ryan Freedman Sushma Kini Chi Zhou.  Pipeline  Clipping  Transformation, homogeneous coordinates  Lighting  Perspective  Viewing.
CS 376 Introduction to Computer Graphics 02 / 21 / 2007 Instructor: Michael Eckmann.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann.
Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphic 2 D Viewing.
Math Fundamentals Maths revisit.
Transformations contd.
11 Vectors and the Geometry of Space
Presentation transcript:

CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann

Michael Eckmann - Skidmore College - CS Spring 2007 Today’s Topics Questions? Programming assignment 02 posted Clipping lines with Liang Barsky Clipping polygons 3d –right handed vs. left handed coordinate systems –3 dimensional vectors –dot product –cross product –parametric equation of a line in 3 dimensions –equation of a plane in 3 dimensions

Michael Eckmann - Skidmore College - CS Spring 2007 Clipping Liang-Barsky line clipping –based on parametric equation of a line given end points (x 0, y 0 ) and (x end, y end ) the parametric equations of a line are: x = x 0 + u (x end – x 0 ) y = y 0 + u (y end – y 0 ) 0 <= u <= 1 –recall that our clipping window has the following vertices in the world (xL, yB), (xR, yB), (xR, yT), (xL, yT) –and a point (x,y) is visible if xL <= x <= xR yB <= y <= yT –replace the parametric equations for x and y in those inequalites xL <= x 0 + u (x end – x 0 ) <= xR yB <= y 0 + u (y end – y 0 ) <= yT

Michael Eckmann - Skidmore College - CS Spring 2007 Liang-Barsky Line Clipping xL <= x 0 + u (x end – x 0 ) <= xR yB <= y 0 + u (y end – y 0 ) <= yT –which can be expressed as 4 inequalities of the form u p k <= q k, where k = 1, 2, 3, or 4 and –p 1 = (x 0 – x end ) p 2 = (x end – x 0 ) p 3 = (y 0 – y end ) p 4 = (y end – y 0 ) –q 1 = (x 0 – xL) q 2 = (xR – x 0 ) q 3 = (y 0 – yB) q 4 = (yT – y 0 ) example: xL <= x 0 + u (x end – x 0 ) subtract x 0 from both sides: xL – x 0 <= u (x end – x 0 ) multiply both sides by –1 and reverse the = : x 0 – xL >= u (x 0 – x end ) which is the same as: u (x 0 – x end ) <= x 0 – xL which is: u p 1 < = q 1

Michael Eckmann - Skidmore College - CS Spring 2007 Liang-Barsky Line Clipping xL <= x 0 + u (x end – x 0 ) <= xR yB <= y 0 + u (y end – y 0 ) <= yT –which can be expressed as 4 inequalities of the form u p k <= q k, where k = 1, 2, 3, or 4 and –p 1 = (x 0 – x end ) p 2 = (x end – x 0 ) p 3 = (y 0 – y end ) p 4 = (y end – y 0 ) –q 1 = (x 0 – xL) q 2 = (xR – x 0 ) q 3 = (y 0 – yB) q 4 = (yT – y 0 ) –a line parallel to a clipping edge has p k = 0, where k represents the edge to which it is parallel: 1=Left, 2=Right, 3=Bottom, 4=Top –if (p k == 0 and q k < 0) then line completely outside boundary, done –if (p k == 0 and q k >= 0) then the line is inside the boundary –if (p k < 0) then the line goes from outside to inside of the infinite extension of a clipping window edge –if (p k > 0) then the line goes from inside to outside of the infinite extension of a clipping window edge

Michael Eckmann - Skidmore College - CS Spring 2007 Liang-Barsky Line Clipping –Recall what k's mean: 1=Left, 2=Right, 3=Bottom, 4=Top –when p k is non-zero, we find the intersection of the line with the infinite extension of the clipping window edge k recall that u p k <= q k so this intersection is simply when u = q k /p k –initialize u 1 to be 0 and u 2 to be 1 –For each of the four infinite extensions of a clipping window edge we calculate either r 1 or r 2 r 1 is the u parameter for the intersection of the line with the edge when coming from the outside of the clipping window to the inside (p < 0) r 2 is the u parameter for the intersection of the line with the edge when coming from the inside of the clipping window to the outside (p > 0) if p u1) if p>0, update u2 to be r2 if it results in a shorter line (i.e. if r2 < u2) if u1 > u2 we reject the line, and we're done. –if it makes it through all four boundary checks without rejection, then the line to be drawn is between u1 and u2.

Michael Eckmann - Skidmore College - CS Spring 2007 Liang-Barsky Line Clipping Example of Liang-Barsky line clipping algorithm in action –(x 0,y 0 ) = (10,5) –(x end,y end ) = (30,30) –Clipping window: xL = 20, xR = 35, yB = 10, yT = 20. –p 1 = (x 0 – x end ) = -20 –p 2 = (x end – x 0 ) = 20 –p 3 = (y 0 – y end ) = -25 –p 4 = (y end – y 0 ) = 25 –q 1 = (x 0 – xL) = -10 –q 2 = (xR – x 0 ) = 25 –q 3 = (y 0 – yB) = -5 –q 4 = (yT – y 0 ) = 15 –u 1 = 0 and u 2 = 1 to start, let's run the algorithm on the board

Michael Eckmann - Skidmore College - CS Spring 2007 Liang-Barsky Line Clipping Another example –(x 0,y 0 ) = (10,18) –(x end,y end ) = (25,25) –Clipping window: xL = 20, xR = 35, yB = 10, yT = 20. –p 1 = (x 0 – x end ) = -15 –p 2 = (x end – x 0 ) = 15 –p 3 = (y 0 – y end ) = -17 –p 4 = (y end – y 0 ) = 17 –q 1 = (x 0 – xL) = -10 –q 2 = (xR – x 0 ) = 25 –q 3 = (y 0 – yB) = 8 –q 4 = (yT – y 0 ) = 2 –u 1 = 0 and u 2 = 1 to start, let's run the algorithm on the board

Michael Eckmann - Skidmore College - CS Spring 2007 Line Clipping Liang-Barsky (L-B) vs. Cohen-Sutherland (C-S) –L-B in general more efficient updates of u1 & u2 require only one divide window edge intersections are computed only once when u1 & u2 are final –C-S repeatedly calcs intersections along a line path even though line may be completely outside clipping window each intersection calc requires a divide and a multiply Both line clipping algorithms can be extended to 3-d A third line clipping algorithm, Nicholl-Lee-Nicholl (N-L-N), which we will not go into is faster than both L-B & C-S but it cannot be extended to 3-d.

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon Clipping Polygon clipping –Polygons can be clipped against successive infinite extensions of the clipping window edges –Keep track of new vertices (intersections with edge of clipping window) at each stage. –Notice the number of vertices increased in the example below.

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon Clipping

Michael Eckmann - Skidmore College - CS Spring 2007 Polygon Clipping The text describes two polygon clipping algorithms. The Sutherland-Hodgman algorithm and the Weiler-Atherton algorithm. A major difference between the two is that the Sutherland-Hodgman algorithm produces as output one polygon. Think about a concave polygon that when clipped, really should result in two polygons. Example on board.

Michael Eckmann - Skidmore College - CS Spring d math (Ch. 5, Appdx A, Sec. 3-15) Coordinate systems Vectors Lines Plane Homogeneous Coordinates of a 3d point Transformations –Translation –Scaling –Rotation (about x, y, z) –Shear (in xy)

Michael Eckmann - Skidmore College - CS Spring 2007 Right-handed 3d coordinate system

Michael Eckmann - Skidmore College - CS Spring 2007 Left-handed 3d coordinate system

Michael Eckmann - Skidmore College - CS Spring 2007 vectors A vector is a directed line segment that has magnitude (length) and direction. We can define a vector as the difference between two points. (Example on board.) In 2 dimensions: V = P 2 -P 1 = (v x, v y ) In 3 dimensions: V = P 2 -P 1 = (v x, v y, v z ) The v x, v y, and v z values are the projections of the line segment onto the x, y and z axes, respectively. Magnitude of a Vector is determined by the Pythagorean theorem: For 2d: |V| = sqrt(v x 2 + v y 2 ) and for 3d: |V| = sqrt(v x 2 + v y 2 + v z 2 )

Michael Eckmann - Skidmore College - CS Spring 2007 vectors For 2d vectors: the direction of a vector is often specified as an angle in relation to the horizontal. For 3d vectors: the direction of a vector is often specified as three angles in relation to the positive axes. (note: The alpha in the diagram would only be accurate if V was on the y-z plane.) cos α = v x / |V| cos β = v y / |V| cos γ = v z / |V| cos 2 α + cos 2 β + cos 2 γ = 1

Michael Eckmann - Skidmore College - CS Spring 2007 vectors A vector has a direction and a magnitude. Does it have a position in the coordinate system?

Michael Eckmann - Skidmore College - CS Spring 2007 vectors A vector has a direction and a magnitude. Does it have a position in the coordinate system? –No –Example: –p1 = (5,5,5), p2 = (7,7,5), p3 = (2,7,3), p4 = (4,9,3) –The vectors generated by [p2 – p1] and [p4 – p3] result in the same vector which is [2,2,0] what's its magnitude? what's its direction? what's its position?

Michael Eckmann - Skidmore College - CS Spring 2007 vectors A vector has a direction and a magnitude. Does it have a position in the coordinate system? –No –Example: –p1 = (5,5,5), p2 = (7,7,5), p3 = (2,7,3), p4 = (4,9,3) –The vectors generated by [p2 – p1] and [p4 – p3] result in the same vector which is [2,2,0] what's its magnitude? sqrt (4+4) = sqrt(8) = 2*sqrt(2) what's its direction? –cos -1 (sqrt(2)/2) = 45 degrees –cos -1 (0) = 90 degrees what's its position? –it has no position

Michael Eckmann - Skidmore College - CS Spring 2007 vectors Vector addition: V 1 + V 2 = (v 1x +v 2x, v 1y +v 2y, v 1z +v 2z ) Scalar multiplication: sV = (sv x, sv y, sv z ) Dot product (aka scalar product) of 2 vectors results in a scalar: V 1 ● V 2 = |V 1 | |V 2 |cos θ θ is the (smaller) angle between the two vectors alternatively: V 1 ● V 2 = v 1x v 2x +v 1y v 2y +v 1z v 2z What would be the dot product of two perpendicular vectors (those with the angle between them being 90 degrees)?

Michael Eckmann - Skidmore College - CS Spring 2007 vectors Cross product (aka vector product) of 2 vectors results in a vector: V 1 x V 2 = u |V 1 | |V 2 |sin θ θ is the angle between the two vectors u is a unit vector (length = 1) perpendicular to both V 1 and V 2 u's direction is determined by the right-hand rule Right-hand rule is: with your right hand, grasp the axis perpendicular to the plane of the two vectors and make sure that the direction of your fingers curve from v1 to v2. u's direction is the direction of your thumb. Alternatively: V 1 x V 2 = (v 1y v 2z – v 1z v 2y, v 1z v 2x – v 1x v 2z, v 1x v 2y – v 1y v 2x ) Cross product is not commutative, nor associative. V 1 x V 2 = - (V 2 x V 1 )

Michael Eckmann - Skidmore College - CS Spring 2007 vectors Cross product of two vectors is a vector that is perpendicular to the two vectors and has magnitude equal to the area of the parallelogram formed by the two vectors. (picture on board)

Michael Eckmann - Skidmore College - CS Spring 2007 vectors Recap –a vector has magnitude and direction (but no position) –addition of 2 vectors results in a vector –a scalar times a vector results in a vector –Cross product of two vectors results in a vector –but –dot product of two vectors results in a scalar

Michael Eckmann - Skidmore College - CS Spring 2007 lines Parametric equation of a line in 3 dimensions –Given points P 1 and P 2 the equation of a line that contains these points is: x = x 1 + t(x 2 – x 1 ) y = y 1 + t(y 2 – y 1 ) z = z 1 + t(z 2 – z 1 ) –Given a point P 1 and vector V the equation of a line that contains the point and is in the direction of V is: x = x 1 + t(x v ) y = y 1 + t(y v ) z = z 1 + t(z v ) Line = P 1 + t (P 2 – P 1 ) Line = P 1 + Vt

Michael Eckmann - Skidmore College - CS Spring 2007 Planes (part of sec. 3.15) The general plane equation: Ax + By + Cz + D = 0 A, B, C, D are constants and (x,y,z) are the coordinates of the points on the plane. A useful form of the plane equation is: A'x + B'y + C'z + D' = 0 where A'=A/d, B'=B/d, C'=C/d, D'=D/d, and d = sqrt(A 2 + B 2 + C 2 ) Because then the distance between a point (x 1, y 1, z 1 ) and the plane is simply: A'x 1 + B'y 1 + C'z 1 + D' A normal vector to a plane is perpendicular to the plane. If the equation of the plane is Ax + By + Cz + D = 0, then a normal to the plane is the vector (A, B, C) Pictures on board.

Michael Eckmann - Skidmore College - CS Spring 2007 The plane equation From the drawing on the board –Equation of the plane: Ax + By + Cz + D = 0 –Given three non collinear points, P 1, P 2, P 3 these points uniquely determine the plane –The cross product of P 1 - P 2 and P 3 - P 2, gives us a normal vector N. –For an arbitrary point P = (x, y, z), P is on the plane if N ● [ P - P 2 ] = 0 –This normal vector gives us the 3 coefficients A, B and C. –To determine the value for D in the plane equation we can take the dot product of N with any point in the plane and get -D. N ● P = [A,B,C] ● [x,y,z] = Ax + By + Cz So, N ● P + D = 0, therefore N ● P = -D. –let's

Michael Eckmann - Skidmore College - CS Spring d transformations Translation Scale Rotation Shear

Michael Eckmann - Skidmore College - CS Spring d Translation 3d Translation in homogeneous coordinates is a direct extension of translation in 2d. [ t x ] [x] [x+t x ] [ t y ] [y] = [y+t y ] [ t z ] [z] [z+t z ] [ ] [1] [ 1 ]

Michael Eckmann - Skidmore College - CS Spring d Scale [ s x ] [x] [s x x] [ 0 s y 0 0 ] [y] = [s y y] [ 0 0 s z 0 ] [z] [s z z] [ ] [1] [ 1 ] 3d Scale has the same problem/feature that 2d scaling has, namely it also translates.

Michael Eckmann - Skidmore College - CS Spring d Rotation Positive rotations are defined to be Rotation about the x-axis is positive going from y to z Rotation about the y-axis is positive going from z to x Rotation about the z-axis is positive going from x to y (see figures 5-36 and 5-38 in text.)

Michael Eckmann - Skidmore College - CS Spring 2007 Right-handed 3d coordinate system

Michael Eckmann - Skidmore College - CS Spring d Rotation About z-axis [ cos θ -sin θ 0 0 ] [ sin θ cos θ 0 0 ] [ ] [ ] About x-axis [ ] [ 0 cos θ -sin θ 0 ] [ 0 sin θ cos θ 0 ] [ ] About y-axis [ cos θ 0 sin θ 0 ] [ ] [ -sin θ 0 cos θ 0 ] [ ] Let's do some calculations on the board – rotating some points to get a feel for these.

Michael Eckmann - Skidmore College - CS Spring 2007 xy Shear [ 1 0 sh x 0 ] [x] [x+sh x z] [ 0 1 sh y 0 ] [y] = [y+sh y z] [ ] [z] [ z ] [ ] [1] [ 1 ] Let's transform a unit cube with this shear and set sh x = 1 and sh y = 2 points are: (0,0,0), (0,0,1), (0,1,0), (1,0,0), (0,1,1), (1,0,1), (1,1,0), (1,1,1)

Michael Eckmann - Skidmore College - CS Spring 2007 xy Shear [ 1 0 sh x 0 ] [x] [x+sh x z] [ 0 1 sh y 0 ] [y] = [y+sh y z] [ ] [z] [ z ] [ ] [1] [ 1 ] Let's transform a unit cube with this shear and set sh x = 1 and sh y = 2 points are: (0,0,0), (0,0,1), (0,1,0), (1,0,0), (0,1,1), (1,0,1), (1,1,0), (1,1,1) transformed they are: (0,0,0), (1,2,1), (0,1,0), (1,0,0), (1,3,1), (2,2,1), (1,1,0), (2,3,1)