0% found this document useful (0 votes)
15 views80 pages

CG Unit - 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views80 pages

CG Unit - 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 80

UNIT- II

Polygons: Polygons and its types, inside test, Polygon filling methods: Seed – Flood
fill and Boundary Fill, Scan-line Fill algorithm 2D Transformations: Translation,
Scaling, Rotation, Reflection and Shearing, Matrix representation and homogeneous
coordinate system, composite transformations 3D Transformation: Translation, scaling,
rotation about X, Y, Z & arbitrary axis, and reflection about XY, YZ, XZ & arbitrary
plane.
Projections: Types of projections- Parallel, Perspective Parallel oblique: Cavalier,
Cabinet, Orthographic isometric, diametric, trimetric Perspective: vanishing points as 1
point, 2 point and 3 point.
08 Hours
Polygons

Polygon is a representation of the surface. It is primitive which is closed in nature. It is


formed using a collection of lines. It is also called as many-sided figure. The lines combined
to form polygon are called sides or edges. The lines are obtained by combining two vertices.

Example of Polygon:
• Triangle
• Rectangle
• Hexagon
• Pentagon
Polygons
Following figures shows some polygons.
Polygons

Types of Polygons
• Concave: A non-convex polygon is said to be
concave. A concave polygon has one interior angle
greater than 180°. So that it can be clipped into
similar polygons.

• Convex: A polygon is called convex of line joining


any two interior points of the polygon lies inside the
polygon.
Polygons

A polygon can be positive or


negative oriented. If we visit
vertices and vertices visit
produces counter clockwise
circuit, then orientation is said
to be positive.
Even Odd method & Winding number Method-Inside & Outside Test of
a Polygon
A polygon may be represented as a number of line segments connected, end to form a closed
figure.
Polygons can be represented in two ways –
• outline from using move commands
• as a solid objects by setting the pixels high inside the polygon including pixels on the
boundary.
To determine a point lies inside a polygon or not, in computer graphics, we have two
methods:
i. Even-Odd method (odd-parity rule)
ii. Winding number Method-Inside
Even-Odd method :
Constructing a line segment between the point (P) to be examined and a known point
outside the polygon is the one way to determine a point lies inside a polygon or not. The
number of times the line segment intersects the polygon boundary is then counted. The
point (P) is an internal point if the number of polygon edges intersected by this line is
odd; otherwise, the point is an external point.
In the figure, the line segment from ‘A’ crosses single edge & hence point A is inside the
polygon. The point B is also inside the polygon as the line segment from B crosses three
(odd) edges. But point C is outside the polygon it as the line segment from C crosses two
(even) edges.
Even-Odd method :
But this even-odd test fails when the
intersection point is a vertex. To handle this
case, we have to make few modifications. We
must look at the other end points of the two
segments of a polygon which meet at this
vertex.

If these points lies on the same side of the constructed line A’P’, then the intersection point
counts as an even number of intersection. But if they lie on the opposite side of constructed
line AP, then the intersection points counts as a single intersection.
Even-Odd method :

As we can see the line segment A’P’


intersects at M which is a vertex and L &
Z are the other end points of the two
segments meeting at M. L & Z lie on
same side of the line segment A’P’, so
the count is taken as even.
Winding Number Method :
There is another alternative method for defining a polygons’ interior point is called the
winding number method. Conceptually, one can stretch a piece of elastic between the point (P)
to be checked and the point on the polygon boundary.
Treat that, elastic is tied to point (P) to be checked firmly and the other end of the elastic is
sliding along the boundary of the polygon until it has made one complete circuit. Then we
check that how many times the elastic has been wound around the point of intersection. If it is
wound at-least once, point is inside. If there is no net winding then point is outside.
In this method, instead of just counting the intersections, we give each boundary line crossed a
direction number, and we sum these directions numbers. The direction number indicates the
direction of the polygon edge was drawn relative to the line segment we constructed for the
test.
Winding Number Method :

