Download presentation
Presentation is loading. Please wait.
Published byGinger Parker Modified over 9 years ago
1
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Spring 2015 Dr. Michael J. Reale
2
NOTE: COUNTERCLOCKWISE ORDER
Assuming: Right-handed system Vertices in counterclockwise order (looking at front of polygon)
3
FILL AREAS Fill area (or filled area) = area to be filled with color or pattern (or both) Usually surface of object Usually polygons
4
WHY POLYGONS? Why? Boundaries = linear equations (efficient fill algorithms) Can approximate most curved surfaces with polygons Shading easier (especially with triangles single plane per triangle) Surface tessellation = approximating a curved surface with polygons More polygons better detail, but more vertices/polygons to process Also called fitting the surface with a polygon mesh
5
POLYGON DEFINITIONS Polygon = a figure with 3 or more vertices connected in sequence by straight-line segments (edges or sides of the polygon) Most loose definition any closed-polyline boundary More finicky definitions contained in single plane, edges have no common points other than their endpoints, no three successive points collinear Standard polygon or simple polygon = closed-polyline with no crossing edges
6
DOES A POLYGON LIE IN A SINGLE PLANE?
In computer graphics, polygon not always in same plane: Round-off error E.g., after transformations Fitting to surface makes non-planar polygons E.g., quad “bent” in half Thus, use triangles single plane per triangle
7
DEGENERATE POLYGONS Degenerate polygons = often used to describe polygon with: 3 or more collinear vertices generates a line segment E.g., in extreme case, triangle with no area Repeated vertex positions some edges have length 0
8
CONVEX VS. CONCAVE Interior angle = angle inside polygon boundary formed by two adjacent edges By interior angle: Convex = all interior angles less than 180° Concave = one or more interior angles greater than or equal to 180° By looking at vertices compared to edge lines: Convex = for all edge lines, all other vertices are on one side Concave = for one or more edge lines, some of the vertices are on one side and some are on the other Also, one or more edge lines will intersect another edge
9
CONVEX VS. CONCAVE: CORNY MEMORY HOOK
10
DEALING WITH DEGENERATES AND CONCAVE POLYGONS
OpenGL cannot deal with degenerate polygons or concave polygons programmer must detect/preprocess them Degenerate polygons detect and remove Concave polygons detect and split into convex polygons
11
What’s your vector, victor?
What’s your vector, victor? A vector = (N x 1) or (1 x N) matrix (# of rows X # of columns) In computer graphics: N usually 2, 3, or 4 (homogeneous coordinates) Use column vectors (N x 1) Components of the vector: 2D x and y values 3D x, y, and z values 4D x, y, z, and w values Vector interpreted as: Location (w = 1) Direction (w = 0) Scalar = single value (or 1x1 vector)
12
LENGTH OF A VECTOR and THE ZERO VECTOR
Use Euclidean distance for length: A vector with a length of zero is called the zero vector:
13
SCALING VECTORS Scalar times a vector = scalar times the components of the vector Example: multiply 5 by a 3D vector A
14
NORMALIZED VECTORS Normalize a vector = divide vector by its length ║v║ makes length equal to 1 Equivalent to multiplying vector by 1/║v║ Resulting vector is called a normalized vector WARNING: This is NOT the same as a NORMAL vector! Although normal vectors are often normalized.
15
ADDING/SUBTRACTING VECTORS
Add/subtract vectors add/subtract components Geometric interpretation: Adding putting head of one vector on tail of the other Subtracting gives direction from one endpoint to the other
16
DOT PRODUCT Result is a single number (i.e., scalar) another name for the dot product is the scalar product Dot product of vector with itself = square of length of vector: Equivalent to: …where θ = smallest angle between the two vectors If the vectors are normalized, then:
17
DOT PRODUCT: CHECKING ANGLES
Remember: DOT PRODUCT: CHECKING ANGLES Look at sign of dot product to check angle: (A · B) > 0 vectors pointing in similar directions (0 <= θ < 90°) (A · B) = 0 vectors are orthogonal (i.e., perpendicular to each other) (θ = 90°) (A · B) < 0 vectors pointing away from each other (90° < θ <= 180°) For normalized vectors, dot product ranges from [-1, 1]: (A · B) = 1 vectors pointing in the exact same direction (θ = 0°) (A · B) = -1 vectors pointing in the exact opposite direction (θ = 180°) (We’re going to use this trick for lighting calculations later )
18
CROSS PRODUCT Also called vector product (results is a vector)
Given two vectors U and V gives vector W that is orthogonal (perpendicular) to both U and V U, V, and W form right-handed system! I.e., can use right-hand-rule on U and V (IN THAT ORDER) to get W Example: (X x Y) = Z axis! The length of W (= U X V) is equivalent to: …where again θ = smallest angle between U and V If U and V are parallel θ = 0° sin θ = 0 get zero vector for W!
19
CROSS PRODUCT: ORDER MATTERS!
WARNING! ORDER MATTERS with the cross product! Property of anti-commutativity REMEMBER THE RIGHT-HAND-RULE!!!
20
COMPUTING THE CROSS PRODUCT: SARRUS’S SCHEME
Follow diagonal arrows for each arrow multiply elements along arrow times sign at top ex = x axis, ey = y axis, ez = z axis
21
DETECTING AND SPLITTING CONCAVE POLYGONS
There are 2 ways we can do this: Vector method Check interior angles using cross product Rotational method Rotate each edge in line with X axis check if vertex below X axis
22
SPLITTING BY VECTOR METHOD
Transform to XY plane (if necessary) Get edge vectors in counterclockwise order: For each pair of consecutive edge vectors, get cross product If concave negative Z component split polygon along first vector in cross product pair Have to intersect this line with other edges Repeat process with two new polygons NOTE: 3 successive collinear points anywhere cross product becomes zero vector!
23
SPLITTING BY ROTATIONAL METHOD
Transform to XY plane (if necessary) For each vertex Vk: Move polygon so that Vk is at the origin Rotate polygon so that Vk+1 is on the X axis If Vk+2 is below X axis polygon is concave split polygon along x axis Repeat concave test for each of the two new polygons Stop when we’ve checked all vertices
24
SPLITTING A CONVEX POLYGON
Every 3 consecutive vertices make triangle Remove middle vertex Keep going until down to last 3 vertices
25
PLANE EQUATION Need plane equation: Need normal of polygon:
Collision detection, raytracing/raycasting, etc. Need normal of polygon: Lighting/shading Backface culling don’t draw polygon facing away from camera General equation of a plane: (x,y,z) = any point on the plane A,B,C,D = plane parameters ON the plane Ax + By + Cz + D = 0 BEHIND the plane Ax + By + Cz + D < 0 IN FRONT OF the plane Ax + By + Cz + D > 0
26
CALCULATING THE PLANE EQUATION
Divide the formula by D Pick any 3 noncollinear points in the polygon Solve set of 3 simultaneous linear plane equations to get A/D, B/D, and C/D use Cramer’s Rule
27
QUICK REVIEW: DETERMINANT OF A MATRIX
28
If THE POLYGON IS NOT CONTAINED IN A PLANE
Either: Divide into triangles OR: Find approximating plane Divide vertices into subsets of 3 Get plane parameters for each subset Get average plane parameters
29
NORMAL VECTOR Normal vector = gives us orientation of plane/polygon
Points towards OUTSIDE of plane From back face to front face Perpendicular to surface of plane Normal N = (A,B,C) parameters from plane equation! Although it doesn’t have to be, the normal vector is often normalized (i.e., length = 1)
30
GETTING NORMAL AND PLANE EQUATION
Solve for plane equation normal = (A,B,C) OR Get normal from edges using cross-product solve for D in plane equation V1, V2, and V3 = consecutive vertices in counterclockwise order: NOTE: Counterclockwise looking from outside the polygon towards inside
31
POINT-nORMAL PLANE EQUATION
Given the normal N and any point on the plane, the following holds true: A related, alternative equation for a plane is the point-normal form: …where V is any 3D point
32
EXAMPLE
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.