0% found this document useful (0 votes)
33 views25 pages

Unit 03

The document discusses concepts related to windowing and clipping in computer graphics, focusing on line clipping and the Cohen-Sutherland algorithm. It explains how to determine which parts of a line are visible within a clipping window and details the steps of the Cohen-Sutherland algorithm for line clipping. Additionally, it introduces the Sutherland-Hodgeman algorithm for polygon clipping, outlining its process and advantages.

Uploaded by

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

Unit 03

The document discusses concepts related to windowing and clipping in computer graphics, focusing on line clipping and the Cohen-Sutherland algorithm. It explains how to determine which parts of a line are visible within a clipping window and details the steps of the Cohen-Sutherland algorithm for line clipping. Additionally, it introduces the Sutherland-Hodgeman algorithm for polygon clipping, outlining its process and advantages.

Uploaded by

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

Savitribai Phule Pune Universityy

Semester N (Information Technology)


Computer Graphics

Unit III: Windowing, Clipping,3D


Transformation, Projections
Chapter 6: Windowing and Clipping

a.1 What 1s Line Cliping ? (4 Marks)


Ans.: Line Clipping
The line is widely used primitive in engineering drawing Most of the engineering shapes contain lines.

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,

the line may be partially visible or completely outside the window.

Fig. 6.1

Line EF is completely visible and will be displayed as it is.

of line AB with the top edge is A'.


One endpoint of line AB is outside the clipping region. The intersection point
Hence segment AA' will be displayed and A'B will be clipped.

Line CD is completely outside the clipping window so it won't be displayed at all.

Line HI intersects left and top border of clipping regions. Intersections with respective boundaries are H and I.

So only segment HT will be displayed. Segments HH' and II would be clipped.

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

region of interest (the viewport).

Bottom Right
Top Left
1000 1010

0001 0000 0010

0101 0100 0110

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

(XWmin YWmin (XW1ax YWmin)


Fig. 6.4

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)

Calculate the four bit outcode as follows:

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).

There are 3 possibilities for the line:


1) Line is completely inside the window (This line should be displayed)
line lies outside the window and should be completely
2) Line lies completely outside the window (This
removed).
line and windoww
3) Line can be inside the window (here we find point of intersection between the
partially
boundary and draw only that portion of line that lies inside the window).

1001 1000 1010

0001 0000 0010

O101 0100 0110

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

The result of logical AND operation on both the


outcodes is 0010. As the result of AND operation is non
zero, line
CD is clipped and not displayed as it lies outside the window boundary.

1001 1000 C 1010


F

G D
0001 0000 0010

0101 0100 0110

Fig. 6.6 Different clipping cases

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.

Letthis point be P2. clip line P2 F. Now you have

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

Slope of PP1 x-X1


We need to find y but slope is known,

y-y1 m(X-X1) b u t x = xwmin

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

ifxKmaxthen Outcode_A(3) = 1 else 0


ifxXmaxthen Outcode B(3) = 1 else 0
ifxi Xmtn then Outcode A(4) = 1 else 0 ifx2< Xmin then Outcode B(4) = 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.

Sutherland Hodgeman Polygon Clipping Algorithm


as we know by
definition of polygon that it isa
The line drawing algorithm cannot be used for polygon clipping
it not give a closed figure so we follow
closed figure. So if line clipping algorithm is used for polygon clipping may
another method i.e the Sutherland- Hodgman algorithm for this purpose

The Sutherland Hodgman algorithm performs a clipping of a polygon


of verices
against each window edge accepts an ordered sequence
in turn. It
v1, v2, v3, ., Vn and puts out a set of vertices defining the clipped polygon
We start with the given set of olygon vertices. We first clip the given polygon
the left boundary of the window to produce a new sequence of
against
vertices.
The obtained set of vertices is then successively passed to the right

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.

Fig.6.11:Stages of polygon clipping


(es 0ay-s0lutions
Computer Graphics (SPPU) Quick Read
1 Clip Left

Consider the polygon ABC to be clipped against the window as


shown in Fig. 6.12. Let us consider the left window boundary edge
AB and AC intersects it at point P and P2 respectively. For edge AB
we store P1 annd B and the edge AC we store P2 C.

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

6.14. The process of converting a polygon to a set of triangles is


Fig.
known as tessellation. Then process each convex polygon

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

successfully eliminates the extraneous edge.


This algorithm is well suited for hardware implementation and can easily be parallelized on multiple processors,
each processor works as a clipper. However, this method works only for convex clipping reglon.

e s easy-solutions
Computer Graphics (SPPU) Quick Read
IN OUT

Fig. 6.15:Solving the issue of Sutherland-Hodgeman algorithm


Algorithm
Sutherland-Hodgeman Polygon Clipping Algorithm :

1. Read coordinates of all vertices of the Polygon.


2. Read coordinates of the clipping window
3. Consider the left edge of the window
4. Compare the vertices of each edge of the polygon, individualy with the clipping plane.
5. Save the resulting intersections and vertices in the new list of vertices according to four possible relationships
between the edge and the clipping boundary.
6. Repeat the steps 4 and 5 for remaining edges or the clipping window. Each time the resultant list of vertices is
successively passed to process the next edge of the clipping window.
7. Stop.
Advantages
I t is easy to implement
. I t clips polygon against all edges of the clipping polygon
Well suited for hardware implementation
Disadvantages
Only works for convex clipping polyon
It clips to each window boundary one at a time
It has redundant edge-line cross computation
Requires considerable amount of memory to store all polygons in original form
Sometime produces single polygon instead of multiple polygons for concave polygon

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):