Example : To test a point (xi, yi), let us consider a horizontal line segment y = yi which
runs from outside the polygon to (xi, yi). We find all the sides which crossed this line
segment.
Now there are 2 ways for side to cross, the side could be drawn starting below end, cross it
and end above the line. In this case we can give direction numbers – 1, to the side or the
edge could start above the line & finish below it in this case, given a direction 1. The sum
of the direction numbers for the sides that cross the constructed horizontal line segment
yield the “Winding Number” for the point.
If the winding number is non-zero , the point is interior to polygon, else, exterior to
polygon.
Winding Number Method :
In the above figure, the line segment crosses 4
edges having different direction numbers : 1, -1,
1& -1 respectively, then :
Winding Number = 1 + (-1) + 1 + (-1) = 0
So the point P is outside the Polygon. The edge
has direction Number -1 because it starts below
the line segment & finishes above. Similarly,
edge has direction Number +1 because it starts
from above the line segment & finishes below
the line segment (See the directions in the
figure).
Polygon filling Method :

Flood Fill Algorithm:


In this flood-fill algorithm, a seed point is taken inside the polygon. The flood fill algorithm
is used when the polygon has multiple color boundaries. In this method, the related pixels
are replaced with the selected color using fill color. The selected pixel values before are
reassigned with the selected color value. This can be done using two approaches either 4-
connected or 8-connected.
Function floodfill(x, y, fillcolor, previouscolor)
if (getpixel (x, y) = previouscolor)
{
setpixel (x, y, fillcolor);
floodfill( x+1, y, fillcolor,previouscolor);
floodfill( x-1, y, fillcolor,previouscolor);
floodfill( x, y+1, fillcolor,previouscolor);
floodfill( x, y-1, fillcolor,previouscolor);
}
getpixel() - The color of specified pixel.
setpixel() - Sets the pixel to specified color.
Polygon filling Method :

Advantages:
• This method is easy to fill colors in computer graphics.
• It fills the same color inside the boundary.

Disadvantages:
• Fails with large area polygons.
• It is a slow method to fill the area.
Polygon filling Method :

Boundary Fill Algorithm:


The boundary fill algorithm uses polygon boundaries. It is also called an edge fill algorithm.
In this method, a seed point is taken in the polygon boundary and checks whether the
adjacent or neighbouring pixel is colored or not. If the adjacent pixel is not colored then, fill
it. This can be done using two approaches: 4-connected or 8-connected.
Function boundaryfill(x, y, color, color1)
int c;
c = getpixel(x ,y);
if (c! =color) & (c!=color1)
{
setpixel (x, y, color);
boundaryfill( x+1, y, color, color1);
boundaryfill( x-1, y, color, color1);
boundaryfill( x, y+1, color, color1);
boundaryfill( x, y-1, color, color1);
}
Polygon filling Method :

Advantages:
• The boundary fill algorithm is used to create attractive paintings.

Disadvantages:
• In the 4-connected approach, it does not color corners.
Polygon filling Method :

Scan Fill Algorithm:


Scan fill algorithm is an area-filling algorithm that fill colors by scanning horizontal lines.
These horizontal lines intersect the boundaries of the polygon and fill colors between the
intersection points. Its main purpose is to fill colors in the interior pixels of the polygon.
Polygon filling Method :

Advantages:
• Scan fill algorithm fills the polygon in the same order as rendering.
• It takes advantage of coherence thus, a fast algorithm.

Disadvantages:
• The intensity of the pixels is unequal.
• Staircase-like appearance when scan line converted to circles.
Polygon filling Method :

Advantages:
• Scan fill algorithm fills the polygon in the same order as rendering.
• It takes advantage of coherence thus, a fast algorithm.

Disadvantages:
• The intensity of the pixels is unequal.
• Staircase-like appearance when scan line converted to circles.
2D Transformations :

Types of Transformations:

• Translation

• Scaling

• Rotating

• Reflection

• Shearing
Translation :

It is the straight line movement of an object from one position to another is called
Translation. Here the object is positioned from one coordinate location to another.

Translation of point:
To translate a point from coordinate position (x, y) to another (x1 y1), we add algebraically
the translation distances Tx and Ty to original coordinate. The translation pair (Tx,Ty) is
called as shift vector.
x1=x+Tx
y1=y+Ty
Translation :

