Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 376 Introduction to Computer Graphics 04 / 20 / 2007 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 376 Introduction to Computer Graphics 04 / 20 / 2007 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 376 Introduction to Computer Graphics 04 / 20 / 2007 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Today’s Topics Questions? review ray-polygon intersections Piecewise Cubic Parametric curves –Hermite –Bezier –Spline

3 Ray / Polygon Intersection The first step in Ray/Polygon intersection is to compute the intersection of the ray with the plane that the polygon lives on. At this point we have –the plane equation Ax+By+Cz+D = 0 –the point of intersection P I = (x I, y I, z I ) of the ray and plane –the vertices V = (x j, y j, z j ) of the polygon on that plane A technique that makes computation easier at this point is to orthographically project the polygon onto either the x-y, y-z, or z-x plane. To do this we just have to ignore the same coordinate of all of the vertices of the polygon and we end up with 2d points. The best coordinate to ignore is the one whose corresponding coefficient in the plane equation is dominant (largest absolute value.)

4 Ray / Polygon Intersection The best coordinate to ignore is the one whose corresponding coefficient in the plane equation is dominant (largest absolute value.) It gives us a polygon in 2d with the largest area of the 3 choices.

5 Ray / Polygon Intersection Note: this technique is a combination of ideas from –Computer Graphics Principles and Practive by Foley, Van Dam, Feiner and Hughes, 1996 Addison-Wesley –Dr. G. Drew Kessler's csc313 course 1999, Lehigh Univ. and –Dr. Xiaoyu Zhang's Advanced Computer Graphics & Visualization page http://courses.csusm.edu/cs697exz/ray_polygon.htm Example: If the plane equation is –0.2 x +0.4 y –0.8945 z +5 = 0 we would orthographically project the polygon onto the x-y plane (ignore the z coordinate of each vertex) This will yield the largest (area) projection. Once we have done this projection, we can translate the intersection point P I to the origin of this new 2d space (call it u-v coordinates). Then determine whether the origin is inside or outside the polygon by counting the number of polygon edge crossings with the positive u axis.

6 Ray / Polygon Intersection The next algorithm distinguishes between several different situations to determine when to add 1 to the number of times the polygon's edges cross the positive u axis. For some edge –1) if the signs of the v coordinate in both vertices are the same, then that edge DOES NOT cross the positive u-axis –2) if the signs of the v coordinate in both vertices are different AND both u coordinates are positive then that edge DOES cross the positive u-axis. –3) if the signs of the v coordinate in both vertices are different AND one of the u coordinates is positive then compute the intersection of the line with v=0. If the u coordinate of this intersection is positive then that edge DOES cross the positive u-axis. –4) if the signs of the v coordinate in both vertices are different AND one of the u coordinates is positive then compute the intersection of the line with v=0. If the u coordinate of this intersection is not positive then that edge DOES NOT cross the positive u-axis. –For cases 2 and 3 above, add 1 to a counter. Do this for all edges in the polygon in order and then check the value of the counter --- if it is odd then the point is in the interior of the polygon and hence the ray intersects with the polygon.

