0% found this document useful (0 votes)
232 views106 pages

Unit 2

The document discusses 2D transformations and viewing in computer graphics. It describes basic 2D transformations like translation, rotation, scaling, and their matrix representations. It also discusses transformation of points, lines, and intersecting lines. The viewing pipeline is introduced including window to viewport coordinate transformation, various clipping operations, and clipping of points, lines, circles, and polygons. Pixel, raster images, vector graphics, and rasterization are also defined. Examples of 2D translation and rotation transformations are provided along with practice problems.

Uploaded by

Alex Son
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)
232 views106 pages

Unit 2

The document discusses 2D transformations and viewing in computer graphics. It describes basic 2D transformations like translation, rotation, scaling, and their matrix representations. It also discusses transformation of points, lines, and intersecting lines. The viewing pipeline is introduced including window to viewport coordinate transformation, various clipping operations, and clipping of points, lines, circles, and polygons. Pixel, raster images, vector graphics, and rasterization are also defined. Examples of 2D translation and rotation transformations are provided along with practice problems.

Uploaded by

Alex Son
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/ 106

SCHOOL OF COMPUTING

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

1151CS125-COMPUTER GRAPHICS

UNIT-2

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


UNIT-2
2D TRANSFORMATION & VIEWING
Basic transformations: translation, rotation, scaling, Matrix representations &
homogeneous coordinates, transformations between coordinate systems,
reflection shear, Transformation of points, lines, parallel lines, intersecting
lines. Viewing pipeline, Window to viewport coordinate transformation,
clipping operations, point clipping, line clipping, clipping circles, polygons
& ellipse.
REFERENCES
1. Hearn & Baker, “Computer Graphics C version”, 2nd ed. Pearson
Education, 2012.
2. www.slideshare.net/.../computer-graphics-image-processing-lecture-n.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Pixel
•  Term that comes from the words PEL (picture element).
• A px (pixel) is the smallest portion of an image or display that a
computer is capable of printing or displaying.
• You can get a better understanding of what a pixel is
when zooming into an image as seen in the picture.

https://youtu.be/15aqFQQVBWU
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
Raster Images
• Computer graphics can be created as either raster or vector images.
Raster graphics are bitmaps.
• A bitmap is a grid of individual pixels that collectively compose an
image.
• Raster graphics render images as a collection of countless tiny squares.
• Each square, or pixel, is coded in a specific hue or shade.
• Individually, these pixels are worthless. Together, they’re worth a
thousand words.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Vector Graphics
• Vector graphics are based on mathematical formulas that define
geometric primitives such as polygons, lines, curves, circles and
rectangles.
• Because vector graphics are composed of true geometric primitives,
they are best used to represent more structured images, like line art
graphics with flat, uniform colors.
• Most created images (as opposed to natural images) meet these
specifications, including logos, letterhead, and fonts.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Rasterisation

• Rasterisation (or rasterization) is the task of taking an image


described in a vector graphics format (shapes) and converting it
into a raster image (a series of pixels, dots or lines, which, when
displayed together, create the image which was represented via
shapes).
• The rasterised image may then be displayed on a computer
display, video display or printer, or stored in a bitmap file format.
• Rasterisation may refer to the technique of drawing 3D models, or
the conversion of 2D rendering primitives such as polygons, line
segments into a rasterized format
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
Basic raster graphical algorithm for 2D primitives

• Idea is to approximate mathematical “ideal” primitives, described in


Cartesian space, by sets of pixels on a raster display (bitmap in
memory or frame buffer)
• Fundamental algorithms for scan converting primitives to pixels, and
clipping them
• Many algorithms were initially designed for plotters
• Can be implemented in hardware, software and Firmware

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D and 3D Transformations
Transformations
Transformations are a fundamental part of the computer graphics.
Transformations are the movement of the object in Cartesian plane .

Types of Transformation
There are two types of transformation in computer graphics.
1) 2D transformation
2) 3D transformation
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
2D and 3D Transformations
Types of 2D and 3D transformation
1) Translation
2) Rotation
3) Scaling
4) Shearing
5) Mirror reflection

Why we use Transformation ?


Transformation are used to position objects , to shape object , to change
viewing positions , and even how something is viewed.
In simple words transformation is used for
1) Modeling
2) Viewing
https://www.mathwarehouse.com/animated-gifs/transformations.php
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
2D Transformation
 When the transformation takes place on a 2D plane .it is called 2D
