CG MODULE-1 Part2
CG MODULE-1 Part2
2.1.1 Introduction
An useful construct for describing components of a picture is an area that is filled with
some solid color or pattern.
A picture component of this type is typically referred to as a fill area or a filled area.
Any fill-area shape is possible, graphics libraries generally do not support specifications
VTUPulse.com
for arbitrary fill shapes
Figure below illustrates a few possible fill-area shapes.
Graphics routines can more efficiently process polygons than other kinds of fill shapes
because polygon boundaries are described with linear equations.
1
Module 2 Fill Area Primitives
Below figure shows the side and top surfaces of a metal cylinder approximated in an
outline form as a polygon mesh.
Displays of such figures can be generated quickly as wire-frame views, showing only the
polygon edges to give a general indication of the surface structure
Objects described with a set of polygon surface patches are usually referred to as standard
graphics objects, or just graphics objects.
VTUPulse.com
or sides of the polygon.
It is required that the polygon edges have no common point other than their endpoints.
Thus, by definition, a polygon must have all its vertices within a single plane and there
can be no edge crossings
Examples of polygons include triangles, rectangles, octagons, and decagons
Any plane figure with a closed-polyline boundary is alluded to as a polygon, and one
with no crossing edges is referred to as a standard polygon or a simple polygon
Problem:
For a computer-graphics application, it is possible that a designated
set ofpolygonvertices do not all lie exactly in one plane
This is due to roundoff error in the calculation of numerical
values, o
t erors in selecting coordinate positions for the vertices, or, more typically, to
approximating a curved surface with a set of polygonal patches
Solution:
To divide the specified surface mesh into triangles
2
Module 2 Fill Area Primitives
Polygon Classifications
Polygons are classified into two types
✓ Convex Polygon and
✓ Concave Polygon
Convex Polygon:
The polygon is convex if all interior angles of a polygon are less than or equal to 180◦,
where an interior angle of a polygon is an angle inside the polygon boundary that is
formed by two adjacent edges
An equivalent definition of a convex polygon is that its interior lies completely on one
side of the infinite extension line of any one of its edges.
Also, if we select any two points in the interior of a convex polygon, the line segment
joining the two points is also in the interior.
Concave Polygon:
A polygon that is not convex is called a
concavepolygon. Te below figure shows convex and concave
polygon
VTUPulse.com
The term degenerate polygon is often used to describe a set of vertices
thatare collinear or that have repeated coordinate positions.
3
Module 2 Fill Area Primitives
Identification algorithm 1
Identifying a concave polygon by calculating cross-products of successive pairs of edge
vectors.
If we set up a vector for each polygon edge, then we can use the cross-product of adjacent
edges to test for concavity. All such vector products will be of the same sign (positive or
negative) for a convex polygon.
Therefore, if some cross-products yield a positive value and some a negative value, we
have a concave polygon
VTUPulse.com
Identification algorithm 2
Look at the polygon vertex positions relative to the extension line of any edge.
If some vertices are on one side of the extension line and some vertices are on the other
side, the polygon is concave.
4
Module 2 Fill Area Primitives
Vector method
First need to form the edge vectors.
Given two consecutive vertex positions, Vk and Vk+1, we define the edge vector between
them as
Ek = Vk+1 – Vk
Calculate the cross-products of successive edge vectors in order around the polygon
perimeter.
If the z component of some cross-products is positive while other cross-products have a
negative z component, the polygon is concave.
We can apply the vector method by processing edge vectors in counterclockwise order If
any cross-product has a negative z component (as in below figure), the polygon is
VTUPulse.com
concave and we can split it along the line of the first edge vector in the cross-product pair
E1 = (1, 0, 0) E2 = (1, 1, 0)
E3 = (1, −1, 0) E4 = (0, 2, 0)
E5 = (−3, 0, 0) E6 = (0, −2, 0)
5
Module 2 Fill Area Primitives
E5 × E6 = (0, 0, 6) E6 × E1 = (0, 0, 2)
Since the cross-product E2 × E3 has a negative z component, we split the polygon along
the line of vector E2.
The line equation for this edge has a slope of 1 and a y intercept of −1 . No other edge
cross-products are negative, so the two new polygons are both convex.
Rotational method
Proceeding counterclockwise around the polygon edges, we
shift the position of the polygon so that each vertex Vk
in turn is at the coordinate origin.
We rotate the polygon about the origin in a clockwise
direction so that the next vertex Vk+1 is on the x axis.
If the following vertex, Vk+2, is below the x
axis, the polygon is concave.
We then split the polygon along the x axis to form two
VTUPulse.com
new polygons, and we repeat the concave test for each
of the two new polygons
6
Module 2 Fill Area Primitives
Inside-Outside Tests
Also called the odd-parity rule or the even-odd rule.
Draw a line from any position P to a distant point outside the coordinate extents of the
closed polyline.
Then we count the number of line-segment crossings along this line.
If the number of segments crossed by this line is odd, then P is considered to be an
interior point Otherwise, P is an exterior point
VTUPulse.com
We can use this procedure, for example,to fill the interior region between two concentric
circles or two concentric polygons with a specified color.
7
Module 2 Fill Area Primitives
The nonzero winding-number rule tends to classify as interior some areas that the odd-
even rule deems to be exterior.
Variations of the nonzero winding-number rule can be used to define interior regions in
other ways define a point to be interior if its winding number is positive or if it is
negative; or we could use any other rule to generate a variety of fill shapes
VTUPulse.com
Boolean operations are used to specify a fill area as a combination of two regions
One way to implement Boolean operations is by using a
variation of the basic winding-number rule consider the
direction for each boundary to be counterclockwise, the
union of two regions would consist of those points
whose winding number is positive
8
Module 2 Fill Area Primitives
Polygon Tables
The objects in a scene are described as sets of polygon surface facets
The description for each object includes coordinate information specifying the geometry for
the polygon facets and other surface parameters such as color, transparency, and light-
reflection properties.
The data of the polygons are placed into tables that are to be used in the subsequent
processing, display, and manipulation of the objects in the scene
These polygon data tables can be organized into two groups:
Geometric tables and
Attribute tables
Geometric data tables contain vertex coordinates and parameters to identify the spatial
VTUPulse.com
orientation of the polygon surfaces.
Attribute information for an object includes parameters specifying the degree of
transparency of the object and its surface reflectivity and texture characteristics
Geometric data for the objects in a scene are arranged conveniently in three lists: a vertex
table, an edge table, and a surface-facet table.
Coordinate values for each vertex in the object are stored in the vertex table.
The edge table contains pointers back into the vertex table to identify the vertices for
each polygon edge.
And the surface-facet table contains pointers back into the edge table to identify the edges
for each polygon
9
Module 2 Fill Area Primitives
The object can be displayed efficiently by using data from the edge table to
identifypolygon boundaries.
An alternative arrangement is to use just two tables: a vertex table and a surface-
facet table this scheme is less convenient, and some edges could get drawn twice in a wire-
frame display.
Another possibility is to use only a surface-facet table, but this duplicates coordinate
information, since explicit coordinate values are listed for each vertex in each polygon
VTUPulse.com
facet. Also the relationship between edges and facets would have to be reconstructed from
the vertex listings in the surface-facet table.
We could expand the edge table to include forward pointers into the surface-facet
table sothat a common edge between polygons could be identifiedmore rapidly the vertex
table could be expanded to reference corresponding edges, for faster information retrieval
Because the geometric data tables may contain extensive listings of vertices and edges
forcomplex objects and scenes, it is important that the data be checked for consistency
and completeness.
Some of the tests that could be performed by a graphics package are
(1) that every vertex is listed as an endpoint for at least two edges,
10
Module 2 Fill Area Primitives
Plane Equations
Each polygon in a scene is contained within a plane of infinite extent.
The general equation of a plane is
Ax + B y + C z + D = 0
Where,
(x, y, z) is any point on the plane, and
The coefficients A, B, C, and D (called plane parameters) are constants
describing the spatial properties of the plane.
We can obtain the values of A, B, C, and D by solving a set of three plane equations using
the coordinate values for three noncollinear points in the plane for the three successive
VTUPulse.com
convex-polygon vertices, (x1, y1, z1), (x2, y2, z2), and (x3, y3, z3), in a counterclockwise
order and solve the following set of simultaneous linear plane
equations for the ratios A/D, B/D, and C/D:
(A/D)xk + (B/D)yk + (C/D)zk = −1, k = 1, 2, 3
The solution to this set of equations can be obtained in determinant form, using Cramer’s
rule, as
Expanding the determinants, we can write the calculations for the plane coefficients n
i
the form
11
Module 2 Fill Area Primitives
It is possible that the coordinates defining a polygon facet may not be contained withina
single plane.
We can solve this problem by dividing the facet into a set of triangles; or we could find
an approximating plane for the vertex list.
One method for obtaining an approximating plane is to divide the vertex list into subsets,
where each subset contains three vertices, and calculate plane parameters A, B, C, Dfor
each subset.
VTUPulse.com
Any point that is not on the plane and that is visible to the front face of a polygon surface
section is said to be in front of (or outside) the plane, and, thus, outside the object.
And any point that is visible to the back face of the polygon is behind (or inside) the
plane.
Plane equations can be used to identify the position of spatial points relative to the
polygon facets of an object.
For any point (x, y, z) not on a plane with parameters A, B, C, D, we have
Ax + B y + C z + D != 0
Thus, we can identify the point as either behind or in front of a polygon surface contained
within that plane according to the sign (negative or positive) of
Ax + By + Cz + D:
if Ax + B y + C z + D < 0, the point (x, y, z) is behind the plane
if Ax + B y + C z + D > 0, the point (x, y, z) is in front of the plane
Orientation of a polygon surface in space can be described with the normal vector for
theplane containing that polygon
12
Module 2 Fill Area Primitives
The normal vector points in a direction from inside the plane to the outside; that is,
fromthe back face of the polygon to the front face.
Thus, the normal vector for this plane is N = (1, 0, 0), which is in the direction of
thepositive x axis.
That is, the normal vector is pointing from inside the cube to the outside andis
perpendicular to the plane x = 1.
The elements of a normal vector can also be obtained using a vector crossproduct
Calculation.
We have a convex-polygon surface facet and a right-handed Cartesian system, we again
VTUPulse.com
select any three vertex positions,V1,V2, and V3, taken in counterclockwise order when
viewing from outside the object toward the inside.
Forming two vectors, one from V1 to V2 and the second from V1 to V3, we calculate
Nas the vector cross-product:
N = (V2 − V1) × (V3 − V1)
This generates values for the plane parameters A, B, and C.We can then obtain the value
for parameter D by substituting these values and the coordinates in
Ax + B y + C z + D = 0
The plane equation can be expressed in vector form using the normal N and the position
P of any point in the plane as
N·P = −D
13