Translation is a movement of objects without deformation. Every position or point is


translated by the same amount.
When the straight line is translated, then it will be drawn using endpoints. For translating
polygon, each vertex of the polygon is converted to a new position.
Similarly, curved objects are translated. To change the position of the circle or ellipse its
center coordinates are transformed, then the object is drawn using new coordinates.
Translation :

Let P is a point with coordinates (x, y).


It will be translated as (x1 y1).

Matrix for Translation:


Scaling :

• It is used to alter or change the size of objects. The change is done using scaling
factors. There are two scaling factors, i.e. Sx in x direction Sy in y-direction. If the
original position is x and y. Scaling factors are Sx and Sy then the value of coordinates
after scaling will be x1 and y1.
• If the picture to be enlarged to twice its original size then Sx = Sy =2. If Sxand Sy are
not equal then scaling will occur but it will elongate or distort the picture.
Scaling :

• If scaling factors are less than one, then the size of the object will be reduced. If
scaling factors are higher than one, then the size of the object will be enlarged.
• If Sx and Sy are equal it is also called as Uniform Scaling. If not equal then called as
Differential Scaling. If scaling factors with values less than one will move the object
closer to coordinate origin, while a value higher than one will move coordinate
position farther from origin.
Scaling :
Enlargement: If T1= ,If (x1 y1)is original position and T1is translation vector then
(x2 y2) are coordinated after scaling

The image will be enlarged two times


Scaling :

Reduction: If T1= . If (x1 y1) is original position and T1 is translation


vector, then (x2 y2) are coordinates after scaling
Scaling :

Matrix for Scaling


Rotation :
• It is a process of changing the angle of the object. Rotation can be clockwise or
anticlockwise. For rotation, we have to specify the angle of rotation and rotation point.
Rotation point is also called a pivot point. It is print about which object is rotated.
Types of Rotation:
1. Anticlockwise
2. Counter clockwise
• The positive value of the pivot point (rotation angle) rotates an object in a counter-
clockwise (anti-clockwise) direction.
• The negative value of the pivot point (rotation angle) rotates an object in a clockwise
direction.
• When the object is rotated, then every point of the object is rotated by the same angle.
Rotation :

• Straight Line: Straight Line is rotated by the endpoints with the same angle and
redrawing the line between new endpoints.

• Polygon: Polygon is rotated by shifting every vertex using the same rotational angle.
• Curved Lines: Curved Lines are rotated by repositioning of all points and drawing
of the curve at new positions.

• Circle: It can be obtained by center position by the specified angle.


• Ellipse: Its rotation can be obtained by rotating major and minor axis of an ellipse by
the desired angle.
Rotation :
Rotation :
Rotation :

Matrix for rotation is a clockwise direction.

Matrix for rotation is an anticlockwise direction.


Reflection :

It is a transformation which produces a mirror image of an object. The mirror image can be
either about x-axis or y-axis. The object is rotated by180°.

Types of Reflection:
1. Reflection about the x-axis
2. Reflection about the y-axis
3. Reflection about an axis perpendicular to xy plane and passing through the origin
4. Reflection about line y=x
Reflection :
Reflection about x-axis: The object can be
reflected about x-axis with the help of the
following matrix

In this transformation value of x will remain


same whereas the value of y will become
negative. Following figures shows the
reflection of the object axis. The object will lie
another side of the x-axis.
Reflection :
Reflection about y-axis: The object can be reflected about y-axis with the help of following
transformation matrix

Here the values of x will be


reversed, whereas the value of y
will remain the same. The object
will lie another side of the y-axis.
Reflection :
Reflection about an axis perpendicular to xy plane and passing through origin:
In the matrix of this transformation is given below

In this value of x and y both


will be reversed. This is also
called as half revolution about
the origin.
Reflection :

Reflection about line y=x: The object may be reflected about line y = x with the help of
following transformation matrix

First of all, the object is rotated at 45°.


The direction of rotation is clockwise.
After it reflection is done concerning
x-axis. The last step is the rotation of
y=x back to its original position that is
counter clockwise at 45°.
Shearing :

