# COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.

## Presentation on theme: "COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015."— Presentation transcript:

COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015

COMP 175 | COMPUTER GRAPHICS Remco Chang2/6103b – Shapes  Points vs. Vectors  What are basis vectors?  In 2D, what 2 vectors cannot be basis vectors?  What is:  a unit vector  a normal vector  a null vector?  Vector math:  Add, subtract, multiple (by scalar)  Normalize a vector  What is a cross product?  How do you find the cross product?  Different ways to think about the cross product?  What is a dot product?  How do you find the dot product?  Different ways to think about the dot product?  Given two vectors A, B, show that the cross product N is orthogonal to A and B. Quick Review of Linear Algebra

COMP 175 | COMPUTER GRAPHICS Remco Chang3/6103b – Shapes  Lines and Polyline  Polyline: lines drawn between ordered points  Polygon  If the first and last points of a polyline are the same point, then the polyline is said to be “closed”, and that the closed polyline forms a polygon  Self-intersected polyline 2D Object Definition simple polygon, closed polyline not closed, simple polyline not simple polygon, closed polyline

COMP 175 | COMPUTER GRAPHICS Remco Chang4/6103b – Shapes  Convex and Concave polygons  Convex: for every pair of points inside the polygon, the line between them is entirely inside the polygon  Concave: for some pair of points inside the polygon, the line between them is not entirely inside the polygon. Not convex. 2D Object Definition convex concave

COMP 175 | COMPUTER GRAPHICS Remco Chang5/6103b – Shapes  Why is a convex polygon so awesome? 2D Object Definition

COMP 175 | COMPUTER GRAPHICS Remco Chang6/6103b – Shapes  Why is a convex polygon so awesome?  Center of mass  Tessellation  Subdivision  Fixed boundary  Exactly two intersections  All diagonals are within the boundary  Tessellation -> computing the area  Every interior angle is less than 180  Etc. 2D Object Definition

COMP 175 | COMPUTER GRAPHICS Remco Chang7/6103b – Shapes  Circle  Set of all points equidistant from one point called the center  The distance from the center is the radius r  The equation for a circle centered at (0, 0) is r 2 = x 2 + y 2 Special Polygons TriangleSquareRectangle (0, y) (0, x) r (0, 0) (x, y)

COMP 175 | COMPUTER GRAPHICS Remco Chang8/6103b – Shapes  A circle can be approximated by a polygon with many sides.  Axis aligned ellipse: a circle scaled in the x and/or y direction 2D Object Definition 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6 0 1 1 2 2 3 4 5 6 7 8 9 3 4 5 6

COMP 175 | COMPUTER GRAPHICS Remco Chang9/6103b – Shapes  Vertex and Edge tables  General purpose, minimal overhead, reasonably efficient  Each vertex listed once  Each edge is an ordered pair of indices to the vertex list Representing Shapes Vertices 0(0, 0) 1(2, 0) 2(0, 1) 3(2, 1) 4(1, 1.5) Edges 0(0, 1) 1(1, 3) 2(3, 4) 3(4, 2) 4(2, 0) E4E4 E3E3 E2E2 E0E0 E1E1 V0V0 V1V1 V2V2 V3V3 V4V4

COMP 175 | COMPUTER GRAPHICS Remco Chang10/6103b – Shapes  Most common representation of shape in three dimensions  All vertices of triangle are guaranteed to lie in one plane  (not true for quadrilaterals or other polygons)  Uniformity makes it easy to perform mesh operations such as subdivision, simplification, transformation etc.  Many different ways to represent triangular meshes Triangle Meshes

COMP 175 | COMPUTER GRAPHICS Remco Chang11/6103b – Shapes  Vertex, Face, (and Normal) Tables Triangular Mesh Representation Vertex List v0 0, 0, 0 f0 f1 f12 f15 f7 v1 1, 0, 0 f2 f3 f13 f12 f1 v2 1, 1, 0 f4 f5 f14 f13 f3 v3 0, 1, 0 f6 f7 f15 f14 f5 v4 0, 0, 1 f6 f7 f0 f8 f11 v5 1, 0, 1 f0 f1 f2 f9 f8 v6 1, 1, 1 f2 f3 f4 f10 f9 v7 0, 1, 1 f4 f5 f6 f11 f10 v8.5,.5, 0 f8 f9 f10 f11 v9.5,.5, 1 f12 f13 f14 f15 Face List f0v0 v4 v5 f1v0 v5 v1 f2v1 v5 v6 f3v1 v6 v2 f4v2 v6 v7 f5v2 v7 v3 f6v3 v7 v4 f7v3 v4 v0 f8v8 v5 v4 f9v8 v6 v5 f10v8 v7 v6 f11v8 v4 v7 f12v9 v5 v4 f13v9 v6 v5 f14v9 v7 v6 f15v9 v4 v7 v0 v1v2 f3 f2 f1 f0 f9 v8 v4 v7 v6 f10 f8 f11 v5