Input to the algorithm: {V Va, Vi, Va, Vs}


Output of left lipper: (V. Vi, Ve, Va, V, Vs}
Output of right clipper: (V, Vi', Va', Va, V, Vs}
* * * * * * * * * * *

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

take into consideration few things


o If the pair of vertex in consideration is outside to inside, then we follow polygon boundary.
o If the pair of vertex in consideration is inside to outside then we move around the window boundary.

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

intersection points and vertices of the


polygon.
Order of Subject Polygon list- Write down all the vertices of the polygon In the subject polygon column.

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

Chapter 7:3D Transformation and Projections


a.1 Write transfomation matrices for 3D translation.
SPPU-Dec, 18,2Marks
Ans.: Transalation
Translation allows to change the position by adding some integers to each coordinate.
Translation in 3D is similar to translation in 2D.
In case of 3D we have an additional z coordinate. To specify the amount of motion in the direction of each of the
coordinate axes.
A translation by (t, ty, tz) transforms the point (x. y, z) to (x+x, y+ty, 2 + tz). (bx, ty, tz) are translation factors
in respective(x, y, z]direction
Let us consider the original point P (x, y, 2), which becomes P(, y';z) after translation. Translated coordinates
are computed by following equations:
XX+

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

(a) Original object P (b) Translated object P


Fig.7.1: Translation of object in space

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

Ccaing is used to change the size of


three factors
an object. The size of an object can be increased or decreased. For scaling the
are required
S, and Sy S.
S Scaling factor in x- direction S, Scaling factor in y-direction S, Scaling factor in z-direction.
= =

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

Onginal object Otject after scaling


(Increase in size)

Fig. 7.2:
Shows Scaling9

Original otject Objact after scaling


(decrease in size)

Fig. 7.3:shows the scaling operation

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

Putting the above expression in matrix form, using homogenous coordinates

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-

in clockwise direction by negating angle of rotation. The


The above matrix can be used for rotation about z-axis
matrix will be as given below

cose sine 0 0
sine cos 0 0
0 10
0 0 0 1J

Rotation about X-axis


z-axis using the
We can derive matrix for rotation about x-axis from the transformation matrix of rotation about
axis.
cyclic permutation of the coordinates
Xy 2*

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

y y cos 0-z sin 0


y sin 0+z cos 0

Re-writing the above equation in matrix form


10 0 00

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.

y y cos 0-z sin 0D

z y sin 0+z cos


Matrix representation of above equation using homogeneous coordinate is given as follow:
P R,(0).P
1

0 cos sin 0
Where, R, (0) =
0 sin cos 0
0 0 0

Rotation about Y-axis

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

M a t r i x representation of above equation using homogeneous coordinate is given as follow:

PR, (0) P
cos sin 0 0
sin 6 cos 0 0D
Where, R, (O) =

1
0

Inverse rotation matrix


matrix for inverse rotation
Inverse rotation is achieved by negating the rotation angle . The transformation
about Z-axis is shown below:
0 0
cos (-6)-sin (-6)
sin (-0) cos (-0) 0 0
R,(-6) 0 0 1 o
0 1
Cosine is even function and sine is an odd function, hence;

cos(-0) =
coscos
0and sin(-
Ssin
0)=-sin 0
0 0
- sin 0 cos 0 0 0

Hence, R, (-0) =
1

-0 in rotation matrix R,(0) and


Similarly, we can achieve inverse rotation about X and Y-axis by replacing 0 by
R,0), respectively.
Q.4 Explain how to perform rotation about an arbitrary axis in 3D with a diagram. SPPU-May 17, May 18, 4 Marks
Ans.

Rotation About an Arbitrary Line

In real-world applications, rotation about the principal


axis is a rare case. Application programmer needs to

rotate the object around any arbitrary axis in space.

the principal axis, it requires more efforts.


When the object is to be rotated around a line which is not parallel to