transformation.
 2D means two dimensional (x-axis and Y-axis

Object Transformation in 2D
 Alter the coordinates descriptions an object
Translation , rotation , scaling , shearing, reflection.
Coordinate system unchanged

Coordinate transformation in 2D
 Produce a different coordinate system

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Translation
2D Translation is a process of moving an object from one
position to another in a two dimensional plane.

Let-

• Initial coordinates of the object O = (Xold, Yold)

• New coordinates of the object O after translation = (X new, Ynew)

• Translation vector or Shift vector = (Tx, Ty)

Given a Translation vector (Tx, Ty)-

• Tx defines the distance the Xold coordinate has to be moved.

• Ty defines the distance the Yold coordinate has to be moved.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Translation

2D Translation

This translation is achieved by adding the translation coordinates to the old

coordinates of the object as

Xnew = Xold + Tx     (This denotes translation towards X axis)

Ynew = Yold + Ty     (This denotes translation towards Y axis)


COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
2D Translation
In Matrix form, the above translation equations may be represented as

•The homogeneous coordinates representation of (X, Y) is (X, Y, 1).


•Through this representation, all the transformations can be performed using
matrix / vector multiplications.
 The above translation matrix may be represented as a 3 x 3 matrix as

https://www.mathwar
ehouse.com/animate
d-gifs/transformations
.php#translations

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


PRACTICE PROBLEMS BASED ON 2D TRANSLATION
 

Given a circle C with radius 10 and center coordinates (1, 4). Apply the translation with

distance 5 towards X axis and 1 towards Y axis. Obtain the new coordinates of C without

changing its radius.

Solution-
 
Given-
Old center coordinates of C = (X old, Yold) = (1, 4)
Translation vector = (Tx, Ty) = (5, 1)
 
Let the new center coordinates of C = (X new, Ynew).
 
Applying the translation equations, we have-
Xnew = Xold + Tx = 1 + 5 = 6
Ynew = Yold + Ty = 4 + 1 = 5
 
Thus, New center coordinates of CGRAPHICS
COMPUTER = (6, 5).
-1151CS125 Dr.T.KAMALESHWAR AP/CSE
PRACTICE PROBLEMS BASED ON 2D TRANSLATION
 
In matrix form, the new center coordinates of C after translation may be
obtained as-

Thus, New center coordinates of C = (6, 5).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Rotation 
Rotation is a process of rotating an object with respect to
an angle in a two dimensional plane.

Consider a point object O has to be rotated from one angle to another in a 2D


plane.

 Let- https://www.math
warehouse.com/an
imated-gifs/transfo
 Initial coordinates of the object O = (Xold, Yold) rmations.php#rota
tions
 Initial angle of the object O with respect to origin = Φ
 Rotation angle = θ

 New coordinates of the object O after rotation = (Xnew, Ynew)

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Rotation 

This rotation is achieved by using the following rotation equations

• Xnew = Xold x cosθ – Yold x sinθ

• Ynew = Xold x sinθ + Yold x cosθ

In Matrix form, the above rotation equations may be represented as

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


PRACTICE PROBLEMS BASED ON 2D ROTATION

Given a line segment with starting point as (0, 0) and ending point as

(4, 4). Apply 30 degree rotation anticlockwise direction on the line segment and

find out the new coordinates of the line.

Solution-

 We rotate a straight line by its end points with the same angle. Then, we re-draw
a line between the new end points.

 Given-

Old ending coordinates of the line = (Xold, Yold) = (4, 4)

Rotation angle = θ = 30º

 Let new ending coordinates of the line after rotation = (Xnew, Ynew).
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
PRACTICE PROBLEMS BASED ON 2D ROTATION
Applying the rotation equations, we have
 Xnew = Xold x cosθ – Yold x sinθ
= 4 x cos30º – 4 x sin30º
= 4 x (√3 / 2) – 4 x (1 / 2)
= 2√3 – 2
= 2(√3 – 1)
= 2(1.73 – 1)
= 1.46
Ynew = Xold x sinθ + Yold x cosθ
= 4 x sin30º + 4 x cos30º
= 4 x (1 / 2) + 4 x (√3 / 2)
= 2 + 2√3
= 2(1 + √3) Thus, New ending coordinates of the line after
= 2(1 + 1.73) rotation = (1.46, 5.46).
= 5.46
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
PRACTICE PROBLEMS BASED ON 2D ROTATION
In matrix form, the new ending coordinates of the line after rotation may
be obtained as-

Thus, New ending coordinates of the line after rotation = (1.46, 5.46).
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
2D Scaling

Scaling is a process of modifying or altering the size of objects.

• Scaling may be used to increase or reduce the size of object.

• Scaling subjects the coordinate points of the original object to change.


• Scaling factor determines whether the object size is to be increased or
reduced.
• If scaling factor > 1, then the object size is increased.

• If scaling factor < 1, then the object size is reduce

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Scaling
Consider a point object O has to be scaled in a 2D plane.
 Let-

• Initial coordinates of the object O = (Xold, Yold)

• Scaling factor for X-axis = Sx

• Scaling factor for Y-axis = Sy

• New coordinates of the object O after scaling = (Xnew, Ynew)

 This scaling is achieved by using the following scaling equations

Xnew = Xold x Sx

Ynew = Yold x Sy

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Scaling
In Matrix form, the above scaling equations may be represented as

For homogeneous coordinates, the above scaling matrix may be represented as


a 3 x 3 matrix as

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


PRACTICE PROBLEMS BASED ON 2D SCALING

Given a square object with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0).
Apply the scaling parameter 2 towards X axis and 3 towards Y axis and
obtain the new coordinates of the object.