7 Ray / Polygon Intersection The n vertices of the polygon are (u i, v i ) where i goes from 0 to n-1. Pseudocode to determine if the origin is inside the polygon initialize numCross to 0 if v 0 > 0 then signHold1 = +1 else signHold1 = -1 for each edge (u a, v a ) to (u b, v b ) { if v b > 0, signHold2 = +1, else signHold2 = -1 if signHold1 != signHold2 { if u a and u b are both > 0, then numCross++ if one of u a or u b is > 0, then { if (crossPosUAxis(u a, v a, u b, v b ) then numCross++ } } signHold1 = signHold2 } if numCross is odd, then the ray and polygon intersect

8 Ray / Polygon Intersection pseudocode for crossPosUAxis recall the parametric equations of a line: u = u b + (u a - u b )t v = v b + (v a - v b )t = 0 (because we're looking for intersection with u axis) so, use the second equation to solve for t then solve the first for u and get u = (u b + ( u a - u b ) * ( v b / (v b -v a ) ) ) crossPosUAxis(u a, v a, u b, v b ) if ( (u b + ( u a - u b ) * ( v b / (v b -v a ) ) ) > 0 ) return true else return false

9 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Polygonal Meshes A collection of edges, vertices and polygons –which are connected –and where each edge is shared by at most 2 polygons (example on board) –each vertex is shared by at least 2 edges When polygonal meshes are created interactively –care must be taken to make sure that the above constraints are fulfilled. Different ways to store a polygonal mesh have consequences on –space (to store the mesh data) –and time (to operate on the polygonal mesh)

10 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Polygonal Meshes Some operations that are common on polygonal meshes –find all edges containing a particular vertex –find all the polygons sharing a particular edge or vertex –find the two vertices for an edge –find all the edges of a polygon –determining if all the conditions of a polygonal mesh are met How the polygonal mesh is represented has consequences on the speed of those operations and on how much space is needed to store a polygonal mesh.

11 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Polygonal Meshes Representation schemes: –represent each polygon as a list of vertices in order around the polygon edges exist between each pair of successive vertices as well as between the last and the first efficient in space for a single polygon inefficient in space for a polygonal mesh, why? interactively working on a polygonal mesh represented this way would be time consuming (e.g. move a vertex --- need to find all the polygons that contain it and move it...) etc. –store all the vertices in a list, and represent a polygon as an ordered list of pointers into the vertex list. easier to find all polygons containing a vertex –store all the vertices in a list, and all the edges in an edge list* and represent a polygon as an ordered list of pointers into the edge list * edge list contains pointers to two vertices and pointers to one or two polygons can easily find all polys that share an edge now

12 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Polygonal Meshes In all 3 representation schemes just described it is still not easy to find all the edges containing a particular vertex –in the description of a vertex, could add pointers to all the edges

13 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Curves Some motivations for having mathematical equations define curves and surfaces 1) polylines and polygons are 1 st degree piecewise linear approximations to curves and surfaces (they are approximations unless they are the exact description of the outline or shape) –if they are approximations, then it takes large numbers of points to describe them for more accurate representations == BAD –if interactively building these surfaces (or edges/outlines) then the more points, the more tedious it is to build We want to be able to get more accurate representations of curved surfaces (or edges/outlines) than polygons or polylines give us AND we want to be able to represent them with less points. This will benefit us by having less storage and be more easily built interactively.

14 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Curves Let's consider 2d dimensional curves which can be later generalized to 3d surfaces. Instead of using piecewise linear functions, we use piecewise smooth curves. These are of a higher degree than linear functions. We have several choices –a) we can use functions like y = f(x) problem that for each value of x there is one and only one y value –can't represent circles/ellipses etc. problem of not being able to easily describe a rotated version of the function problem that you can't represent vertical lines and is problematic to represent curves with a tangent/slope of infinity –b) we can use implicit equations like f(x,y) = 0 (e.g. a circle of radius 1 like: x 2 + y 2 – 1 = 0) may have more solutions than we want --- e.g. to model half a circle you'd need constraints on the values of x or y or both. joining 2 implicitly defined curves is hard to make the tangents at the join point agree

15 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Curves We have several choices –c) we can use parametric equations of the curve x = f(t) and y = g(t) –where f(t) and g(t) are typically cubic polynomials the problems of the other 2 choices are solved as we shall see –we typically use cubic polynomials because 1) quadratic or linear polynomials do not allow a curve segment to be described with 2 endpoints and specific slopes at the 2 endpoints 2) higher degree (than 3) polynomials are more compute intensive and allow (possibly) unwanted artifacts in the curve A cubic polynomial to define a finite curve segment has 4 coefficients per parametric equation x(t) = a x t 3 + b x t 2 + c x t + d x y(t) = a y t 3 + b y t 2 + c y t + d y z(t) = a z t 3 + b z t 2 + c z t + d z where 0 <= t <= 1