This case is more complicated than the previous cases.

Desired rotation is achieved by the


Let the rotation axis passes from the points P;P2 as shown in Fig. 7.5(a).
composite transformation. Following steps should be performed for that:

Translate the rotation axis such that it passes through


the origin (Refer Fig. 7.5(b)).
Step 1:
Rotate the translation axis such that it
coincides one
of the principal axes (Refer Fig. 7.5(c)
Step 2:
Step 3: Perform the actual rotation operation (Refer Fig. 7.5(d).
Perform inverse rotation to bring rotation axis to the original orientation (Refer Fig. 7.5(e))
Step 4:
Step 5: Perform inverse translation to move back the rotation axis to its original location (Refer Fig. 7.5(O).-
Ces 0asy-solutions3
Computer Graphics (SPPU) 16 Quick Read
The sequence of the operations to perform the desired rotation is described in Fig. 7.5.

PA
X

(a) (6) (C)

(a)Initial Configuration (6) Step 1:Translate Pi to the (c) Step 2: Align Pi Pa to

origin Z-axis

P
P
2P
(d) Step 3: Rotation about (e) Step 4: Rotate the axis to ( ) Step 5: Translate the axis to

Z-axis by given angle the original orientation the original location

Fig. 7.5: Rotation about an arbitrary line

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)

Fig. 7.6: Orientation of rotation axis PiPa

Direction of rotation axis PaPa is given by:

P,PaPa- P1 = V= (%a-X, y2 - Y1, 22-)

Unit vector in direction of rotation axis is defined as

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)

Fig. 7.7: Position of rotation axis after translation by point Pi


1 0 0 -X
0
T
o 1
-Y
0 o 1-Z1
Lo o 0 1
This transformation moves the rotation axis as shown in Fig. 7.7, Pi' and Pa' are the translated coordinates of the
original endpoints.
Length of the rotation axis is already normalized to simplify the mathematical computation. So, normalized
coordinates of u would be (a, b, c) as computed before.
Now align the rotation axis with the Z-axis, to do so rotate the vector u around the X-axis in anticlockwise
direction by the angle a such that unit vector falls in XZ plane.
Then rotate unit vector in XZ plane around the Y-axis in a clockwise direction by the angle p to align it with the Z.
axis.
To align the vector u with Z-axis, first put the torch on X-axis such that the shadow of vector u falls in YZ plane,
call the shadow u
As this would be parallel projection on the YZ plane, x coordinate will become 0 and the remaining two
coordinates will not alter

ul0.b.o u[a.b.c)

Torch
Shadow

o (0,0.0)

Fig. 7.8: Shadow of vector u on YZ plane


As shown in Fig. 7.8, parallel projection of vector u on YZ plane would be u'(0, b, c). Parallel projection on the YZ

coordinate; it does not affect remaining coordinates. It is easier to find out an angle a
plane only eliminates the x

with projected vector u1, compared to u,

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)

Fig.7.9:Computation of angle a from projected vector ui


F r o m Fig 7.10, sin and cosine angles between uj and Z axis is computed using trigonometric rue ds,

sin a Opposite side b


Hypotenuse d

cos a Adjacent side


Hypotenuse
d Vb+
T h e rotation
matrix around the X-axis is,
0 00
0 cosa-sin a 0 0 c/d - b/d 0
R,(a)= 0 sin a cos a 0 b/d c/d 0

This transformation matrix


0

moves unit vector u from


0 0 JL XZ 2D
space to plane as shown in Fig. 7.11. Here, u' is the
vector after rotation of u around the X-axis by an angle a.

u' (a.0.d)

Fig. 7.11:Position of vector u after rotation about


X-axis angle a by the
As rotation was performed about X-axis, the x
component ot u won't
change. And u' is in XZ plane, so its y
component is zero, and z component is d, we
already computed. Rotation does
not alter the
length of vector u' will remain 1. length and hence the
I a (bc-1
If we rotate u' by the angle p about Y-axis in a clockwise direction, it will be aligned with the Z- axis.
S.
a 7 12. sin and cosine angles between u and L-axIS
IS computed using the trigonometric rule as,

esonsy-solutlons
Computer Graphics (SPPU) Quick Read

sin p Opposite side=a


Hypotenuse
cos B Adjacent side
Hypotenuse -d
So transformation matrix for rotation about Y-axis would be,
cos 0 sinB 0 d 0 -a 0
01 0 0 0. 1 0 0

R,(B) sin B 0 cosB 0 a 0 d


0
0 0 Lo o o 1J
Above three steps, translation, rotation about X-axis and rotation about Y-axis would align line P;Pa to the Z-axis.
The actual rotation about 1ine P.Pz by the angle 0 is achieved by rotation about Z-axis using the following
rotation matrix.

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,

R(0) TR; () R) (9) R,(0) R,(8) R().T