Solution-
 Given-
• Old corner coordinates of the square = A (0, 3), B(3, 3), C(3, 0), D(0, 0)
• Scaling factor along X axis = 2

• Scaling factor along Y axis = 3

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


PRACTICE PROBLEMS BASED ON 2D SCALING
For Coordinates A(0, 3)
 Let the new coordinates of corner A after scaling = (Xnew, Ynew).
 Applying the scaling equations, we have-

Xnew = Xold x Sx = 0  x 2 = 0


Ynew = Yold x Sy = 3 x 3 = 9

 Thus, New coordinates of corner A after scaling = (0, 9).

For Coordinates B(3, 3)


 Let the new coordinates of corner B after scaling = (Xnew, Ynew).
 Applying the scaling equations, we have-

Xnew = Xold x Sx = 3  x 2 = 6


Ynew = Yold x Sy = 3 x 3 = 9

 Thus, New coordinates of corner B after scaling = (6, 9).


COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
PRACTICE PROBLEMS BASED ON 2D SCALING

For Coordinates C(3, 0)


 Let the new coordinates of corner C after scaling = (Xnew, Ynew).
 Applying the scaling equations, we have-
Xnew = Xold x Sx = 3  x 2 = 6
Ynew = Yold x Sy = 0 x 3 = 0

 Thus, New coordinates of corner C after scaling = (6, 0).

 For Coordinates D(0, 0)


 Let the new coordinates of corner D after scaling = (Xnew, Ynew).
 Applying the scaling equations, we have-
Xnew = Xold x Sx = 0  x 2 = 0
Ynew = Yold x Sy = 0 x 3 = 0
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
PRACTICE PROBLEMS BASED ON 2D SCALING
Thus, New coordinates of the square after scaling = A (0, 9), B(6, 9), C(6, 0),
D(0, 0).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Reflection

• Reflection is a kind of rotation where the angle of rotation is 180 degree.


• The reflected object is always formed on the other side of mirror.

• The size of reflected object is same as the size of original object.


• Consider a point object O has to be reflected in a 2D plane.

Let-

• Initial coordinates of the object O = (Xold, Yold)

• New coordinates of the reflected object O after reflection

= (Xnew, Ynew)

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Reflection
Reflection On X-Axis:
This reflection is achieved by using the following reflection equations
Xnew = Xold
Ynew = -Yold
In Matrix form, the above reflection equations may be represented as-

For homogeneous coordinates, the above reflection matrix may be represented


as a 3 x 3 matrix as

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Reflection
Reflection On Y-Axis:
This reflection is achieved by using the following reflection equations-
• Xnew = -Xold
• Ynew = Yold 
In Matrix form, the above reflection equations may be represented as

For homogeneous coordinates, the above reflection matrix may be


represented as a 3 x 3 matrix as

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


PRACTICE PROBLEMS BASED ON 2D REFLECTION

Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the reflection
on the X axis and obtain the new coordinates of the object.

Solution-
Given-
Old corner coordinates of the triangle = A (3, 4), B(6, 4), C(5, 6)
Reflection has to be taken on the X axis
 
For Coordinates A(3, 4)
 Let the new coordinates of corner A after reflection = (Xnew, Ynew).
 
Applying the reflection equations, we have-
Xnew = Xold = 3
Ynew = -Yold = -4
 
Thus, New coordinates of corner A after reflection = (3, -4). Dr.T.KAMALESHWAR AP/CSE
COMPUTER GRAPHICS -1151CS125
PRACTICE PROBLEMS BASED ON 2D REFLECTION

For Coordinates B(6, 4)


 Let the new coordinates of corner B after reflection = (X new, Ynew).

 Applying the reflection equations, we have-


Xnew = Xold = 6
Ynew = -Yold = -4

 Thus, New coordinates of corner B after reflection = (6, -4).


 
For Coordinates C(5, 6)
 Let the new coordinates of corner C after reflection = (X new, Ynew).

 Applying the reflection equations, we have-


Xnew = Xold = 5
Ynew = -Yold = -6

 Thus, New coordinates of corner C after reflection = (5, -6).


 

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


