CS 450: Computer Graphics OVERVIEW OF POLYGONS

Slides:



Advertisements
Similar presentations
Vectors, Points, Lines and Planes Jim Van Verth Lars M. Bishop
Advertisements

Computer Graphics- SCC 342
CS 450: COMPUTER GRAPHICS LINEAR ALGEBRA REVIEW SPRING 2015 DR. MICHAEL J. REALE.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
CMPE 466 COMPUTER GRAPHICS
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Vector Calculus Mengxia Zhu Fall Objective Review vector arithmetic Distinguish points and vectors Relate geometric concepts to their algebraic.
Shared Graphics Skills Cameras and Clipping Planes
Classes of Polygons Planar polygons Non-planar polygons Simple
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
Computational Geometry & Collision detection
12 VECTORS AND THE GEOMETRY OF SPACE.
Introduction It is not uncommon for people to think of geometric figures, such as triangles and quadrilaterals, to be separate from algebra; however, we.
Chapter 3 Vectors.
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
Hidden Line Removal Adopted from U Strathclyde’s course page.
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Class 25: Question 1 Which of the following vectors is orthogonal to the row space of A?
Chapter 2: Vectors Ian Parberry University of North Texas Fletcher Dunn Valve Software 3D Math Primer for Graphics and Game Development.
Vectors.
Linear Algebra Review CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005.
CS 450: Computer Graphics 2D TRANSFORMATIONS
CSE554SimplificationSlide 1 CSE 554 Lecture 7: Simplification Fall 2014.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
Chapter 3. Vector 1. Adding Vectors Geometrically
2IV60 Computer Graphics Basic Math for CG
Geometric Intuition Randy Gaul. Vectors, Points and Basis Matrices Rotation Matrices Dot product and how it’s useful Cross product and how it’s useful.
Geometry Vocabulary Test Ms. Ortiz. 1. If two parallel lines are cut by a transversal, then the corresponding angles are congruent.
Chapter 3 Vectors.
Mathematical Fundamentals
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Introduction to 3D Graphics Lecture 4: Scenes and Scene Graphs Anthony Steed University College London.
Chapter 4.1 Mathematical Concepts
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
CS 450: COMPUTER GRAPHICS QUATERNIONS SPRING 2015 DR. MICHAEL J. REALE.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
CS 325 Introduction to Computer Graphics 02 / 17 / 2010 Instructor: Michael Eckmann.
Methods and Solving Equations
Introduction to Computational Geometry Hackson
VECTORS. A vector is a quantity that has both magnitude and direction. It is represented by an arrow. The length of the vector represents the magnitude.
Geometric Objects and Transformation
CSE554SimplificationSlide 1 CSE 554 Lecture 7: Simplification Fall 2013.
CSE554Fairing and simplificationSlide 1 CSE 554 Lecture 6: Fairing and Simplification Fall 2012.
Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.
Background Mathematics Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
Chapter 3 Vectors. Vector quantities  Physical quantities that have both numerical and directional properties Mathematical operations of vectors in this.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
VECTORS AND THE GEOMETRY OF SPACE. The Cross Product In this section, we will learn about: Cross products of vectors and their applications. VECTORS AND.
Computer Graphics Matrices
CSCE 552 Fall 2012 Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Basic Theory (for curve 01). 1.1 Points and Vectors  Real life methods for constructing curves and surfaces often start with points and vectors, which.
Unit 10 Transformations. Lesson 10.1 Dilations Lesson 10.1 Objectives Define transformation (G3.1.1) Differentiate between types of transformations (G3.1.2)
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
Computer Graphics Mathematical Fundamentals Lecture 10 Taqdees A. Siddiqi
Vectors in the Plane 8.3 Part 1. 2  Write vectors as linear combinations of unit vectors.  Find the direction angles of vectors.  Use vectors to model.
Chapter 3 Vectors. Vector quantities  Physical quantities that have both numerical and directional properties Mathematical operations of vectors in this.
Properties of Transformations. Translate Figures and Use Vectors Translation: moves every point of a figure the same distance in the same direction Image:
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Computer Graphics Lecture 21 Triangles and Planes Taqdees A
Math Fundamentals Maths revisit.
Lecture 13 Clipping & Scan Conversion
Parallel and Perpendicular Lines/Triangles and Transformations
Game Programming Algorithms and Techniques
Polygons.
Presentation transcript:

CS 450: Computer Graphics OVERVIEW OF POLYGONS Spring 2015 Dr. Michael J. Reale

INTRODUCTION TO POLYGONS

INTRODUCTION So far, we’ve talked mostly about points, lines, and curves Fill area (or filled area) = some area that needs to be filled in with a solid color or pattern Usually used to describe the surface of an object (but not always) Usually polygons (but not always)

WHY POLYGONS? Most graphics libraries force you to use polygons for filled areas Why? Polygon boundaries can be described with linear equations Makes fill algorithms more efficient Can approximate most curved surfaces with polygons Similar to approximating curve with line segments Makes shading easier (especially if polygons are triangles  single plane per triangle) Can still create the illusion of a curved/complicated surface with tricks like phong shading and normal mapping 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 http://www.guru3d.com/articles-pages/radeon-hd-5870-review-test,7.html

WHAT IS A POLYGON, EXACTLY? The official definition varies, but at bare minimum: 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

DOES A POLYGON LIE IN A SINGLE PLANE? In computer graphics, polygon not always in same plane: Round-off error I.e., points originally in single plane, but, after transformation, the points may be slightly off Fitting to surface makes non-planar polygons E.g., if using quads, approximation may “bend” the quad in half Thus, we usually use triangles to avoid this problem

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  generates shape with: Extraneous lines Overlapping edges Edges with length 0

CONVEX VS. CONCAVE: BY INTERIOR ANGLE Interior angle = angle inside polygon boundary formed by two adjacent edges Convex = all interior angles less than 180° Concave = one or more interior angles greater than or equal to 180°

CONVEX VS. CONCAVE: BY PICKING SIDES Another way to define convex vs. concave is to look at each line formed by each edge and see if all other vertices on one side or not 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

CONVEX VS. CONCAVE: CORNY MEMORY HOOK

DEALING WITH DEGENERATES AND CONCAVE POLYGONS Most graphics software packages (i.e., OpenGL) can’t really deal with the degenerate polygons To avoid extra processing, however, they leave it as the programmer’s problem Concave polygons are more complicated to deal with when it comes to filling algorithms Solution: split concave polygon into convex polygons (e.g., triangles) Again, often have to do this yourself OpenGL “requires” that all polygons be convex (or at least, there’s no guarantee the filling will work if not convex)

BRIEF VECTOR MATH REVIEW

INTRODUCTION Before we go any further, we’ll need to quickly review some concepts from linear algebra We will revisit these concepts in a future, more thorough review For now, let’s talk about: Vectors Vector length Scaling vectors Normalized vectors Adding/subtracting vectors Dot product Cross product