16 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Curves x(t) = a x t 3 + b x t 2 + c x t + d x y(t) = a y t 3 + b y t 2 + c y t + d y z(t) = a z t 3 + b z t 2 + c z t + d z where 0 <= t <= 1 can be written in matrix form as: Q(t) = [x(t) y(t) z(t)] = T C where T = [t 3 t 2 t 1] and [a x a y a z ] C = [b x b y b z ] [c x c y c z ] [d x d y d z ]

17

18

19 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Curves Continuity - when joining two curve segments together (piecewise curves). There are several different kinds of continuity to consider Geometric continuity –G 0 geometric continuity = the curve segments are joined together –G 1 geometric continuity = the curve segments are joined together and the directions of tangent vectors are equal at the point where they are joined Parametric continuity –C 0 parametric continuity = same as G 0 geometric continuity –C 1 parametric continuity = the curve segments are joined together and the directions AND magnitudes of tangent vectors are equal at the point where they are joined –C k parametric continuity = the curve segments are joined together and the directions AND magnitudes of all the derivatives up to the k th are equal at the point where they are joined (that is, the 1 st through k th derivatives exist and are continuous themselves)

20 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Curves Let me draw on the board some example joined curve segments and point out their continuity.

21 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Curves There are several families of cubic polynomial curve segments that are determined by different things –Hermite determined by the 2 endpoints and the tangent vector at each of the 2 endpoints –Bezier determined by the 2 endpoints P 1 & P 4 and 2 other intermediate points P 2 & P 3 not on the curve –the tangent vectors at the end points are the vectors P 1 P 2 and P 3 P 4 –which are [P 2 – P 1 ] and [P 4 – P 3 ] –Spline determined by 4 specific points Note: there can be higher degree polynomials of these families of curves (see a few slides ahead for a 4 th degree polynomial Bezier curve segment)

22 Hermite Curve segment examples (on the board)

23 Bezier Curve segment examples

24 more Bezier Curve segment examples

25 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Recall x(t) = a x t 3 + b x t 2 + c x t + d x y(t) = a y t 3 + b y t 2 + c y t + d y z(t) = a z t 3 + b z t 2 + c z t + d z where 0 <= t <= 1 can be written in matrix form as: Q(t) = [x(t) y(t) z(t)] = T C where T = [t 3 t 2 t 1] and [a x a y a z ] C = [b x b y b z ] [c x c y c z ] [d x d y d z ]

26 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Basis Matrix and Geometry Vector Q(t) = [x(t) y(t) z(t)] = T C where T = [t 3 t 2 t 1] and [a x a y a z ] C = [b x b y b z ] [c x c y c z ] [d x d y d z ] can be rewritten so that C = M G where –M is a 4x4 matrix called the Basis Matrix and –G is a 4x1 column vector called the Geometry Vector so Q(t) = T M G

27 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Recall Q(t) = [x(t) y(t) z(t)] = T M G where T = [t 3 t 2 t 1] and [m 11 m 12 m 13 m 14 ] M = [m 21 m 22 m 23 m 24 ] [m 31 m 32 m 33 m 34 ] [m 41 m 42 m 43 m 44 ] [G 1 ] G = [G 2 ] [G 3 ] [G 4 ] look at x(t) = (t 3 m 11 + t 2 m 21 + t m 31 + m 41 )g 1x +

28 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Blending functions look at x(t) x(t) = (t 3 m 11 + t 2 m 21 + t m 31 + m 41 )g 1x + (t 3 m 12 + t 2 m 22 + t m 32 + m 42 )g 2x + (t 3 m 13 + t 2 m 23 + t m 33 + m 43 )g 3x + (t 3 m 14 + t 2 m 24 + t m 34 + m 44 )g 4x where g 1x is the x coordinate of G 1 similar equations for y(t) and z(t) the curve is a weighted sum of the elements of the Geometry Matrix where the weights are cubic polynomials of t which are called the Blending Functions the Blending Functions B are given by B = T M so Q(t) = B G


Download ppt "CS 376 Introduction to Computer Graphics 04 / 20 / 2007 Instructor: Michael Eckmann."

Similar presentations


Ads by Google