PRACTICE PROBLEMS BASED ON 2D REFLECTION

Thus, New coordinates of the triangle after reflection =


A (3, -4), B(6, -4), C(5, -6).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing
2D Shearing is an ideal technique to change the shape of an
existing object in a two dimensional plane.
In a two dimensional plane, the object size can be changed along X
direction as well as Y direction. So, there are two versions of shearing

1. Shearing in X direction
2. Shearing in Y direction
 Consider a point object O has to be sheared in a 2D plane.
 Let-
•Initial coordinates of the object O = (Xold, Yold)

•Shearing parameter towards X direction = Shx

•Shearing parameter towards Y direction = Shy

•New coordinates ofCOMPUTER


the object O -1151CS125
GRAPHICS after shearing = (Xnew, Ynew) Dr.T.KAMALESHWAR AP/CSE
2D Shearing
Shearing in X Axis-
Shearing in X axis is achieved by using the following shearing equations
• Xnew = Xold + Shx x Yold
• Ynew = Yold 
In Matrix form, the above shearing equations may be represented as

For homogeneous coordinates, the above shearing matrix may be represented as


a 3 x 3 matrix as-

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing
Shearing in Y Axis-
• Shearing in Y axis is achieved by using the following shearing equations
• Xnew = Xold
• Ynew = Yold + Shy x Xold
• In Matrix form, the above shearing equations may be represented as-

For homogeneous coordinates, the above shearing matrix may be represented


as a 3 x 3 matrix as

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing
PRACTICE PROBLEMS BASED ON 2D SHEARING IN COMPUTER
GRAPHICS-
 
Problem-01:
 
Given a triangle with points (1, 1), (0, 0) and (1, 0). Apply shear parameter 2 on
X axis and 2 on Y axis and find out the new coordinates of the object.
 
Solution-
 
Given-
Old corner coordinates of the triangle = A (1, 1), B(0, 0), C(1, 0)
Shearing parameter towards X direction (Shx) = 2
Shearing parameter towards Y direction (Shy) = 2

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

Shearing in X Axis-

 For Coordinates A(1, 1)

 Let the new coordinates of corner A after shearing = (X new, Ynew).

 Applying the shearing equations, we have-

Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3

Ynew = Yold = 1

Thus, New coordinates of corner A after shearing = (3, 1).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates B(0, 0)


 

Let the new coordinates of corner B after shearing = (Xnew, Ynew).

 
Applying the shearing equations, we have-

Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0

Ynew = Yold = 0

 
Thus, New coordinates of corner B after shearing = (0, 0).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates C(1, 0)

 Let the new coordinates of corner C after shearing = (Xnew, Ynew).

 Applying the shearing equations, we have-

Xnew = Xold + Shx x Yold = 1 + 2 x 0 = 1

Ynew = Yold = 0

 Thus, New coordinates of corner C after shearing = (1, 0).

Thus, New coordinates of the triangle after shearing in X axis = A (3, 1),

B(0, 0), C(1, 0).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

Shearing in Y Axis-

 For Coordinates A(1, 1)

 Let the new coordinates of corner A after shearing = (X new, Ynew).

 Applying the shearing equations, we have-

Xnew = Xold = 1

Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3

Thus, New coordinates of corner A after shearing = (1, 3).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates B(0, 0)


 

Let the new coordinates of corner B after shearing = (X new, Ynew).

Applying the shearing equations, we have-

Xnew = Xold = 0

Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0

Thus, New coordinates of corner B after shearing = (0, 0).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates C(1, 0)

Let the new coordinates of corner C after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-

Xnew = Xold = 1

Ynew = Yold + Shy x Xold = 0 + 2 x 1 = 2

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing
• Thus, New coordinates of corner C after shearing = (1, 2).
• Thus, New coordinates of the triangle after shearing in Y axis = A (1, 3),
B(0, 0), C(1, 2).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing
PRACTICE PROBLEMS BASED ON 2D SHEARING IN COMPUTER
GRAPHICS-
 
Problem-01:
 
Given a triangle with points (1, 1), (0, 0) and (1, 0). Apply shear parameter 2 on
X axis and 2 on Y axis and find out the new coordinates of the object.
 
Solution-
 
Given-
Old corner coordinates of the triangle = A (1, 1), B(0, 0), C(1, 0)
Shearing parameter towards X direction (Shx) = 2
Shearing parameter towards Y direction (Shy) = 2

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

Shearing in X Axis-

 For Coordinates A(1, 1)

 Let the new coordinates of corner A after shearing = (X new, Ynew).

 Applying the shearing equations, we have-

Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3

Ynew = Yold = 1

Thus, New coordinates of corner A after shearing = (3, 1).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates B(0, 0)


 

