Chapter - TwoPartTwo
Chapter - TwoPartTwo
Polygons
Polygon
Representation
Polygon Faces
OpenGL Fill-Area
Functions
3
Polygons
Fill-area primitives (Polygons):
Any enclosed boundary
Filled by solid color or
Polygons
pattern
2D shapes with boundary
Polygon formed by connected
Representation straight line segments
Need ≥3 coplanar points
Polygons package
More efficient to fill a polygon
Convex?
Polygon
Representation
Check interior angles
Check the infinitely extended edge
N u E1 E2 sin
Check the cross product of pair of
Polygon Faces adjacent edge.
Concave Polygons
OpenGL Fill-Area At least 1 interior angle>180o
Functions
Degenerate Polygon
The polygon has less than 3 vertices; or
The polygon has collinear vertices; or
The polygon has non-coplanar vertices; or
The polygon has repeated vertices.
5
Splitting Concave Polygons-Vector
Technique
Compute the cross product of the
Polygons edges
Polygon
If it has different sign
Representation Extend the first edge of the pair till it
intersect to one of the other edges
Polygon Faces Split the polygon in to two
From the intersecting point
OpenGL Fill-Area
Functions
6
Polygon Representations
Polygons
Polygon
Representation
Polygon Faces
Using two types of table of data
OpenGL Fill-Area Geometric tables
Functions Store geometric information
like shapes and positions of the polygons
Attribute tables
Stores appearance information
like color and opacity
7
Polygon Front and Back Faces
Polygons as a part of 3D polygonal meshes
Front face: points outward from the object
Polygons
Back face: points twards the object interior
Polygon
Representation
Polygon Faces
OpenGL Fill-Area
Functions
8
Polygon Front and Back Faces
Polygons Normal vector :
A vector perpendicular to the plane of the
Polygons
polygon
Points away from the front face of the
Polygon
polygon
Representation
Polygon Faces
OpenGL Fill-Area
Functions
9
Computing Normal Vectors
Graphics packages compute the Normal Vector
automatically
By computing cross product of adjacent edges
Polygons Cross product is a vector perpendicular to the
two vectors
Polygon Considering the vertices
Representation anti-clockwise : normal vector points towards
us
Polygon Faces Clockwise: normal vector points away from us
E1 = (1,0,0)
E2 = (0,1,0)
OpenGL Fill-Area
N (0,0,1) N u E1 E2 sin
Functions
0 ≤ θ ≤ 180o
direction of the unit vectoru is
determined by the right-hand
rule
10
OpenGL Fill-Area Functions
All polygons must be convex
Polygons Vertices should be given in anti-
Polygon
clockwise direction
Representation We are watching it from outside of the
object
Polygon Normal
Vectors Default fill style is solid
By the given color settings
OpenGL Fill-Area
Functions 7 ways of drawing polygons
Using glRect* function
Using 6 different symbolic constants
with glBegin .... glEnd
11
OpenGL Fill-Area Functions 1.
Polygons
Polygon
Representation
Polygon Normal
Vectors
OpenGL Fill-Area
Functions glRecti(200,100,50,250);
OpenGL Fill-Area
Functions
13
OpenGL Fill-Area Functions 3.
glBegin(GL_TRIANGLES);
glVertex2iv(p1);
Polygons Front face is towards the
glVertex2iv(p2);
glVertex2iv(p6); camera . The points are
Polygon glVertex2iv(p3); given in anti-clockwise
Representation glVertex2iv(p4);
glVertex2iv(p5);
Polygon Normal glEnd();
Vectors
OpenGL Fill-Area
Functions
14
OpenGL Fill-Area Functions 4.
glBegin(GL_TRIANGLE_STRIP);
glVertex2iv(p1);
Polygons
glVertex2iv(p2);
glVertex2iv(p6);
Polygon glVertex2iv(p3);
Representation glVertex2iv(p5); The points for only first
glVertex2iv(p4); triangle are given in anti-
Polygon Normal glEnd(); clockwise
Vectors
OpenGL Fill-Area
Functions
15
OpenGL Fill-Area Functions 5.
glBegin(GL_TRIANGLE_FAN);
Polygons glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3); The first point of the first
Polygon
glVertex2iv(p4); triangle is the beginning
Representation
glVertex2iv(p5); of the fan. points are
glVertex2iv(p6); given in anti-clockwise
Polygon Normal glEnd();
Vectors
OpenGL Fill-Area
Functions
16
OpenGL Fill-Area Functions 6.
glBegin(GL_QUADS);
glVertex2iv(p1);
Polygons
glVertex2iv(p2);
glVertex2iv(p3);
Polygon The quadrilateral points
glVertex2iv(p4);
Representation are given in anti-clockwise
glVertex2iv(p5);
glVertex2iv(p6);
Polygon Normal glVertex2iv(p7);
Vectors glVertex2iv(p8);
glEnd();
OpenGL Fill-Area
Functions
17
OpenGL Fill-Area Functions 7.
glBegin(GL_QUAD_STRIP);
Polygons glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3); The first quadrilateral
Polygon glVertex2iv(p4);
Representation points are given in anti-
glVertex2iv(p5); clockwise
glVertex2iv(p6);
Polygon Normal glVertex2iv(p7);
Vectors glVertex2iv(p8);
glEnd();
OpenGL Fill-Area
Functions
Any Question?