It is transformation which changes the shape of object. The sliding of layers of object occur.
The shear can be in one direction or in two directions.
Shearing in the X-direction: In this horizontal shearing sliding of layers occur. The
homogeneous matrix for shearing in the x-direction is shown below:

Shearing in the Y-direction: Here shearing is done by sliding along vertical or y-axis.
Shearing :

Shearing in X-Y directions: Here layers will be slided in both x as well as y direction. The
sliding will be in horizontal as well as vertical direction. The shape of the object will be
distorted. The matrix of shear in both directions is given by:
Shearing :
3D Transformation :

Types of Transformations:

• Translation

• Scaling

• Rotating
Translation :
It is the movement of an object from one position to another position. Translation is done
using translation vectors. There are three vectors in 3D instead of two. These vectors are in
x, y, and z directions. Translation in the x-direction is represented using Tx. The translation
is y-direction is represented using Ty. The translation in the z- direction is represented using
Tz.
If P is a point having co-ordinates in three directions (x, y, z) is translated, then after
translation its coordinates will be (x1 y1 z1) after translation. Tx Ty Tz are translation
vectors in x, y, and z directions respectively.
x1=x+ Tx
y1=y+Ty
z1=z+ Tz
Translation :

Three-dimensional transformations are performed by transforming each vertex of the object.


If an object has five corners, then the translation will be accomplished by translating all five
points to new locations. Following figure 1 shows the translation of point figure 2 shows the
translation of the cube.
Matrix for translation
Translation :
Scaling :

Scaling is used to change the size of an object. The size can be increased or decreased. The
scaling three factors are required Sx Sy and Sz.
Sx=Scaling factor in x- direction
Matrix for Scaling
Sy=Scaling factor in y-direction
Sz=Scaling factor in z-direction
Scaling :

Scaling of the object relative to a fixed point.


Following are steps performed when scaling of objects with fixed point (a, b, c). It can be
represented as below:
• Translate fixed point to the origin
• Scale the object relative to the origin
• Translate object back to its original position.
Scaling :
Scaling
Scaling: :
Rotation :

It is moving of an object about an angle. Movement can be anticlockwise or clockwise. 3D


rotation is complex as compared to the 2D rotation. For 2D we describe the angle of
rotation, but for a 3D angle of rotation and axis of rotation are required. The axis can be
either x or y or z.
Rotation :
Rotation :
Rotation :
Rotation :
rotation of the object about the Z axis

rotation of the object about the Y axis


Rotation :

Rotation about Arbitrary Axis


When the object is rotated about an axis that is not parallel to any one of co-ordinate axis,
i.e., x, y, z. Then additional transformations are required. First of all, alignment is needed,
and then the object is being back to the original position. Following steps are required
1. Translate the object to the origin
2. Rotate object so that axis of object coincide with any of coordinate axis.
3. Perform rotation about co-ordinate axis with whom coinciding is done.
4. Apply inverse rotation to bring rotation back to the original position.
5. Apply inverse translation to bring rotation axis to the original position.
Rotation :
Rotation :
Figure show the original position of object and
position of object after rotation about the x-axis
Reflection :
It is also called a mirror image of an
object. For this reflection axis and
reflection of plane is selected. Three-
dimensional reflections are similar to two
dimensions. Reflection is 180° about the
given axis. For reflection, plane is
selected (xy,xz or yz). Following
matrices show reflection respect to all
these three planes.
Reflection :

Reflection relative to XY plane Reflection relative to YZ plane

Reflection relative to ZX plane


Shearing:

It is change in the shape of the object. It is also called as deformation. Change can be in
the x -direction or y -direction or both directions in case of 2D. If shear occurs in both
directions, the object will be distorted. But in 3D shear can occur in three directions.

Matrix for shear


Shearing:
Shearing:
Projections:

Representing an n-dimensional object into an n-1 dimension is known as projection. It is


process of converting a 3D object into 2D object, we represent a 3D object on a 2D plane
{(x,y,z)->(x,y)}. It is also defined as mapping or transforming of the object in projection
plane or view plane. When geometric objects are formed by the intersection of lines with a
plane, the plane is called the projection plane and the lines are called projections.
Projections:

Types of Projections:
1.Parallel projections
2.Perspective projections
Projections:

Centre of Projection:
It is an arbitrary point from where the lines are drawn on each point of an object.
• If cop is located at a finite point in 3D space , Perspective projection is the result
• If the cop is located at infinity, all the lines are parallel and the result is a parallel
projection.
Projections:

Parallel Projection:
• A parallel projection is formed by extending parallel lines from each vertex of object
until they intersect plane of screen.
• Parallel projection transforms object to the view plane along parallel lines. A projection is
said to be parallel, if center of projection is at an infinite distance from the projected
plane.
• A parallel projection preserves relative proportion of objects, accurate views of the
various sides of an object are obtained with a parallel projection.
• The projection lines are parallel to each other and extended from the object and intersect
the view plane.
Projections:

• It preserves relative propositions of objects, and it is used in drafting to produce scale


drawings of 3D objects.
• This is not a realistic representation, the point of intersection is the projection of the
vertex.
Projections:

Parallel projection is divided into two parts and these two parts sub divided into many.

Orthographic Projections:
• In orthographic projection the direction of projection is normal to the projection of the
plane. In orthographic lines are parallel to each other making an angle 90 with view
plane.
• Orthographic parallel projections are done by projecting points along parallel lines that
are perpendicular to the projection line.
• Orthographic projections are most often used to procedure the front, side, and top views
of an object are called evaluations.
Projections:
• Engineering and architectural drawings commonly employ these orthographic
projections. Transformation equations for an orthographic parallel projection as straight
forward.
• Some special orthographic parallel projections involve plan view, side elevations. We can
also perform orthographic projections that display more than one phase of an object, such
views are called monometric orthographic projections.

Oblique Projections:
• Oblique projections are obtained by projectors along parallel lines that are not
perpendicular to the projection plane.
Projections:
• An oblique projection shows the front and top surfaces that include the three dimensions
of height, width and depth.
• The front or principal surface of an object is parallel to the plane of projection. Effective
in pictorial representation.

Orthographic Projections Oblique Projections


Projections:

Isometric Projections: Orthographic projections that show more than one side of an
object are called axonometric orthographic projections. The most common axonometric
projection is an isometric projection. In this projection parallelism of lines are preserved but
angles are not preserved.

Dimetric projections: In these two projectors have equal angles with respect to two
principal axis.

Trimetric projections: The direction of projection makes unequal angle with their
principal axis.
Projections:

Cavalier Projections:
All lines perpendicular to the
projection plane are projected
with no change in length. If the
projected line making an angle
45 degrees with the projected
plane, as a result the line of the
object length will not change.
Projections:

Cabinet Projections:
All lines perpendicular to the projection
plane are projected to one half of their
length. These gives a realistic appearance
of object. It makes 63.4 degrees angle
with the projection plane. Here lines
perpendicular to the viewing surface are
projected at half their actual length.
Projections:

Perspective Projections:
• A perspective projection is the one produced by straight lines radiating from a common
point and passing through point on the sphere to the plane of projection.
• Perspective projection is a geometric technique used to produce a three dimensional
graphic image on a plane, corresponding to what person sees.
• Any set of parallel lines of object that are not parallel to the projection plane are projected
into converging lines. A different set of parallel lines will have a separate vanishing point.
• Coordinate positions are transferred to the view plane along lines that converge to a point
called projection reference point.
Projections:

Perspective Projections:
• The distance and angles are not preserved and parallel lines do not remain parallel.
Instead, they all converge at a single point called center of projection there are 3 types of
perspective projections.
• Two characteristic of perspective are vanishing point and perspective force shortening.
Due to fore shortening objects and lengths appear smaller from the center of projections.
The projections are not parallel and we specify a center of projection cop.
Projections:

Different types of perspective projections:

One point perspective projections: In this, principal axis has a finite vanishing
point. Perspective projection is simple to draw.
Projections:

Two point perspective projections: Exactly 2 principals have vanishing


points. Perspective projection gives better impression of depth.
Projections:

Three point perspective projections: All the three principal axes have finite
vanishing point. Perspective projection is most difficult to draw.

You might also like