Let the new coordinates of corner B after shearing = (Xnew, Ynew).

 
Applying the shearing equations, we have-

Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0

Ynew = Yold = 0

 
Thus, New coordinates of corner B after shearing = (0, 0).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates C(1, 0)

 Let the new coordinates of corner C after shearing = (Xnew, Ynew).

 Applying the shearing equations, we have-

Xnew = Xold + Shx x Yold = 1 + 2 x 0 = 1

Ynew = Yold = 0

 Thus, New coordinates of corner C after shearing = (1, 0).

Thus, New coordinates of the triangle after shearing in X axis = A (3, 1),

B(0, 0), C(1, 0).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

Shearing in Y Axis-

 For Coordinates A(1, 1)

 Let the new coordinates of corner A after shearing = (X new, Ynew).

 Applying the shearing equations, we have-

Xnew = Xold = 1

Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3

Thus, New coordinates of corner A after shearing = (1, 3).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates B(0, 0)


 

Let the new coordinates of corner B after shearing = (X new, Ynew).

Applying the shearing equations, we have-

Xnew = Xold = 0

Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0

Thus, New coordinates of corner B after shearing = (0, 0).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates C(1, 0)

Let the new coordinates of corner C after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-

Xnew = Xold = 1

Ynew = Yold + Shy x Xold = 0 + 2 x 1 = 2

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing
• Thus, New coordinates of corner C after shearing = (1, 2).
• Thus, New coordinates of the triangle after shearing in Y axis = A (1, 3),
B(0, 0), C(1, 2).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing
PRACTICE PROBLEMS BASED ON 2D SHEARING IN COMPUTER
GRAPHICS-
 
Problem-01:
 
Given a triangle with points (1, 1), (0, 0) and (1, 0). Apply shear parameter 2 on
X axis and 2 on Y axis and find out the new coordinates of the object.
 
Solution-
 
Given-
Old corner coordinates of the triangle = A (1, 1), B(0, 0), C(1, 0)
Shearing parameter towards X direction (Shx) = 2
Shearing parameter towards Y direction (Shy) = 2

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

Shearing in X Axis-

 For Coordinates A(1, 1)

 Let the new coordinates of corner A after shearing = (X new, Ynew).

 Applying the shearing equations, we have-

Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3

Ynew = Yold = 1

Thus, New coordinates of corner A after shearing = (3, 1).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates B(0, 0)


 

Let the new coordinates of corner B after shearing = (Xnew, Ynew).

 
Applying the shearing equations, we have-

Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0

Ynew = Yold = 0

 
Thus, New coordinates of corner B after shearing = (0, 0).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates C(1, 0)

 Let the new coordinates of corner C after shearing = (Xnew, Ynew).

 Applying the shearing equations, we have-

Xnew = Xold + Shx x Yold = 1 + 2 x 0 = 1

Ynew = Yold = 0

 Thus, New coordinates of corner C after shearing = (1, 0).

Thus, New coordinates of the triangle after shearing in X axis = A (3, 1),

B(0, 0), C(1, 0).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

Shearing in Y Axis-

 For Coordinates A(1, 1)

 Let the new coordinates of corner A after shearing = (X new, Ynew).

 Applying the shearing equations, we have-

Xnew = Xold = 1

Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3

Thus, New coordinates of corner A after shearing = (1, 3).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates B(0, 0)


 

Let the new coordinates of corner B after shearing = (X new, Ynew).

Applying the shearing equations, we have-

Xnew = Xold = 0

Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0

Thus, New coordinates of corner B after shearing = (0, 0).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing

For Coordinates C(1, 0)

Let the new coordinates of corner C after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-

Xnew = Xold = 1

Ynew = Yold + Shy x Xold = 0 + 2 x 1 = 2

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


2D Shearing
• Thus, New coordinates of corner C after shearing = (1, 2).
• Thus, New coordinates of the triangle after shearing in Y axis = A (1, 3),
B(0, 0), C(1, 2).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Windows Port
• The window port can be confused with the computer window but it isn’t
the same. The window port is the area chosen from the real world for
display. This window port decides what portion of the real world should be
captured and be displayed on the screen. The widow port can thus be
defined as,
"A world-coordinate area selected for display is called a window.
A window defines a rectangular area in the world coordinates."

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Viewport
The Viewport is the area on a display device to which a window is
mapped. Thus, the viewport is nothing else but our device’s screen. The
viewport can thus be defined as follows:
"A viewport is a polygon viewing region in computer graphics. The viewport
is an area expressed in rendering-device-specific coordinates, e.g. pixels
for screen coordinates, in which the objects of interest are going to be
rendered."

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Difference between Window Port and Viewport

Window Port Viewport