10 0 0
d 0 a0
o 1 0 Y1 0 1 00
-a 0 d 0
0 0 1
Z1
L 0 0 0 1
0 0 0 1
0 0 0 1.

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) =

R(0)= T:A, (B) R(0) A, T


es0asy-olutions
Computer Graphics (SPPU 20 Quick Read
This is the desired transformation sequence.
Note: f the rotation axis is passing from the orngin, then translation and inverse translation step9 are not
requireu
Assumption: Length of rotation axis is normalized, i.e. I = ]v] = 1.
Q.5 Write transformation matrix for 3-D rellection w.r.t. x-axis.
SPPU-May 19. 2 Marks
Ans.: Reflection

in 3D, relection can be performed either with respect to the selected axis or with respect to the selected plane.

Reflection about an axis is equivalent to rotation by 180° about that axis.

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.

***

Fig.7.12:Reflection about X=0 plane

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:

1. Translate the reference point to the origin.


2. Align the normal vector N to Z-axis by performing the following steps.
() Rotate normal N by the angle a about X-axis such that it falls in XY plane.
(ii) Rotate the vector in XY plane about Y-axis by the angle B such that it gets aligned with the
Z-axis.
3. Perform reflection through Z = 0 plane.

4. Inverse rotation about Y axis by angle B.


5. Inverse rotation about X-axis by angle a.
6. Inverse translation to reposition the reference point to the original location.
So, the transformation matrix would be,

M TR R Refz-oy Ror Raco T


Ifreference point is specified at the origin, then we do not need to perform step 1 and 6. In that case,

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

View plane View plane

() Parallel Projection (b) Perspective Projection


Fig. 7.13: Types of projection
Parallel projection
In parallel projection, coordinate positions of the object are transformed to view plane by parallel
rays/projectors (Refer Fig. 7.13 (a)).
In perspective projection, rays are fired from a point source, called center of projection, which intersects the

object coordinates and projects


it on view plane (Refer Fig. 7.13 (b)).

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

rays are inclined and meeting at a point called center of projection.


. W e can classify projections as follows:
Types of Projection

Types'of Projection

Perspective
Parallel

Orthographi Oblique Ome point Two poin:


Three
poin:

MutiviewAxonometric Cavalier Cabinet

|1sometric Dimetric Trimetric

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)
(

Orthographic parallel projection Oblique parallel projection


Fig. 7.16: Types of parallel projection
Parallel projection preserves true shape and size of the object on view plane.
However, it fails to capture depth information and hence cannot produce a realistic view.
Based on the direction of the projection vectors and their relation with view plane, parallel projection is further
classified as an orthographic parallel projection or oblique parallel projection.
When all projectors are parallel to each other and perpendicular to the view plane, it is called orthographic

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

projection and the object.

Projection of a distant object is smaller than that of the nearer object


Fig. 7.17 describes this property of perspective projection.

Fig. 7.17: Effect of perspective projection

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

Fig. 7.19: View from X-axis


is behind
Z-axis and centre of projection
For this particular case, we are considering that the object is on positive to valid position
be generalized any
projection plane i.e. on d distance on negative Z-axis. Although, this can
ne
of object, view-plane and COP.
lf we look from the X-axis, Fig. 7.18 looks like Fig. 7.19. From the triangle equality rule,

Ya
yp z+d
v i e w plane
M.y.2)
pYp

OP center
of projection

Fig. 7.20: View from Y-axis

Fig. 7.20:
Ifwe look from the Y-axis, Fig. 7.17 looks
as

From the triangle equality rule,

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.

1. Projectors are parallel to each other.


Projectors are not parallel.
2.
Need to specify the direction of projection. Need to specify the center of projection.
3.
Center of projection is at infinite distance Center of projection is at a finite distance.

4. Does not produce realistic view.


a Produces realistic view.

5. Depth information is lost Depth information is preserved.


6.
Preserve relative proportion of object. Does not Preserve relative proportion of object.
7.
Subtypes: Orthographic projection, oblique Subtypes: Single point two points, three-point
projection. projection
a.10 Differentiate Between Orthographic and Isometric Projection. (4 Marks)
Ans.: Orthographic vs. Isometric Projection

Sr. No. Orthographic Projection Isometric Projection


Provides a 2D view of the object Provides a 3D view of the object
2. Each view of orthographic projection shows only|lsometric projection displays at least three sides of
one side of the object the object
. |In orthographic projection, the projection plane is| In isometric projection, the projection plane is not
parallel to one of the principal plane
parallel to any oftheprincipalplane
4.
Does not preserve depth Dose include depth

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

Front Vieww A Side View

es 0asy-solutions

You might also like