COMP 175 | COMPUTER GRAPHICS Remco Chang12/6103b – Shapes Questions?

COMP 175 | COMPUTER GRAPHICS Remco Chang13/6103b – Shapes Normals

COMP 175 | COMPUTER GRAPHICS Remco Chang14/6103b – Shapes Calculating Normal

COMP 175 | COMPUTER GRAPHICS Remco Chang15/6103b – Shapes 3D Barn Shape

COMP 175 | COMPUTER GRAPHICS Remco Chang16/6103b – Shapes 3D Barn Shape

COMP 175 | COMPUTER GRAPHICS Remco Chang17/6103b – Shapes 3D Barn Shape

COMP 175 | COMPUTER GRAPHICS Remco Chang18/6103b – Shapes  3D meshes can be represented as vertices, (edges), faces, and normals  Are there other ways to encode 3D meshes? Other Possible Encodings

COMP 175 | COMPUTER GRAPHICS Remco Chang19/6103b – Shapes Parametric Shapes

COMP 175 | COMPUTER GRAPHICS Remco Chang20/6103b – Shapes  2.5D objects are 3D objects that are “protrusions” or “extensions” of 2D shapes (i.e., 2D shape + height) 2.5D Objects

COMP 175 | COMPUTER GRAPHICS Remco Chang21/6103b – Shapes 3D Extrusions

COMP 175 | COMPUTER GRAPHICS Remco Chang22/6103b – Shapes  A spring can be described in Cartesian coordinate system as:  Or in cylindrical coordinate as: 3D Extrusions

COMP 175 | COMPUTER GRAPHICS Remco Chang23/6103b – Shapes Surfaces from Revolutions

COMP 175 | COMPUTER GRAPHICS Remco Chang24/6103b – Shapes  We can think of the shapes in assignment 2 the same way... ““Vertices in Motion”  So we can make 3D shapes out of 2D and 1D primitives Technically...

COMP 175 | COMPUTER GRAPHICS Remco Chang25/6103b – Shapes Questions?

COMP 175 | COMPUTER GRAPHICS Remco Chang26/6103b – Shapes  These two have the same number of quads…  What is the difference? GL Normal

COMP 175 | COMPUTER GRAPHICS Remco Chang27/6103b – Shapes GL Normal

COMP 175 | COMPUTER GRAPHICS Remco Chang28/6103b – Shapes glNormal3f(nx, ny, nz); glBegin(GL_QUADS); glVertex3f(x1, y1, z1); glVertex3f(x2, y2, z2); glVertex3f(x3, y3, z3); glVertex3f(x4, y4, z4); glEnd(); GL Normal

COMP 175 | COMPUTER GRAPHICS Remco Chang29/6103b – Shapes glBegin(GL_QUADS); glNormal3f(nx1, ny1, nz1); glVertex3f(x1, y1, z1); glNormal3f(nx2, ny2, nz2); glVertex3f(x2, y2, z2); glNormal3f(nx3, ny3, nz3); glVertex3f(x3, y3, z3); glNormal3f(nx4, ny4, nz4); glVertex3f(x4, y4, z4); glEnd(); GL Normal

COMP 175 | COMPUTER GRAPHICS Remco Chang30/6103b – Shapes  What are the normals?  For a circle / sphere?  For a cube?  For a cylinder?  For a cone?  How do you define what a normal is? GL Normal

COMP 175 | COMPUTER GRAPHICS Remco Chang31/6103b – Shapes  What are the normals?  For a circle / sphere?  For a cube?  For a cylinder?  For a cone?  Thinking of the normal of a curved surface as the normal to the tangent plane GL Normal

COMP 175 | COMPUTER GRAPHICS Remco Chang32/6103b – Shapes  Write a render function that takes in two parameters, radius and slices, and produces a 2D circle drawn as a set of polylines (assume centered at (0,0)), with a defined normal for each vertex  That is, fill in this function: void drawCircle2D(float radius, int slices) { : glBegin (...); for (int i=0; i<...) { : glNormal2f(...); glVertex2f(...); } glEnd(); } Exercise

COMP 175 | COMPUTER GRAPHICS Remco Chang33/6103b – Shapes Questions?

Download ppt "COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015."

Similar presentations