Window port is the coordinate area specially Viewport is the display area of viewport in which
selected for the display. the window is perfectly mapped.
Region Created according to World Coordinates. Region Created according to Device Coordinates.
It is a region selected form the real world. It is a It is the region in computer graphics which is a
graphically control thing and composed of visual polygon viewing region.
areas along with some of its program controlled
with help of window decoration.
A window port can be defined with the help of a A viewport is defined by the GPORT command.
GWINDOW statement.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Clipping
Clipping means identifying portions of a scene that are outside a specified
region. For a 2D graphics the region defining what is to be clipped is called
the clip window.
Types of clipping:
1. All-or-none clipping: If any part of object outside clip window then the
whole object is rejected.
2. Point clipping: Only keep the points that are inside clip window.

3. Line clipping: Only keep segment of line inside clip window.

4. Polygon clipping: Only keep segment of polygon inside clip window.


5. Text clipping.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Point Clipping
• Suppose that the clip window is a rectangle. The point P = (x, y) is saved
for display if the following are satisfied:
xwmin ≤ x ≤ xwmax
ywmin ≤ y ≤ ywmax
• Otherwise, the point will be clipped (not saved for display).
Example of Point Clipping
P1= (10,20), P2= (30,50), P3= (60,90), and P4= (130,150). Suppose that the coordinates of the two
opposite corners of the clip window are (xwmin, ywmin) = (30, 30) and (xwmax, ywmax) =
(130, 110). Which of the above points will be clipped?

• P2 and P3 will saved because:


• For P2: 30 ≤ 30 ≤ 130 and 30 ≤ 50 ≤ 110.
• For P3: 30 ≤ 60 ≤ 130 and 30 ≤ 90 ≤ 110.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Line Clipping
The concept of line clipping is same as point clipping. In line clipping, we
will cut the portion of line which is outside of window and keep only the
portion that is inside the window.
Cohen-Sutherland Line Clippings

This algorithm uses the clipping window as shown in the below figure. The
minimum coordinate for the clipping region is (XWmin,YWmin) and the
maximum coordinate for the clipping region is (XWmax,YWmax)

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Line Clipping
 We will use 4-bits to divide the entire region.
 These 4 bits represent the Top, Bottom, Right, and Left of the region as
shown in the below figure.
 Here, the TOP and LEFT bit is set to 1 because it is the TOP-
LEFT corner.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Line Clipping

3 possibilities for the line


• Line can be completely inside the window 

This line should be accepted This line should NOT be rejected.


• Line can be completely outside of the window

 This line will be completely removed from the region


• Line can be partially inside the window 

We will find intersection point and draw only that portion of line that is
inside region

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Mid Point Subdivision Line Clipping Algorithm
• It is used for clipping line. The line is divided in two parts. Mid points of
line is obtained by dividing it in two short segments. Again division is
done, by finding midpoint. This process is continued until line of visible
and invisible category is obtained. Let (xi,yi) are midpoint

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Mid Point Subdivision Line Clipping Algorithm

• x5lie on point of intersection of boundary of window.

Advantage of midpoint subdivision Line Clipping:


• It is suitable for machines in which multiplication and division operation is
not possible. Because it can be performed by introducing clipping divides
in hardware.
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
Mid Point Subdivision Line Clipping Algorithm

Example: Window size is (-3, 1) to (2, 6). A line AB is given having co-
ordinates of A (-4, 2) and B (-1, 7). Does this line visible. Find the visible
portion of the line using midpoint subdivision?
Solution:
• Step1: Fix point A (-4, 2)

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Mid Point Subdivision Line Clipping Algorithm

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Mid Point Subdivision Line Clipping Algorithm
Step2: Find b"=mid of b'and b

So (-1, 5) is better than (2, 4) Find b"&bb''(-1, 5) b (-1, 7)

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Mid Point Subdivision Line Clipping Algorithm
• So B""to B length of line will be clipped from upper side

• Now considered left-hand side portion.


• A and B""are now endpoints
• Find mid of A and B""
• A (-4, 2) B ""(-1, 6)

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Mid Point Subdivision Line Clipping Algorithm

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Mid Point Subdivision Line Clipping Algorithm

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Liang-Barsky Line Clipping Algorithm
• The Liang-Barsky algorithm is a line clipping algorithm.
• This algorithm is more efficient than Cohen–Sutherland line clipping
algorithm and can be extended to 3-Dimensional clipping.
• This algorithm is considered to be the faster parametric line-clipping
algorithm.
• The following concepts are used in this clipping:
– The parametric equation of the line.

– The inequalities describing the range of the clipping window which is


used to determine the intersections between the line and the clip
window.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Liang-Barsky Line Clipping Algorithm
The parametric equation of a line can be given by,