What’s your vector, victor? A vector is basically a (N x 1) or (1 x N) matrix (# of rows X # of columns) In computer graphics: N is usually 2, 3, or 4 (homogeneous coordinates) Usually 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 Scalar = single value (or 1x1 vector) http://www.spudislunarresources.com/blog/wp-content/uploads/2013/03/Airplane.jpg

INTERPRETING VECTORS A vector can also be interpreted as: …in space Location (w = 1) Direction (w = 0) …in space

LENGTH OF A VECTOR We usually use Euclidean distance to get the length of a vector: The square of the distance (not surprisingly) is given by:

ZERO VECTOR A vector with a length of zero is called the zero vector:

SCALING VECTORS To multiply a scalar by a vector, you multiple that scalar by the components of the vector Example: multiply 5 by a 3D vector A

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.

ADDING/SUBTRACTING VECTORS To add/subtract vectors, you add/subtract their respective components:

GEOMETRIC INTERPRETATION OF ADDING/SUBTRACTING (DIRECTION) VECTORS Adding  putting head of one vector on tail of the other Subtracting  gives direction from one endpoint to the other

DOT PRODUCT Given two 3D vectors A and B, the dot product of A and B is given by: Basically: Multiple corresponding components Add them together NOTE: Result is a single number (i.e., scalar)  another name for the dot product is the scalar product

DOT PRODUCT WITH YOURSELF The dot product of a vector A with itself is equal to the square of its length:

DOT PRODUCT: WHAT DOES IT MEAN? The dot product of two vectors A and B is in fact equivalent to: …where θ = smallest angle between the two vectors (Basically it has to do with projecting one vector on another; we’ll discuss this later) If the vectors are normalized, then:

DOT PRODUCT: CHECKING ANGLES Remember: DOT PRODUCT: CHECKING ANGLES What this means: (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  )

CROSS PRODUCT 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!

LENGTH OF CROSS PRODUCT 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!

CROSS PRODUCT: ORDER MATTERS! WARNING! ORDER MATTERS with the cross product! Property of anti-commutativity REMEMBER THE RIGHT-HAND-RULE!!!

COMPUTING THE CROSS PRODUCT To compute the cross product:

COMPUTING THE CROSS PRODUCT: SARRUS’S SCHEME An easier way to remember this is with a method called 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

IDENTIFYING AND SPLITTING CONCAVE POLYGONS

DETECTING CONCAVE POLYGONS We can do this one of two ways: Check interior angles for one greater than 180° For each edge line, check if vertices are all on the same side  if not, concave

CHECKING INTERIOR ANGLES Treat each edge as a vector (go counterclockwise): For each pair of consecutive edge vectors, get cross product If convex  signs of all cross products will be the same In 2D  cross product will always be +Z or –Z In 3D  transform polygon to XY plane (as best we can) If concave  one or more will be different NOTE: This breaks down if we have 3 successive collinear points anywhere  cross product becomes zero vector!

SPLITTING A CONCAVE POLYGON There are 2 ways we can do this: Vector method Rotational method

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 a cross product has a negative z component  split polygon along first vector in cross product pair Have to intersect this line with other edges

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

SPLITTING A CONVEX POLYGON Once we have a convex polygon(s), it is usually beneficial to split it into triangles: Every 3 consecutive vertices  make triangle Remove middle vertex Keep going until down to last 3 vertices

POLYGONS, PLANES, and NORMALS

INTRODUCTION We’re going to assume at this point that each polygon we have fits into a single plane (triangle or not) One very important piece of information we need to know is what is the front (and back) of our polygon Need this for: Lighting/shading Backface culling (i.e., not drawing polygons that face away from the camera) More generally, we also would like to know the equation of the plane the polygon rests in Useful for collision detection and/or raytracing

PLANE EQUATION Each polygon in our 3D scene is contained within a plane of infinite extent The general equation of a plane is as follows: (x,y,z) = any point on the plane A,B,C,D = plane parameters

CALCULATING THE PLANE EQUATION To get the plane parameters: 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:

USING CRAMER’S RULE It turns out you can use something called Cramer’s Rule to solve this Basically, the solutions for A, B, C, and D are given by the following determinants: More information on Cramer’s Rule: http://www.purplemath.com/modules/cramers.htm http://2000clicks.com/MathHelp/AlgebraOnline/a000926PointsLines3d.htm

QUICK REVIEW: DETERMINANT OF A MATRIX

GETTING THE DETERMINANTS Expanding the determinants gives us the answers for A,B,C, and D This will actually work even when D = 0 (technically you can’t use Cramer’s Rule under those circumstances, but the workaround actually gives you the same answer)

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

FRONT AND BACK Each polygon has a front face and a back face We can use the plane equation to determine if a given point (x,y,z) is: 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 NOTE: This is valid for a right-handed coordinate system, so we should also make sure our vertices are ordered counterclockwise!

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)

GETTING THE NORMAL VECTOR FROM EDGES You can also compute the normal vector directly from the edges using the cross-product Assuming V1, V2, and V3 are consecutive vertices of a convex polygon in counterclockwise order: Can also use this approach to get A, B, and C, and then solve for D. NOTE: Counterclockwise looking from outside the polygon towards inside

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 Basically, think of a vector going from P (a point on the plane) to some other point V. If that vector is on the plane, it should be orthogonal to the normal (hence, the dot product with be 0).

EXAMPLE