1 / 36

Computer Graphics Lab.

Computer Graphics Lab. Fall 2011 Hyunki Hong Dept. of Imaging Science & Arts, GSAIM Chung-Ang Univ. Ch.4 Vector Tools for Graphics 4.1 Introduction  - describe the objects and how light bounces around to illuminate them,

mickey
Download Presentation

Computer Graphics Lab.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Graphics Lab. Fall 2011 Hyunki Hong Dept. of Imaging Science & Arts, GSAIM Chung-Ang Univ.

  2. Ch.4 Vector Tools for Graphics 4.1 Introduction  - describe the objects and how light bounces around to illuminate them, so that the final pixel values on the display can be computed. → vector analysis & transformations Ch.4 Vector Tools for Graphics 4.1 Introduction  - describe the objectsand how light bounces around to illuminate them, so that the final pixel values on the display can be computed. → vector analysis & transformations - Why are vectors so important?   a. a computer-aided design problem Ch.4 Vector Tools for Graphics 4.1 Introduction  - describe the objectsand how light bounces around to illuminate them, so that the final pixel values on the display can be computed. → vector analysis & transformations - Why are vectors so important?   a. a computer-aided design problem   b. The camera must form an image of something on its "viewplane", and the image must be transferred to a screen window on the user's display. → perspective projections Ch.4 Vector Tools s for Graphics 4.1 Introduction  - describe the objectsand how light bounces around to illuminate them, so that the final pixel values on the display can be computed. → vector analysis & transformations - Why are vectors so important?   a. a computer-aided design problem   b. The camera must form an image of something on its "viewplane", and the image must be transferred to a screen window on the user's display. → perspective projections   c. reflection (ex. ray tracing)     : where exactly does the reflected image appear, and what is its color & shape? 

  3. - Some basics   Fig. 4.2 2D & 3D coordinate systems (b) right-handed, (c) left-handed 3D coordinate system 4.2 Review of vectors - Viewed geometrically, vectors are objects having length & direction - represent various physical entities: force, displacement, velocity - often drawn as an arrow of a certain length pointing in a certain direction

  4. - a vector geometrically as a displacement from one point to another. - the difference between two points is a vector: v = Q - P - the sum of a point and a vector is a point: P + v = Q - a vector through a list of its components; an n-D vector is given by an n-tuple: w = (w1, w2, …, wn). 4.2.1 Operations with vectors - addition & multiplication by scalars (real numbers)

  5. - Fig. 4.5: the sum of two vectors   (a) the parallelogram rule for adding vectors (b) one vector (b) starting at the head of the other (a) and draw the sum as emanating from the tail of a to the head of b. - Scaling a vector & Subtracting vectors a – c = a + (-c).

  6. (a) (b) 4.2.2 Linear combinations of vectors - a linear combination of the m vectors: w = a1v1 + a2v2 + … + amvm - affine combinations of vectors: if the coefficients add up to unity →a1 + a2 + … + am= 1. 4.2.2 Linear combinations of vectors - a linear combination of the m vectors: w = a1v1 + a2v2 + … + amvm - affine combinations of vectors: if the coefficients add up to unity →a1 + a2 + … + am= 1. - convex combination of vectors    a. Not only must the coefficients of the linear combination sum to unity, but each coefficient must also be nonnegative.   b. a1, a2, …, am form a partition of unity. : a unit amount of "material" is partitioned into pieces. cf. spline curves, colors (three primary colors)   c. Fig. : the set of vectors representable by convex combinations v = (1- a)v1 + av2 = v1 + a(v2 – v1) v1 = (2, 6) v2 = (3, 3) v3 = (7, 4) b = .2v1 + .5v2 + .3v3 ex. 2(3, 4, -1) + 6(-1, 0, 2) = (0, 8, 10)

  7. 4.2.3 The Magnitude of a vector; unit vectors - a vector w is represented by the n-tuple - the magnitude of |w| = (w12 + w22 + … + wn2)1/2. : the distance from the tail to the head of the vector - a unit vector (direction) & normalizing a vector: a = a / |a| 4.2.3 The Magnitude of a vector; unit vectors - a vector w is represented by the n-tuple - the magnitude of |w| = (w12 + w22 + … + wn2)1/2. : the distance from the tail to the head of the vector - a unit vector (direction) & normalizing a vector: a = a / |a| 4.3 The Dot Product → a scalar : multiply corresponding components of the two n-D vectors and add the results → d = v · w = ∑viwi (i = 1, 2, …, n) 4.3.1 Properties of the dot product - symmetry: a · b = b · a (commutative) - linearity: (a + c) · b = a · b + c · b - homogeneity: (s a) · b = s(a · b) - | b |2 = b · b (the square of the length of the vector) → | b | = (b · b)1/2 ex. (2, 3, 1) · (0, 4, -1) = 11

  8. 4.3.2 The angle between two vectors - application: find the angle between two vectors or between two intersecting lines   → the cosine of the angle between two vectors b and c : b · c = |b| · |c| cos(θ)      : the dot product of the normalized vectors 4.3.2 The angle between two vectors - application: find the angle between two vectors or between two intersecting lines   → the cosine of the angle between two vectors b and c : b · c = |b| · |c| cos(θ)      : the dot product of the normalized vectors 4.3.3 The Sign of b · c, and perpendicularity - Vectors b & c are perpendicular (orthogonal, normal) if b · c = 0. - the standard unit vectors in 3D have components   : i = (1,0,0), j = (0,1,0), and k = (0,0,1) cf. <, >

  9. 4.3.4 The 2D "Perp" Vector (Fig.4.11) - Let a = (ax, ay). Then a⊥ = (-ay, ax) is counterclockwise perpendicular to a.   4.3.5 Orthogonal projections and the distance from a point to a line - three geometric problems   a. projecting a vector onto a given vector: Fig. (b)   b. resolving a vector into its components in one direction: (b) & (c) 가. The vector c is resolved into the portion Kv along v and the portion Mv┻ perpendicular to v: c = Kv + Mv┻. 나. the orthogonal projection of c onto v is Kv 다. the distance from C to the line is |Mv ┻ |. 4.3.4 The 2D "Perp" Vector (Fig.4.11) - Let a = (ax, ay). Then a⊥ = (-ay, ax) is counterclockwise perpendicular to a.  Why?

  10. c. finding the distance between a point and a line 4.3.6 Applications of projection: reflections - find the direction that an object takes upon being reflected at a given surface - When light reflects from a mirror, we know that the angle of reflection must equal the angle of incidence. - Fig. : Reflection of a ray from a surface   a. a ray having direction a, hitting line L, and reflecting in direction r the vector n is perpendicular to the line.   b. Eq. : direction of the reflected ray r = e – m, e = a – m→r = a - 2m, 이전 페이지 관계에서 유도 m: the orthogonal projection of a onto n

  11. cf. Reflectance Model • Simple Analytic Model: - Diffuse reflection + - Specular reflection + - Emission + - “Ambient”

  12. 4.4 The Cross Production (vector product) of Two Vectors : a = (ax, ay, az), b = (bx, by, bz) → a × b = (aybz – azby)i + (azbx – axbz)j + (axby – aybx)k - find a perpendicular vector to both of the given vectors - Eq. 4.26   a. i × j = k,   j × k = i,   k × i = j   b. a × b = -b × a    (antisymmetry)   c. a × (b + c) = a × b + a × c  (linearity)   d. (sa) × b = s(a × b)   (homogeneity) 4.4 The Cross Production (vector product) of Two Vectors : a = (ax, ay, az), b = (bx, by, bz) → a × b = (aybz – azby)i + (azbx – axbz)j + (axby – aybx)k - find a perpendicular vector to both of the given vectors - Eq. 4.26   a. i × j = k,   j × k = i,   k × i = j   b. a × b = -b × a    (antisymmetry)   c. a × (b + c) = a × b + a × c  (linearity)   d. (sa) × b = s(a × b)   (homogeneity) 4.4.1 Geometric interpretation of the cross product - Fig. 4.14: Interpretation of the cross product   a. a × b : vector perpendicular (orthogonal) to both a & b   b. The length of a × b equals the area of the parallelogram determined by a & b. : |a × b| = |a||b|sin(θ)

  13. 4.4.2 Finding the normal to a plane - Fig. : Finding the plane through three given points   a. Any three points P1, P2, and P3 determine a unique plane, as long as the points do not lie in a straight line.   b. a = P2 - P1, b = P3 - P1→ n = a × b 4.4.2 Finding the normal to a plane - Fig. : Finding the plane through three given points   a. Any three points P1, P2, and P3 determine a unique plane, as long as the points do not lie in a straight line.   b. a = P2 - P1, b = P3 - P1→ n = a × b 4.5 Representation of Key Geometric Objects - Problems   a. Is point P on the line?   b. Where does the line intersect another line or some other object? - How points & vectors differ and how each is represented? - homogeneous coordinates

  14. 4.5.1 Coordinate systems and coordinate frames - Points have a location, but no size or direction, whereas vectors have a size & direction, but no location. - Fig. : A coordinate frame positioned in "the world"   a. A coordinate frame consists of a specific point (the origin) and three mutually perpendicular unit vectors, a, b, & c.   b. Eq. 4.28 가. a vector v has the representation (v1, v2, v3) in this system. → v = v1a + v2b + v3c 나. P is “at" a location that is offset from the origin by p1a + p2b + p3c. (p1, p2, p3)

  15. “affine combination” independent on system - homogeneous representation of a point & a vector   a. useful to represent both points and vectors using the same set of basic underlying objects, (a, b, c, o).   b. the vector v = v1a + v2b + v3c.   the point P = p1a + p2b + p3c + o   c. OpenGL uses 4D homogeneous coordinates for all its vertices.  - Linear combinations of vectors : the differce of two points → vector, the sum of a point and a vector → another point, the sum of two vectors → another vector 4.5.2 Affine combinations of points - any affine combination of points is a legitimate point. - Fig. : Adding points is not a valid operation. Suppose the origin is shifted by vector u, so that P is shifted to P + u and R to R + u. If E is a valide point, it must be shifted to E ' = E + u. E = fP + gR → E ' = fP + gR + (f + g)u, which is not E + u unless f + g = 1

  16. - Ex. 4.5.1 & Fig. 4.20 : The centroid of a triangle as an affine combination → where the point that is 2/3 of the way from D to G lies?   a. The centroid is simply the average of the locations of the N vertices → affine combination. - Ex. 4.5.1 & Fig. 4.20 : The centroid of a triangle as an affine combination → where the point that is 2/3 of the way from D to G lies?   a. The centroid is simply the average of the locations of the N vertices → affine combination. 4.5.3 Linear interpolation of two points - The affine combination of points: P = A(1 - t) + Bt.   → a linear interpolation between the points A & B. - tween at t of points A & B: the point P(t) that is the fraction t on the way along the straight line from A to point B. 4.5.4 "Tweening" for art & animation - The procedure is simplest if the two figures are polylines based on the same number of points. - Fig. 4.22 & 4.23 G=(E+F)/2, C=D+(G-D)t, t=2/3, C=(D+E+F)/3

  17. a. drawTween() draws a tween of two polylines A & B, each having n vertices, at the specified value of t.   b. Double buffering is used to make the transition from one displayed tween to the next instantaneous one. - Fig. 4.25: Face caricature (Tweening & extrapolation) → caricaturelike distortions - key frames : 10 tweens using linear interpolation → saving a great deal of the artist's time 4.5.5 Preview: Quadratic & cubic tweening and Bezier curves - Bézier curves as tweening (Fig. 4.26)   a. simply tweening between a collection of points.

  18. b. With linear interpolation, we "partition unity" into the pieces (1-t) & t, and we use these pieces to "weight" the points A & B.      → quadric interpolation by partitioning unity into three pieces.          : P(t) = (1 - t)2A + 2t(1 - t)B + t2C. 4.5.6 Representing lines & planes - lines in 2D & 3D spaces (Fig. 4.27)

  19.   a. A line is defined by two points, C & B.      : It is infinite in length, passing through the points and extending forever in both directions.   b. A line segment is also defined by two points, its endpoints, but extends only from one endpoint to the other.   c. A ray is "semi-infinite".     : specified by a point and a direction, starting at that point and extending infinitely far in a given direction - parametric representation of a line   a. L(t) = C + bt,  where b = B - C.     : As t varies, so does the position of L(t) along the line.    b. a function of t that generates the coordinates of every point on L as t varies      : the parametric representation of a line L (Fig. 4.28)   a. A line is defined by two points, C & B.      : It is infinite in length, passing through the points and extending forever in both directions.   b. A line segment is also defined by two points, its endpoints, but extends only from one endpoint to the other.   c. A ray is "semi-infinite".     : specified by a point and a direction, starting at that point and extending infinitely far in a given direction

  20. - Points normal form for the equation of a line (the implicit form)   a. fx + gy = 1,  where f & g are constants.     : the dot product (f, g) · (x, y) = 1.       → for every point on a line, a certain dot product must have the same value.   b. the point normal equation for the line: n · (R - C) = 0 ex. Line passes through points C=(3, 4) & B=(5,-2). Then b=B-C=(2,-6) and b┻=(6,2). Choosing C as the point on the line, we have the point normal form : (6,2) · ((x,y)-(3,4))=0 or 6x+2y=26. → y=-3x+13.

  21. - Moving from one representation to another   a. three different ways to characterize a line: Fig.   b. stored in a suitable data structure to capture the specifics of each line that is of interest.     1. The two-point form: C & B; datum = {C, B}     2. The parametric form: C + bt; datum = {C, b}     3. The point normal (implicit) form (in 2D only): n · (P - C) = 0; datum = {C, n}

  22. - Planes in 3D space   a. the parametric representation of a plane      1. three ingredients         : one of its points, C, and two (nonparallel) vectors, a & b, that lie in the plane.   2. the three-point form & the affine combination of points         : P(s, t) = C + s(A - C) + t(B - C)  →  P(s, t) = sA + tB + (1 - s - t)C b. the point normal equation of the plane : n · (R - B) = 0 P(s, t) = C + as + bt

  23. c. three fundamental forms      1. the three-point form, say C, B, and A; datum = {C, B, A}.      2. the parametric form, C + as + bt; datum = {C, a, b}.      3. the point normal (implicit) form, n · (P - C) = 0; datum = {C, n}.

  24. - planar patches : a piece of a plane   a. the plane: a quilt of many patches joined together   b. Fig. 4.31: Mapping between two spaces to define a planar patch      → P(s, t) = C + as + bt 4.6 Finding the Intersection of Two Line Segments - the problem: Given two line segments, determine whether they intersect, and if they do, find their point of intersection.   → the use of the parametric forms & dot products - planar patches : a piece of a plane   a. the plane: a quilt of many patches joined together   b. Fig. 4.31: Mapping between two spaces to define a planar patch      → P(s, t) = C + as + bt ex. P(0,0) = C, P(1,0) = C+a,P(0,1) = C+b,P(1,1) = C+a+b

  25. - Fig. 4.32 : Many cases for two line segment   a. Every line segment has a parent line.: the infinite line of which it is part.   b. Unless two parent lines are parallel, they will intersect at some point. → Eq. : to locate the point. AB(t)=A+bt, CD(u)=C+du,A+bt=C+du , Defining c = C-A for convenience, bt=c+du. Dot both sides with d┴ to eliminate the term in d, giving d┴ ·bt = d┴ ·c. → t = d┴c/d┴b, u = b┴c/d┴b

  26. a = B - A, b = C – B, c = A – C. the midpoint of AB: A + a/2. the parametric form for the perpendicular bisector: A + a/2 + a┻t Similarly the perpendicular bisector of AC = A + c/2 + c┻u Point S lies where these meet. → a┻t = b/2 + c┻u 4.6.1 Application of line intersections: The circle through three points - draw the unique circle that passes through three given points (Fig. 4.33) : the excircle or circumscribed circle of the triangle defined by the points    a. The center S of the desired circle must be equidistant from all three vertices, so it must lie on the perpendicular bisector of each side of triangle ABC.     : The perpendicular bisect is the locus of all points that are equidistant from two given points. (Fig. 4.34)   b. determine S if we can compute where two of the perpendicular bisects intersect.   c. derive the center of the excircle & the radius of the excircle: Eq. 4.49 유도? L(t) = (A + B)/2 + (B - A)┻t

  27. 4.7 Intersections of Lines with Planes:Clipping → For two points A & C, which part of segment AC lies inside P? - the problem of clipping a line against a convex polygon in 2D or a convex polyhedron in 3D   → in viewing 3D objects, tracing rays - In 2D, we want to find where a line intersects another line; in 3D, we want to find where a line intersects a plane. - Consider a line described parametrically by R(t) = A + ct. : ray   a. compute where it intersects the object: the point normal form n · (P - B) = 0   b. Fig. 4.36 : Where does a ray hit a line or a plane? P P

  28.   c. At t = thit (hit time), the line & ray must have the same coordinates, so A + cthit must satisfy the equation of the point normal form of the line or plane.    d. the hit time & the location (Eq. 4.51) n·(A + cthit - B) = 0 → n·(A -B) + n·cthit = 0 → thit = n·(B - A) / n·c   e. Fig. 4.37 : the direction of the ray is "along with" n or "against (counter to)" n. If n · c > 0, the ray is aimed “along with” the normal. If n · c = 0, the ray is parallel to the line. If n · c < 0, the ray is aimed “counter to” the normal. P B P

  29. 4.8 Polygon Intersection Problems - In 3D, an object is often modeled as a polygonal "mesh"   : a collection of polygons that fit together to make up the object’s “skin” - If the skin forms a closed surface that encloses some space, the mesh is called a polyhedron. - Fig. 4.38: Intersection problems involving a line & a polygonal object.   a. Is a given point P inside or outside the object?   b. Where does a given ray R first intersect the object?   c. Which part of a given line L lies inside the object, and which part lies outside?

  30. 4.8.1 Working with convex polygons and polyhedra - A convex polygon is completely described by a set of "bounding lines (2D)" or "bounding planes (3D)" - Each bounding line defines two half-spaces.   a. the inside half-space containing the polygon   b. the outside half-space sharing no points with the polygon. - The advantage in dealing with convex polygons   a. We perform intersection tests only on infinite lines, do not need to   check whether an intersection lies "beyond" an endpoint.   b. The point normal form can be used, which simplifies the calculations.

  31. 4.8.2 Ray intersections and clipping for convex polygons - the intersection problem (Eq. 4.54 & Fig. 4.40)   a. Entering hit point = A + ctin   b. Exiting hit point = A + ctout   c. The ray is inside P for all t in the interval [tin, tout]. - the clipping problem   : For the two points A & C, which part of segment AC lies inside P? Where does the ray A + ct intersect that line?   a. Fig. 4.41: A segment clipped by a polygon.

  32. b. for each bounding line,      1. the hit time of the ray with the bounding line:      2. whether the ray is entering or exiting the polygon:   c. algorithm     1. Initialize the candidate interval to [0, 1].     2. For each bounding line, find the hit time thit and determine whether it is an entering or exiting hit: 가. If thit is an entering hit, set tin = max(tin, thit)           where tin : the time for the first endpoint of the clipped segment 나. If thit is an exiting hit, set tout = min(tout, thit)     3. If the candidate interval is not empty, the segment from A + ctin to A +ctout lies inside P.       : the endpoints of the clipped line, the entering & exiting points of the ray thit = n·(B - A) / n·c HOW? If n · c > 0, the ray is aimed “along with” the normal. If n · c = 0, the ray is parallel to the line. If n · c < 0, the ray is aimed “counter to” the normal.

  33. - Fig. 4.43 : Testing when a ray lies inside a convex polygon. 4.8.3 The Cyrus-Beck clipping algorithm - int CyrusBeckClip(Line& seg, LinesList& L) 4.8.4 Clipping against arbitrary polygons - Fig. : Where is a ray (A + ct) inside an arbitrary polygon P (by the list of vertices P0, ..., PN-1)? - the N finite segments such as P3P4 that form its edges (no longer by a collection of infinite bounding lines) - find all of the genuine hits of the ray with edge of P and place them in a list of the hit times. 3.4 -4.7

  34. Assignments * OpenGL Programming - Fig. 4.22 Tweening a T into a house - Making Polygon and Bézier curve by using mouse input

More Related