X = x1 + t(x2-x1)

Y = y1 + t(y2-y1)

•Where, t is between 0 and 1.

•Then, writing the point-clipping conditions in the parametric form:

xwmin <= x1 + t(x2-x1) <= xwmax

ywmin <= y1 + t(y2-y1) <= ywmax

The above 4 inequalities can be expressed as,

•Where k = 1, 2, 3, 4 (correspond to the left, right, bottom, and top boundaries,

respectively).

•The p and q are defined as,


COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
Liang-Barsky Line Clipping Algorithm
p1 = -(x2-x1), q1 = x1 - xwmin (Left Boundary)

p2 = (x2-x1), q2 = xwmax - x1 (Right Boundary)

p3 = -(y2-y1), q3 = y1 - ywmin (Bottom Boundary)

p4 = (y2-y1), q4 = ywmax - y1 (Top Boundary)

When the line is parallel to a view window boundary, the p value for that
boundary is zero.

• When pk < 0, as t increase line goes from the outside to inside (entering).

• When pk > 0, line goes from inside to outside (exiting).

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Liang-Barsky Line Clipping Algorithm
• When pk = 0 and qk < 0 then line is trivially invisible because it is outside

view window.

• When pk = 0 and qk > 0 then the line is inside the corresponding window

boundary.
Using the following conditions, the position of line can be determined:
Condition Position of line

pk = 0 parallel to the clipping boundaries

pk = 0 and qk < 0 completely outside the boundary

pk = 0 and qk >= 0 inside the parallel clipping boundary

pk < 0 line proceeds from outside to inside

pk > 0 line proceeds from inside Dr.T.KAMALESHWAR


COMPUTER GRAPHICS -1151CS125 to outside AP/CSE
Liang-Barsky Line Clipping Algorithm

• Parameters t1 and t2 can be calculated that define the part of line that lies
within the clip rectangle.
When,

• pk < 0, maximum(0, qk/pk) is taken.

• pk > 0, minimum(1, qk/pk) is taken.

• If t1 > t2, the line is completely outside the clip window and it can be
rejected. Otherwise, the endpoints of the clipped line are calculated from
the two values of parameter t.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Liang-Barsky Line Clipping Algorithm

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Liang-Barsky Line Clipping Algorithm

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Liang-Barsky Line Clipping Algorithm

• We have umin = 1/4 and umax = 3/4

• Pend - P0 = (15+5,9-3) = (20,6)


• ƒ If umin < umax , there is a line segment

-compute endpoints by substituting u values ƒ


• Draw a line from (-5+(20)·(1/4), 3+(6)·(1/4))
to

(-5+(20)·(3/4), 3+(6)·(3/4))

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Polygon Clipping

In a polygon, all lines are connected. Lines can be a combination of edges


and vertices, which together form a polygon. A polygon refers to a two-
dimensional architecture made up of a number of straight lines.

Some Examples of the polygon:

• Triangles

• Pentagons

• Hexagons

• Quadrilaterals

• The polygon’s name defines how many sides the architecture contains.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Polygon Clipping
• Triangle: It has three sides.

• Pentagon: A pentagon has five sides.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Polygon Clipping
• Hexagon: It contains six sides.

• Quadrilaterals: It contains four sides.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Polygon Clipping
Types of Polygon

• There are two basic types of polygon-

• Concave Polygon

• Convex Polygon

• Concave Polygon: The concave polygon does not have any part of its
diagonals in its exterior. In a concave polygon, at least one angle should be

greater than 180° (angle >180°). 

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Polygon Clipping
Convex Polygon: The convex polygon has at least one part of diagonal in its

exterior. In a convex polygon, all the angles should be less than 180°

(angle<180°). 

Polygon Clipping

Polygon clipping is a process in which we only consider the part which is

inside the view pane or window. We will remove or clip the part that is

outside the window. We will use the following algorithms for polygon

clipping-
• Sutherland-Hodgeman polygon clipping algorithm
• Weiler-Atherton polygon clipping algorithm
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
Sutherland Hodgeman Polygon Clipping

• A polygon can also be clipped by specifying the clipping window.


• Sutherland Hodgeman polygon clipping algorithm is used for polygon
clipping.
• In this algorithm, all the vertices of the polygon are clipped against each
edge of the clipping window.
• First the polygon is clipped against the left edge of the polygon window to
get new vertices of the polygon.
• These new vertices are used to clip the polygon against right edge, top
edge, bottom edge, of the clipping window as shown in the following
figure.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Polygon Clipping

• While processing an edge of a polygon with clipping window, an


intersection point is found if edge is not completely inside clipping
window and the a partial edge from the intersection point to the outside
edge is clipped.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Polygon Clipping
• The following figures show left, right, top and bottom edge clippings

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Weiler-Atherton polygon clipping algorithm
• This algorithm helps us to clip a filled area.

