Unit 03
Unit 03
the monitor should not render the portion of the scene which is
When we display the scene on screen, we
outside the clipping window. It is essential to determine which portion of the line is inside the clipping region.
Various cases of line membership are discussed here. Consider the clipping rectangle PQRS in Fig. 6.1. Scene
contains four lines. If both endpoints of the line are withina rectangle, the line is completely visible. Otherwise,
Fig. 6.1
Line HI intersects left and top border of clipping regions. Intersections with respective boundaries are H and I.
Fig. 6.2 shows the output of the scene after the clipping procedure
Computer Graphics (SPPU) Quick Read
- A n n - k * * * * * * - k * -
Fig. 6.2
a.2 Explain Cohen-Sutherland line clipping algorithm with example. SPPU-May 15, May 17, Dec. 18, May 19, 4 Marks
Ans.: Cohen - Sutherland Line Clipping Algorithm
Introduction
Dr. Ivan E. Sutherland co-developed the Cohen Sutherland clipping algorithm. The algorithm divides a two-
dimensional space into 9 regions and then determines whether the lines or portions of lines are visible in the central
Bottom Right
Top Left
1000 1010
Fig. 6.3
The algorithm uses 4-bits binary outcode to divide the entire region. These 4 bits represent the Top, Bottom,
Right, and Left of the region as shown in the following Fig. 6.3.Here, the TOP and LEFT bit is set to 1 because it is the
TOP-LEFT corner.
(XWmin YWmax) Clipping (XWmax YWmax)
Window
This algorithm uses the clipping window as shown in the above Fig. 6.4.
The minimum coordinate for the clipping region(window boundary) is( Wmin, YWmin) and the maximum
coordinate for the clipping region is (XWmax, YWmax)
Ces easy-solutions
Computer Graphics(SPPU) Quick Read
. Anything inside the window will be disalyed, whereas line or parts ofline lyving outside given window boundary
is clipped and hence not visible.
Four Bit code is calculated by comparing end points of the given line (xy) by four co-ordinates (XWmin, YWmin)
and (XWmax, YWmax) which are the coordinates of the area of interest (0000)
1) Set First Bit if 1 end point of the line lies to left of window (x <XWmin).
2) Set Second Bit if 1 end point of the line lies to right of window (x> XWmax).
lies bottom of window (y < Ywmin.
3) Set Third Bit if 1 end point of the line to
4) Set Fourth Bit if 1 end point of the lines lies on top of window (y >
YWmax).
Fig.66.5
Case I
A and B are 0000 as it lies within the window.
Considering the fig. 6.4, line AB. the outcode of point
have outcodes 0000 then the line is completely visible and
According to the algorithm, if the endoints of the line
it should not be clipped
Case I
perform logical AND operation on both
Consider line CD. The.outcodes of both the endpoints are nonzero,
so we
D is 0010.
outcodes. Outcode of point C is 1010 and outcode of point
G D
0001 0000 0010
Ces easy-s0lutionsS
Computer Graphics (SPPU) Quick Read
Case
TBR L
outcode of E 0 0 01
E0001 outcode of F 0 0 0
Fig. 6.7
If we observe both the outcodes then we find difference in left bit. That means point E is lying outside the left
boundary of thewindow.
of intersection be
So we need to find the point of intersection of line. EF with left window boundary. Let the point
P1. Now we consider EP1. P, has outcode 0000.
0001
P1 0001
Now as point E is outside we discard EP1. Now consider the line P, F. outcode of Pi is 0000 compare Fand P.
T B R L
Outcode of Pi = 0 0 1
F 1
Comparing last bits of P1 and F. Point F is outside, so find intersection with top window boundary.
ig. 6.8
P(0000) and P2(0000) as both outcodes are zero, line Pi, P2 is visible.
Now to find the point of intersection with window boundary.
P(XYY)
PNY)
XWmAxYWmax
(XWminYmin
Fig. 6.9
The intersection is with the lert window
bounaary so the X-coordinate will be Xwmin. We need to find
y-value,
Ces easy-solutionsS
Computer Graphics (SPPU) Quick Read
For line PQ slope (m) = 2
Now as slope is known we can find the slope between Pi and P
y-y1 m (xWmin-X1)
y Y1+m (xWmin X1)
Similarly the point of intersection with right boundary of window can be found. Wherex will be xwmax.
y y1+m (xWmax-X1)
N o w for top window boundary the point of intersection y = ywmax We need to find x-coordinate.
X-X1 as y yW max
yW max1
x 1 m
And bottom edge y value is yWmin and
Wmin1
X X+ m
Algorithm
Step 1: Read (Xmin Ymin) and (Xmax Ymax)- Lower-left and top-right corner of clipping window
Step 2: Read A(x1, y1) and B(xz ya) end points ofline
Step 3: Compute outcode of both end points ofline
ify Ymax then OutcodeA(1) = 1 else 0 ify2> Ymax then Outcode_B(1) = 1 else 0
ify< Ymin then Outcode A(2) = 1 else 0 if y2< Ymin then Outcode B(2) = 1 else 0
Step 4 If both endpoints have an outcode 0000 then given line is completely inside and we display this line
Step 5: If step 4f ails, perform the logical AND operation on both outcodes.
Step5.1: If the result of logical AND operation is not 0000, then given line is completely outside.
Step 5.2 Else line is partially inside
Step 5.2.a : Choose an endpoint of the line that is outside the given window.
Step 5.2.b: Find the intersection point of the window boundary (based on outcode).
Step 5.2.c: Replace endpoint with the intersection point and update the outcode.
Step 5.2.d: Repeat step 2 until we find a clipped line either trivially accepted or rejected.
Step 6: Repeat step 3 for all lines
es 0asy-s0lutlons
Computer Graphics (SPPU) Quick Read
Advantages
I t is easy to understand.
..
Simple to implement.
Best suitable for the lines fully inside or outside.
I t can easily be extended for 3D line clipping
Disadvantages
.Repeated clipping is expensive.
Only applicable to rectangular clipping window. It cannot handle any other snape
I t can be improved using more regions (e.g. Nichol Lee Nichol approach).
it with Cohen-Sutherland Cipping.
Compare
a.3 EXpiain
Sutherland- Hodgeman algorithm for polygon clipping.
SPPU-Dec. 17, Dec. 18,6 Marks
Ans.
boundary clipper, then similarly to the top boundary clipper and bottom
boundary clipper, as shown in Fig. 6.8. At each step a new set of polygon
Original Polygon
vertices is generated and passed to the next window boundary clipper.
Fig.6.10
Consider the example given to clip polygon ABC
Left clipped
Bottom clipped
edae of polygon ABC lies outside the window
Doundary so the vertices of
polygon remains as it was in previous
step.
P
Fig. 6.12
2. Clip Right
No edge of the polygon intersects the right side of the window so the output vertex List is not updated remains
same as previous step.
3. Clip bottom
As the edge BC vertex B is inside the window and C lies outside the window boundary. So we store point of
intersection of BC ie. Pg in the output vertex list. Now consider edge AC. point P, is point of intersection of edge AC.
So P is also stored in the output vertex list.
4. Clip Top
As no edge intersects the top of the window boundary the output vertex list remain same.
Final output vertex is P1 B Pa P4 P2
When we traverse along the polygon boundary, one of the following four cases occurs:
Inside Outside Inside Outside Inside Outside Inside utside
P: second
i: first
Output output
Polygon
being
clipped
p: output
Clip
boundary 1: Output
L
Case 1 Case 2 Case 3 Case 4
(no output)
Fig. 6.13:Output for various clippers
This problem can be handled in many ways. One way is to
convert the concave polygon to multiple convex polygons as shown in
individually.
Fig. 6.14: Tessellation process
Another way of solving this problem is to tag the different new vertices as follow.
on the
Call a the new vertex generated on the transition from IN to OUT, Call B the new vertex generated
transition from OUT to IN. Starting from OUT, connect a and ß as soon a as is generated. This process
e s easy-solutions
Computer Graphics (SPPU) Quick Read
IN OUT
Q.4 Clip the subject polygon (V1-V2-v3-V4-V5-V1) against the given clipping polygon. (4 Marks)
Cipping polygon
Subject polygon
Fig. 6.16
Ceseasy-solutions
Computer Graphies (SPPU) Quick Read
Ans. : Intersection of the different clippers with subject polygon are shown in Fig. 6.16{a):
Output of top clipper: (V,. Vi. Vs, Vi, vs, ve, V?}
Output of bottom clipper: {Va", VE, Vs, vs', vi'. Vs, Vs)
Fig. 6.16(a)
The final clipped polygon would be {VE", V, Va, Vs'. va', Vs, V.}.
a.5 Explain the term with example Generalized Clipping. SPPU-Dec. 17, 4 Marks
Ans.: Weiler Atherton Polygon Clipping9
This algorithm is also referred to as generalized polygon clipping algorithm. In Sutherland Hodgeman algorithm,
we move along the edges of the polygon.
In weiler atherton algorithm we sometimes follow the polygon boundary and sometimes the window boundary.
The path to be followed the polygon direction. We move around the polygon boundary either in
depends on
clockwise or anticlockwise direction. Suppose we follow the polygon boundary in clockwise direction then we
Fig. 6.17
clockwise direction
Suppose, we move along the polygon boundary in
The output vertex list will be all the vertices of the polygon.
outside inside store the point of intersection P1 and
edge of the polygon PQ we move from
to so we
Consides the
inside store the second vertex ie R.
Q. The next edge is QR both are so we
Now consider edge RS, here we move from inside to outside, so only the point of intersection Pz is stored till here
the working of algorithm is similar to Cohen Sutherland algorithm.
So the next point to
Now as we move from inside to outside we follow window boundary in clockwise direction.
T.
consider is P we store P2 P1. For edge S T, we store point of intersection Pg and
intersection P4 and move along the window
For edge TU we store U. Now for edge UV we store point of
boundary as we move from inside to outside and store P4 Pa
Ces0asy-solutiens
Computer Graphics (SPPU 0 Quick Read
Algorithm of Weiler-Atherton Polygon Clipping
Step 1: First.create a list of intersection In the starting or ending state. (11, I 2 . .
polnts that are 11)
Step 2 Now, create two more lists; one for subject polygon and other for clip polygon. F l bon iss win
Order of Clip Polygon list- Write down the points of the window.
clipping
Step 3 nsert the vertices in both lists in such a way that the intersection point exists between the correct vertices.
tep Now, start from the first vertex of the polygon. Select the first intersection point as an entering point and
ollow the same process until we reach the
exiting point
Step5 W e can move from clip polygon list to subject polygon list and search for the finishing intersection point
Repeat the process until we find the entering point.
Step 6: Now, the polygon is being clipped. Repeat the same process until each point has been visited once.
Step 7: Stop
Advantages
T h i s algorithm can also handle concave polygons easily.
It does not require splitting the concave polygon to convert it into a convex polygon.
Unlike the Sutherland-Hodgeman algorithm, it does not produce spurious edge, so no post-processing is
required.
Disadvantages
Not easy to
paralenze
es casy-solutions
Computer Graphics (SPPU) Quick Read
y y+y
= z+
Equivalent homogeneous matrix representation is:
P TP
1 0
new 0
T
0 1 0
new Ty Yold
new o 0 1
T old
Lo o o 1.
3D Translation matrix
( 10 0 Tx
1 0 00
o 1 0
0 1 0 0
or
Ty
0 0 1 o 0 0 1
T
T, T, T 1 o 00 1
10 0 0
0 10 0
xYZ1)= 0 0 1 0 X YZ 1]
Ly1
Write matrices in the homogenous coordinate system for the following transformation: 3D Scaling
Q.2
SPPU-May 16,Dec.18,2Marks
es easy-solutions
Computer Graphics (SPPU) 12 Quick Read
Ans.: Scaling
Scaling
Let, s S Sy, S be a vector of the scaling parameters in all three directions, scaling with respect to the origin of
point P is computed as,
P S .PP
X Sx
y Sy
S,z
Matrix representation of scaling transformation
S 0 0
0 S, 0
0
.
00 s 0
L0 0 0 1-
If all three parameters are the same, it is called uniform
scaling. which preserves the original shape of the object
to be scaled. Otherwise, it is called non-uniform scaling
Fig. 7.2:
Shows Scaling9
Rotation
. T o define the direction of rotation in 3D, we use the right-hand rule:
Point the extended thumb ot your right
o
hand in the direction from
(dx, dy, dz) is the point that specifies the axis of rotation. (0,0,0) to (dx, dy, dz), where
Then the direction of rotation for positive angles is given by the direction in which
o Obtain rotations around other axes tnrougn cycuc permutation of coordinate
your fingers curl.
parameters:
XyZX
Here, we will discuss all possible cases of rotation in space.
es0asy-solutions
Computer Graphics (SPPU) 13 Quick Read
a.3 Write transtormation matrices for 3D rotation about axis SPPU-May 16,Dec, 18, May 19.6 Marks
Ans.: Rotation About Axis
3D rotation is simply an extension of 2D rotation with added dimension. Fig. 7.4 depicts the rotation about X, Y
and1Z-axis.
X
() (b) (0)
(a)Rotation about X-axis (b) Rotation about the Y-axis (c) Rotation about Z-axis
Fig. 7.4:3D Rotation about principal axes
While studying 2D transformation we have already studied rotation for object in clockwise and anticlockwise
direction.
To rotate an object with respect to z-axis is very much similar to rotation of an object in 2d in anticlockwise direction.
When we perform rotation about the z-axis, z coordinates remain unchanged. So the equation for rotation about
Z-axis is,
x X Cos - y sin 0
y = x sin 0+ y cos 0
PR P
cose sin8 0 0
-sin6 cos6 0 0
00 1 o
00 o 1
The above figure shows transformation matrix for rotation about z axis in anticlockwise direction
cos sine 0 0
- sine cos6 0 0
Rz
0 1 0
0 0 0 1-
cose sine 0 0
sine cos 0 0
0 10
0 0 0 1J
Cescasy-solutions
Computer Graphics (SPPU) 14 Quick Read
We replace x-coordinate by y. y coordinate by z and z-coordinate by x value.We know from above the equation
for rotation about z-axis
x cos 8 y sin 8
y xsin0+y cos 0
=
Here the y and z coordinates change whereas the x-coordinate remains the same
0 cose sine
(For Anticlockwise direction)
0-sine cose
0
0
0 cos- sin6
0 sine cos0 : (For Clockwise direction)
0
Rotation of object about X-axis does not alter the X-coordinate. It only affects Y and Z-coordinates. Rotation
about X axis is given by.
0 cos sin 0
Where, R, (0) =
0 sin cos 0
0 0 0
Similarly, rotation of an object about Y-axis does not alter the Y-coordinate. It only affects Z and X-coordinates.
Rotation about Y-axis is given by,
X z sin 0 + x cos 6
y
z 2 cos 0-x sin 0
Matrix representation ofabove equation using homogeneous coordinate is given as follow:
P = R, (0) P
cos 0 sin 0
0 1 0 0
Where, R, 0) =
sin 0 cos 0
0 0 0 J
Ceseasy-solutions
Computer Graphics (SPPU Quick Read
Rotation about Z-axis
.Similarly, rotation of object about Z-axis does not alter the Z-coordinate. It only affects X and Y coordinates
Rotation about Z-axis is given by,
X Xcos 6- y sin 0
y xsin 0+ y cos
PR, (0) P
cos sin 0 0
sin 6 cos 0 0D
Where, R, (O) =
1
0
cos(-0) =
coscos
0and sin(-
Ssin
0)=-sin 0
0 0
- sin 0 cos 0 0 0
Hence, R, (-0) =
1
PA
X
origin Z-axis
P
P
2P
(d) Step 3: Rotation about (e) Step 4: Rotate the axis to ( ) Step 5: Translate the axis to
We can align the rotation axis with any of the principal axes. For the sake of discussion, we will align it with
the Z-axis.
Let Piku y Z) and Pz(xz Y 2) be the endpoints of the rotation axis depicted in Fig. 7.6
Palbaza)
P112)
uVIy-x,)+-y)+(Za-21)
( a , b, c)
Where,aVb
and, IV Va-x,+ -y)+ - z,
es easy-solutionsS
Computer Graphics (SPPU) 7 Quick Read
If the rotation axis is not passing through the origin, we should translate any of the endpoints(Pi or Pa) to the
origln. Omit this step if rotation axis is already passing through the origin.
For the given case, let us translate the point Pi to the origin. This is done by applying the following translation
matrix to the endpoints of the rotation axls.
P2 (*2 Y2 22)
P (0, 0,0)
ul0.b.o u[a.b.c)
Torch
Shadow
o (0,0.0)
coordinate; it does not affect remaining coordinates. It is easier to find out an angle a
plane only eliminates the x
eseasy-solutions
Computer Graphics (SPPU) Quick Read
As shown in
8
Fig. 7.9 Vector
u makes and by the ange d around
axis, u' will get align with Z-axis and u
an
angle with the Z-axis. If we rotate
a u ui
X
will fallin XZ plane.
g0.b.c ufa.b.c)
o (0.0,0)
u' (a.0.d)
esonsy-solutlons
Computer Graphics (SPPU) Quick Read
cos - sin 0 0 0
sin cos 0 0 0
R () =
0 010
0
To move the rotation axis to its actual position, perform the first three steps in reverse order. The composite
transformation matrix would be,
10 0 0
cos -sin 0 0 d 0 -a 0
sin 0 cos0 0 0 0 1 0 0 0 1 0 -Yi
001-z1
0 0 0 JL o o 0 1 Lo 0 0 1
0 1
0 0 0
d 0 -a 0
0 10 0
Here, R,(B) R,(o)
=
a 0 d
o c/d o
A
b
0 0 0
Lo o 0 1 0 0
0 a 0
10 0 0
d o a
0 -ab
dc/dbo
=A
And R () R) (B) =
in 3D, relection can be performed either with respect to the selected axis or with respect to the selected plane.
Transformation matrices for reflection about X= 0, Y= 0and Z = Oplanes are shown below
0
1 0
Refix-0) 0 0 10
0 0 1-
10 0 0
0-1 0 0
Rely 0) 0 0 1 0
00 0 1-
0 0 0
0 1 0 0
Retz-0) 0 0 1 0
0 0 0 1-
We can compute the reflected coordinate of the object about a plane X= 0 by following transformation sequence.
P M P =Refx-oy PP
X -1 0 0 0
0
X -Xx
z 2
When wetake reflection aboutX= 0 plane, only X-coordinate of the object vertices would be
flipped, there won't
be any change in Y and Z coordinates. We can observe the similar effect for reflection
about other planes.
Fig. 7.12 describes the reflection about X = 0 plane. Grey object is the reflected one.
***
es 0asy-solutions
Computer Graphics (SPPU) 21 Quick Read
Reflection through the general plane
A b o v e matrices are valid for reflection through any of the principal planes. We can extend the concept for
relection through arbitrary plane using rotation, translaton and reflecton.
Plane is uniquely identified by two parameters: the reference point from which plane is passing and the normal
vector of the plane.
Let us find the transformation matrix for reflection through a plane passing from reference point R, and havingg
normal vector N = ai + bj +ck. The transformation is achieved by performing the following steps:
M R R ) Refa-o Rr Ra
Q.6 What are the types of projection and write in briet about each type of projections. SPPU May 17, May 19, 6 Marks
Ans.; Projection
Tt is the process of converting a 3D object into a 2D object.
It is also defined as mapping or transformation of the object in projection plane or view plane
The view plane is displayed surface. It is the plane on which the object is projected. It is also known as a
projection plane or plane of projection.
Projection is broadly classified into two categories : Parallel projection and perspective projection.
Center ot
projecion
Projectors
Projectors
es 0asy-solutions
Quick Read
Computer Graphics(SPPU) 2
line in space. PiP2 Is projected
Fig. 7.13 demonstrates parallel and perspective projectlons. PPa is the original
line on 2D view plane.
e case or parallel projection, projectors are parallel to each other, whereas in case of perspectuve projection
Types'of Projection
Perspective
Parallel
Fig.7.14:Taxonomy of projection
a.7 Explain the following term with an example: Parallel projection. SPPU-Dec. 15, Dec. 18,2 Marks
Ans.
Parallel projection discards z-coordinate and parallel lines from each vertex on the object are extended until they
intersect the view plane.
In parallel projection, we specify a direction of projection instead of center of projection.
In parallel projection, the distance from the center of projection to project plane is infinite.
in this type of projection, we connect the projected vertices by line segments which correspond to connections
on the original object.
all projection vectors are parallel to each other.
In parallel projection,
Parallel projections are less realistic, but they are good for exact measurements. In this type of projections
Darallel lines remain parallel and angles are not preserved. Various types of parallel projections are shown in the
following hierarchy.
Parallel Projection
orthographie Oblique
Side AxonametricCavaier
Gabiner
Fig.7.15: Classification of parallel projection
esasy-solutions
Computer Graphics (SPPU) 23 Quick Read
Parallel projection is achieved by passing parallel rays from the object vertices and projecting the objecton view plane.
. In parallel projection, all projection vectors are parallel to each other.
D)
(
parallel projection. projectors are parallel to each other but are not perpendicular
If to the view plane, it is
called oblique parallel projection. Both types of projections are illustrated in Fig. 7.16
Q.8 Explain perspective projection with example. SPPU-Dec. 15, May 18, 4 Marks
Ans.: Perspective Projection
information but it does not
Perspective projection preserves the depth
preserve the true shape and size of the object. Size of the projected
the distance between the view plane, the center of
object depends on
Let us derive the transformation matrix for the perspective projection of point P(x. y, z) on view plane
is at distance d from the origin on Z-axis as shown in
Z 0 (i.e. XY plane). Assume that the center of projection (COP)
Fig. 7.18.
Px.y.2)
plane
Viewp
PMy.)
Conler
Projocionn
XY plane
Fig. 7.18: Perspective projection of P(x, y, z) on
escasy-solutions
Computer Graphics (SPPU) 24
Quick Read
View plane
PXY.
PpY
COP
Ya
yp z+d
v i e w plane
M.y.2)
pYp
OP center
of projection
Fig. 7.20:
Ifwe look from the Y-axis, Fig. 7.17 looks
as
Xd
Xp z+d
at z =
0, projected z coordinate would be 0.
.As view plane is positioned
Zp 0
d 0 0
0 d 00
F r o m this, we can define a transformation matrix as, M = 0 0 0 0
0 o 1 d
P. = M.P
Projected Coordinates,
1 d
or it Is not parallel
to XY plane in that case
is not XY plane
Ifview plane the normal of
the plane get aligned with 2-axis.
transformation such that
Ces 0asy-solutions
Computer Graphics (SPPU)_ 25
Other cases of
Quick Read
perspective projections are discussed at the end of this section.
a.9 Compare Parallel Projection and Perspective Projection.
(4 Marks)
Ans.:
Parallel vs. Perspective Projection
Sr. Parallel Projection
Perspective Projection
NO.
5. True shape and size of an object is preserved The projected object is foreshortened equally in all
three directions.
6. Example Example:
Top View
Top View Front View R . S .V i e w
es 0asy-solutions