• The filled area may be a convex polygon or concave polygon.


• This algorithm was introduced to identify the visible surfaces.

• This algorithm helps to create individual polygons in some cases.


• In the Weiler-Atherton algorithm, we consider the view pane boundaries
instead of edges and vertices of the polygon.

Explanation:
1. Finding all the intersection points and grouping them
Here, let there be a polygon ABCD and another polygon VWXYZ. Let
ABCD be the clipping polygon and let VWXYZ be the clipped polygon.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Weiler-Atherton polygon clipping algorithm

So, we can find the intersection points using any method. For example, we
can find the intersecting points separately and then find for each intersecting
point find if it is entering or leaving, or, we can use Cyrus Beck and find all
the intersecting points and also get if a point is entering or exiting. Refer 
Cyrus Beck for more information on this algorithm.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Weiler-Atherton polygon clipping algorithm

2. Making and filling of two lists


Now, we make two lists. One for the clipping polygon and one for the clipped
polygon.
Now this is how we fill it:

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Weiler-Atherton polygon clipping algorithm

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Weiler-Atherton polygon clipping algorithm

3. Running of the algorithm


• We start at the clipped polygon’s list, i.e. VWXYZ.

• Now, we find the first intersecting point that is entering.

• Hence we choose i1.

• From here we begin the making of the list of vertices (or vector) to make a
clipped sub-polygon.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Weiler-Atherton polygon clipping algorithm

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Weiler-Atherton polygon clipping algorithm
According to the given example, i1 Y i2 is a clipped sub-polygon.
Similarly, we get:

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Weiler-Atherton polygon clipping algorithm
• i0 V i3 as another sub-polygon also.

• Hence, we were able to get two sub-polygons as a result of this polygon


clipping, which involved a concave polygon, which resulted in:

• Similarly, this clipping works for convex polygons

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Weiler-Atherton polygon clipping algorithm

Limitations:
• This polygon clipping algorithm does not work for self – intersecting
polygons, although some methods have been proposed to be able to solve
this issue also, and have successfully worked.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Text Clipping
• Various techniques are used to provide text clipping in a computer
graphics. It depends on the methods used to generate characters and the
requirements of a particular application. There are three methods for text
clipping which are listed below
All or none string clipping
All or none character clipping
Text clipping
All or none string clipping

In all or none string clipping method, either we keep the entire string or we reject
entire string based on the clipping window.
COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE
Text Clipping
All or none character clipping
This clipping method is based on characters rather than entire string. In this
method if the string is entirely inside the clipping window, then we keep it.
If it is partially outside the window, then −
• You reject only the portion of the string being outside

• If the character is on the boundary of the clipping window, then we discard


that entire character and keep the rest string.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Text Clipping
Text clipping
This clipping method is based on characters rather than the entire string. In
this method if the string is entirely inside the clipping window, then we
keep it. If it is partially outside the window, then
• You reject only the portion of string being outside.

• If the character is on the boundary of the clipping window, then we discard

only that portion of character that is outside of the clipping window.


 

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Learning materials
TEXT BOOKS
1. Hearn & Baker, “Computer Graphics C version”, 2nd ed. Pearson Education, 2012.
2. Rafael C. Gonzalez and Richard E. Woods, “Digital Image Processing”, Third
Edition,Pearson Education, 2008.

REFERENCES
1. DaveShreiner, Graham Sellers, John M. Kessenich, Bill M. Licea-Kane ,”OpenGL
Programming Guide: The Official Guide to Learning OpenGL, Version 4.3”, 8th
Edition, ARB working group.
2. Hearn and Baker, “Computer Graphics using open GL”, 3rd edition, Pearson
Education,2009.
3. Rogers, “Procedural Element for Computer Graphics”, 2nd ed, Tata McGraw Hill,
2001.
4. Peter Shirley, Michael Ashikhmin, Michael Gleicher, Stephen R Marschner, Erik
Reinhard, KelvinSung, and AK Peters, Fundamental of Computer Graphics, CRC
Press, 2010.
5. William M. Newman and Robert F.Sproull, “Principles of Interactive Computer
Graphics”, Mc GrawHill 1978.

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE


Web References
1. ww.cs.manchester.ac.uk/ugt/COMP27112/
2. www.slideshare.net/.../computer-graphics-image-processing-lecture-n.
3. http://www.cs.kent.edu/~farrell/cg02/reference/
4.
https://www.university.youth4work.com/study-material/computer-graphi
cs-lecture
5. http://nptel.ac.in/

COMPUTER GRAPHICS -1151CS125 Dr.T.KAMALESHWAR AP/CSE

You might also like