0% found this document useful (0 votes)
17 views28 pages

Computer Graphics 2

The document discusses various algorithms and transformations in computer graphics, including the Midpoint Circle Drawing Algorithm, 2D General Pivot-Point Rotation, and reflections of 2D objects. It explains the steps involved in these transformations, emphasizing their efficiency and mathematical foundations. Additionally, it covers scaling operations in 3D and the calculation of frame buffer sizes, alongside deriving 2D coordinate transformation equations.

Uploaded by

Marzia Borno
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)
17 views28 pages

Computer Graphics 2

The document discusses various algorithms and transformations in computer graphics, including the Midpoint Circle Drawing Algorithm, 2D General Pivot-Point Rotation, and reflections of 2D objects. It explains the steps involved in these transformations, emphasizing their efficiency and mathematical foundations. Additionally, it covers scaling operations in 3D and the calculation of frame buffer sizes, alongside deriving 2D coordinate transformation equations.

Uploaded by

Marzia Borno
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/ 28

2018-Question 1 Sf=S2⋅S1

B. Midpoint Circle Drawing Algorithm For example, if the first scaling matrix is S(sx1,sy1) and the
second is S(sx2,sy2), the final scaling values will be sx1⋅sx2
The Midpoint Circle Drawing Algorithm is an incremental and sy1⋅sy2.
algorithm that is an extension of the Bresenham line
algorithm. It is used to draw circles by approximating the B. 2D General Pivot-Point Rotation
curve with discrete pixels.
2D General Pivot-Point Rotation is the process of rotating
Here's how it works: an object about a specified point, known as the pivot
point, rather than the origin. The transformation is
1. It starts at the top of the circle at point (0,r), accomplished in three steps:
where r is the radius.
2. It calculates the coordinates for one octant (one- Step 1: Translation Translate the object such that the
eighth) of the circle. pivot point (xp,yp) moves to the origin. This is done by
3. For each step, it uses a decision parameter to applying a translation matrix T(−xp,−yp):
choose between two candidate pixels. This
parameter determines which pixel is closest to T1=100010−xp−yp1
the true circle arc.
4. It plots the chosen pixel and then uses symmetry
Step 2: Rotation Rotate the object about the origin by the
to plot the corresponding points in the other
desired angle θ. The rotation matrix R(θ) is:
seven octants.

R(θ)=cosθsinθ0−sinθcosθ0001
Advantage of using Midpoint Circle over other circle
drawing algorithms:
Step 3: Inverse Translation Translate the object back to its
original position by moving the pivot point from the origin
The primary advantage of the Midpoint Circle algorithm is
to (xp,yp). This is an inverse translation with matrix T(xp,yp
its efficiency.
):

 It performs calculations using only integer


T2=100010xpyp1
arithmetic. This avoids floating-point operations,
which are computationally expensive and can be
slow. This makes it a very fast algorithm for real- The final composite transformation matrix, which can be
time graphics. applied to any point (x,y) of the object, is the product of
these three matrices: Tfinal=T2⋅R(θ)⋅T1
 It's incremental, meaning it calculates the next
pixel based on the previous one. This avoids
repetitive or expensive calculations. C. Reflection of a 2D Object
 By calculating one octant and then using
symmetry, it significantly reduces the number of The reflection of a 2D object relative to an axis
required calculations, as only 1/8th of the circle perpendicular to the XY plane and passing through point P
needs to be computed directly. is the same as a reflection about a point. A reflection
about a point P in 2D space inverts the coordinates relative
Question 2. to that point. The transformation involves a series of steps
similar to the pivot-point rotation.
A. Scaling in 2-Dimensional Composite Transformation
Step 1: Translation Translate the object so that the point
of reflection P(xp,yp) moves to the origin.
When concatenating successive scaling operations in a 2D
composite transformation, the resulting output is
multiplicative. T1=100010−xp−yp1

This is because composite transformations are achieved by Step 2: Reflection about the Origin Reflect the object
multiplying the individual transformation matrices. If you about the origin. The reflection matrix MO is:
have two scaling operations with matrices S1 and S2, the
final transformation matrix Sf is given by the matrix MO=−1000−10001
multiplication:
Step 3: Inverse Translation Translate the object back so  Coordinate Transformation (Viewing
that the origin returns to the reflection point P(xp,yp). Transformation): In this case, the object remains
stationary in space, but the coordinate system
T2=100010xpyp1 itself is moved, rotated, or scaled. The
coordinates of the object's points change
The final composite transformation matrix for a point because they are now being measured with
respect to a new, transformed coordinate
reflection is: Tfinal=T2⋅MO⋅T1
system. This type of transformation is typically
used to change the viewpoint or camera
D. 3D Scaling Operation with a Fixed Point position, making it appear as if the objects in the
scene are moving relative to the viewer.
Similar to the 2D pivot-point rotation, a 3D scaling
operation with respect to a fixed point (xf,yf,zf) also B. 60∘ Rotation of Triangle A(1,1), B(11,2), C(5,5)
involves three steps:
This problem has two parts. First, we rotate the triangle
Step 1: Translation Translate the object so that the fixed about the origin, and second, we rotate it about point P(-1,
point (xf,yf,zf) coincides with the origin. 0). The question states "60∘" and "4.75" as angles.
Assuming the second angle is also 60∘ as is typical for this
T1=100001000010−xf−yf−zf1 type of problem, we proceed with the rotation by 60∘ in
both cases.
Step 2: Scaling Scale the object relative to the origin with
scaling factors (sx,sy,sz). The scaling matrix S(sx,sy,sz) is: Given: θ=60∘

S=sx0000sy0000sz00001  cos(60∘)=0.5
 sin(60∘)=23≈0.866
Step 3: Inverse Translation Translate the object back so
that the origin returns to the fixed point (xf,yf,zf). Part 1: Rotation About the Origin

T2=(100001000010xfyfzf1 The rotation formulas for a point (x,y) about the origin are:
x′=xcosθ−ysinθ y′=xsinθ+ycosθ
The final transformation matrix for a 3D scaling with a
fixed point is the product of these three matrices: Tfinal
 Vertex A(1,1):
=T2⋅S⋅T1
x′=1(0.5)−1(0.866)=0.5−0.866=−0.366
y′=1(0.866)+1(0.5)=0.866+0.5=1.366 A'(-0.366,
3.A What is transformation? 1.366)
 Vertex B(11,2):
In computer graphics, a transformation is a function that x′=11(0.5)−2(0.866)=5.5−1.732=3.768
maps a point from one coordinate system to another. It is y′=11(0.866)+2(0.5)=9.526+1.0=10.526 B'(3.768,
used to change the position, size, or orientation of an 10.526)
object. Common transformations include translation,  Vertex C(5,5):
rotation, and scaling. x′=5(0.5)−5(0.866)=2.5−4.33=−1.83
y′=5(0.866)+5(0.5)=4.33+2.5=6.83 C'(-1.83, 6.83)
The key difference between geometric transformations
and coordinate transformations lies in what is being Part 2: Rotation About Point P(-1, 0)
transformed: the object or the coordinate system itself.
This is a general pivot-point rotation. The transformation
 Geometric Transformation (Object for each point (x,y) is: (x′,y′)=(T(−xp,−yp)⋅R(θ)⋅T(xp,yp
Transformation): This is a transformation where ))⋅(x,y) with pivot point P(−1,0).
the object is moved, rotated, or scaled relative
to a fixed, stationary coordinate system. The
 Vertex A(1,1):
coordinate axes do not change, but the object's
1. Translate to origin: (1−(−1),1−0)=(2,1)
coordinates are updated to reflect its new
2. Rotate by 60∘:
position and orientation. This is the most
x′′=2(0.5)−1(0.866)=1−0.866=0.134
common type of transformation used to
y′′=2(0.866)+1(0.5)=1.732+0.5=2.232
manipulate objects within a scene.
The rotated point is (0.134,2.232).
3. Translate back: coordinate axis using a series of
(0.134+(−1),2.232+0)=(−0.866,2.232) transformations (translation and
A'(-0.866, 2.232) rotation). You then perform the
 Vertex B(11,2): reflection and finally apply the inverse
transformations to restore the object
and the axis to their original positions.
1. Translate to origin:
(11−(−1),2−0)=(12,2)
2. Rotate by 60∘: 4.A Frame Buffer Size Calculation
x′′=12(0.5)−2(0.866)=6−1.732=4.268
y′′=12(0.866)+2(0.5)=10.392+1=11.392 Step 1: Calculate the total number of pixels.
The rotated point is (4.268,11.392).
3. Translate back:
 Width in pixels = (screen width in inches) ×
(4.268+(−1),11.392+0)=(3.268,11.392)
(pixels per inch)
B'(3.268, 11.392)
 Vertex C(5,5):
 Width in pixels =
8 inches×100 pixels/inch=800 pixels
 Height in pixels = (screen height in inches) ×
1. Translate to origin: (5−(−1),5−0)=(6,5)
(pixels per inch)
2. Rotate by 60∘:
x′′=6(0.5)−5(0.866)=3−4.33=−1.33
 Height in pixels =
10 inches×100 pixels/inch=1000 pixels
y′′=6(0.866)+5(0.5)=5.196+2.5=7.696
The rotated point is (−1.33,7.696).  Total number of pixels =
3. Translate back: 800×1000=800,000 pixels
(−1.33+(−1),7.696+0)=(−2.33,7.696)
C'(-2.33, 7.696) Step 2: Calculate the number of bits per pixel.

C. Creating a Mirror Image of a 2D Object  The color lookup table (CLUT) has 64 positions.
The number of bits required to address 64
A mirror image of a 2D object is created using a reflection unique positions is determined by solving 2n=64.
transformation. This transformation flips the object across  Since 26=64, each pixel requires 6 bits to store
a specified line, known as the axis of reflection. the index of its color in the lookup table.

The coordinates of each point (x,y) on the object are Step 3: Calculate the total size in bytes.
changed to a new point (x′,y′) based on the axis of
reflection.  Total size in bits = (Total pixels) × (bits per pixel)
 Total size in bits = 800,000×6=4,800,000 bits
 Reflection about the x-axis:  Total size in bytes = (Total size in bits) / 8
o The x-coordinate remains the same,  Total size in bytes = 84,800,000=600,000 bytes
while the y-coordinate is inverted.
o Formulas: x′=x, y′=−y
o Transformation Matrix: The smallest possible size for the frame buffer is 600,000
bytes.

(100−1)
B. Derivation of 2D Coordinate Transformation Equations

 Reflection about the y-axis:


We are to derive the equations for transforming a point
o The y-coordinate remains the same,
P(x,y) to new coordinates (x′,y′) in a system rotated
while the x-coordinate is inverted.
counterclockwise by an angle θ. We will use the geometric
o Formulas: x′=−x, y′=y
method based on projecting the point onto the axes and
o Transformation Matrix:
using trigonometry.

(−1001)
1. Define the original point P. Let the original coordinate
system be (X,Y) and the new, rotated system be (X′,Y′). A
 Reflection about an arbitrary line: point P has coordinates (x,y) in the original system. Let the
o To reflect an object across a line that is distance of point P from the origin be r, and the angle it
not a coordinate axis, you must first makes with the X-axis be ϕ. From basic trigonometry, we
align the reflection axis with a have:
 x=rcosϕ  The light passes through a polarizer, which only
 y=rsinϕ allows light waves vibrating in a specific direction
to pass.
2. Define the new coordinates P'. The new coordinate  The polarized light then enters a layer of liquid
system (X′,Y′) is rotated counterclockwise by an angle θ crystals. Without an electric current, these
relative to the original system. The coordinates of point P crystals are arranged in a twisted structure that
in the new system are (x′,y′). The angle of point P with guides the light along its path.
respect to the new X'-axis is ϕ−θ. The new coordinates are  As the light exits the liquid crystal layer, it hits a
therefore: second polarizer, oriented 90 degrees from the
first one. Because the liquid crystals twisted the
light, it is able to pass through the second
 x′=rcos(ϕ−θ)
polarizer. This makes the pixel appear bright.
 y′=rsin(ϕ−θ)
b) State and explain Bresenham's Line Drawing
3. Use trigonometric identities to expand the algorithm.
expressions. We use the trigonometric identities for the
difference of two angles:
Bresenham's Line Drawing algorithm is an efficient and
widely used algorithm for drawing a line between two
 cos(A−B)=cosAcosB+sinAsinB points on a digital screen. It only uses integer arithmetic,
 sin(A−B)=sinAcosB−cosAsinB which makes it very fast and eliminates the need for
floating-point calculations, avoiding potential rounding
Applying these to our equations for x′ and y′: errors.

 x′=r(cosϕcosθ+sinϕsinθ) The algorithm's core idea is to determine the next pixel to


plot by evaluating the error between the ideal line and the
 y′=r(sinϕcosθ−cosϕsinθ)
closest pixel. It makes a decision at each step about which
pixel to choose, either moving horizontally or diagonally,
4. Substitute original coordinates to obtain the final based on a decision parameter.
equations. Now, we substitute x=rcosϕ and y=rsinϕ back
into the expanded equations:
Here is a simplified explanation of the algorithm's steps for
a line with a slope between 0 and 1:
 x′=(rcosϕ)cosθ+(rsinϕ)sinθ
 y′=(rsinϕ)cosθ−(rcosϕ)sinθ 1. Input: The starting point (x0,y0) and the ending
point (x1,y1).
This gives us the final transformation equations: 2. Calculate initial parameters: Determine the
change in x (Δx) and the change in y (Δy).
3. Initialize the decision parameter (p0): p0
 x′=xcosθ+ysinθ
=2Δy−Δx
 y′=−xsinθ+ycosθ 4. Loop: Start from the initial point and iterate until
the end point is reached. At each step, consider
2017- Question 1 two possible pixels: a horizontal one and a
diagonal one.
a) Explain the working principle of Liquid Crystal Display o If pk<0: The next pixel to choose is the
(LCD) as a flat panel display device. horizontal one. pk+1=pk+2ΔyThe new
point is$$(x_k + 1, y_k)$$.
An LCD (Liquid Crystal Display) works by manipulating light
o If pk≥0: The next pixel to choose is the
using liquid crystals. Liquid crystals are special molecules diagonal one. pk+1=pk+2Δy−2ΔxThe
new point is$$(x_k + 1, y_k + 1)$$.
that can be twisted or untwisted by applying an electric
current. This twisting and untwisting changes the path of 5. Plot the points: Plot the pixel coordinates
light passing through them. decided in each step.

Question 2
Here's how it generally works:

a) Define differential scaling.


 A backlight (usually LED) provides the light
source.
Differential scaling, also known as non-uniform scaling, is a producing correct results (multiple polygons) where other
geometric transformation that scales an object by algorithms might fail.
different amounts along different axes. Unlike uniform
scaling, where an object is scaled by the same factor in all Here is a general outline of the algorithm:
directions, differential scaling can stretch or compress an
object, changing its proportions.
1. Identify Intersection Points: Find all intersection
points between the edges of the subject polygon
For a 2D object with a point and the clip polygon.
2. Mark Vertices: For both the subject and clip
(x,y) polygons, mark the vertices as "inside" or
"outside" the other polygon. For intersection
, differential scaling is typically represented by a scaling points, they are marked as "entering" or
matrix:x′y′1=Sx000Sy0001⋅xy1where Sx is the scaling "exiting" the clip polygon boundary.
factor along the x-axis and Sy is the scaling factor along the 3. Establish Lists: Create an ordered list of vertices
y-axis.If Sx =Sy, the scaling is differential. This type of for the subject polygon and a separate list for
scaling is useful in computer graphics for tasks like creating the clip polygon. Add the intersection points into
perspective effects, distorting shapes, or fitting objects their respective lists in the correct order along
into a specific region. the edges.
4. Traverse and Output: Start at a "valid" vertex,
which is typically the first "entering" intersection
b) With neat diagrams, explain 2D general fixed-point
point.
scaling.

The algorithm can be visualized as walking along the


2D fixed-point scaling is a transformation that scales an
boundary of the subject polygon.
object about a specific point other than the origin. This
"fixed point" remains in the same position before and
after the scaling transformation. The process of fixed-point Answer to Question 3
scaling involves three main steps:
a) What do you understand by "Blobby" objects?
1. Translate the fixed point to the origin: The
object is translated so that the desired fixed "Blobby" objects, also known as metaballs or implicit
point $$(x_f, y_f)$$moves to the origin$$(0, surfaces, are a type of computer graphics primitive used to
0)$$. This is done by a translation matrix T(−xf model organic, fluid, and malleable shapes. Unlike
,−yf). traditional polygonal objects composed of vertices and
2. Scale the object about the origin: Once the fixed faces, blobby objects are defined by mathematical
point is at the origin, a standard scaling functions, which represent a field of influence.
transformation is applied. This scales the object
relative to the new origin. The scaling matrix is Here's how it works:
S(sx,sy).
3. Translate the fixed point back to its original
position: The object is then translated back by  Each metaball is assigned a potential function,
the same amount it was initially moved, but in typically a decreasing function of distance from
the opposite direction. This is done by a its center. A common function is f(r)=1/r2.
translation matrix T(xf,yf).  To determine if a point in 3D space is part of the
object, the potential from all metaballs is
summed up at that point: P(x,y,z)=i∑fi(x,y,z).
The composite transformation matrix for fixed-point
scaling is:  The final surface is defined by the set of all
points where the summed potential equals a
specified threshold value, usually called the
T(xf,yf)⋅S(sx,sy)⋅T(−xf,−yf) isovalue or isolevel.

c) Explain the Weiler-Atherton polygon clipping


When two or more metaballs are close to each other, their
algorithm. fields of influence merge, causing their surfaces to "blob"
together smoothly.
The Weiler-Atherton polygon clipping algorithm is a
method for clipping a subject polygon against a clip b) Define "Convex hull" and "Control polygon".
polygon. It is particularly known for its ability to handle
complex cases, including concave subject polygons,
 Convex hull: The convex hull of a set of points in a) Describe Cohen-Sutherland line clipping algorithm.
a plane is the smallest convex polygon that
contains all of those points. Intuitively, if you The Cohen-Sutherland line clipping algorithm is a method
imagine the points as nails sticking out of a used to quickly and efficiently clip line segments against a
board, the convex hull is the shape a rubber rectangular window. It is a "divide and conquer" algorithm
band would form if stretched around all of the that categorizes each endpoint of a line segment based on
nails. its position relative to the clipping window.

A polygon is convex if for every pair of points The algorithm works as follows:
inside the polygon, the line segment connecting
them is also entirely contained within the 1. Region Codes (Outcodes): The 2D plane is
polygon. The convex hull is a fundamental
divided into 9 regions by extending the clipping
concept in computational geometry and is used
window's boundaries. Each region is assigned a
in various applications, including collision
4-bit binary code called a "region code" or
detection, shape analysis, and pattern
"outcode." The bits are assigned based on the
recognition.
point's position relative to the top, bottom,
right, and left edges of the clipping window.
 Control polygon: The control polygon (also o Bit 1 (Left): Set to 1 if the point is to
known as the Bézier polygon) is a sequence of the left of the window.
points used to define the shape of a curve, o Bit 2 (Right): Set to 1 if the point is to
typically a Bézier curve or B-spline. The vertices the right of the window.
of the control polygon are called control points. o Bit 3 (Bottom): Set to 1 if the point is
below the window.
The control polygon itself does not form the o Bit 4 (Top): Set to 1 if the point is
curve. Instead, it acts as a guide. The curve is a above the window.
smooth path that is "pulled" towards the control
points. The first and last points of the control The window itself has the region code 0000.
polygon are usually the endpoints of the curve.
The intermediate control points dictate the 2. Clipping Decisions: For a line segment with
shape and direction of the curve without actually endpoints P1andP2, the algorithm performs a
lying on the curve itself. series of checks using the outcodes:
o Case 1: Trivial Accept: If the outcode
c) State and explain "Cardinal splines" as an interpolating of both endpoints is 0000 (i.e.,
piece-wise cubic polynomials. outcode(P1) | outcode(P2) == 0000),
the entire line is inside the window. It
Cardinal splines are a type of cubic interpolating spline. is trivially accepted and can be drawn.
The term "interpolating" means that the curve passes o Case 2: Trivial Reject: If the bitwise
directly through all of the given control points. "Piece- AND of the outcodes is not 0000 (i.e.,
wise" means that the curve is made up of a series of outcode(P1) & outcode(P2) != 0000), it
segments, and each segment is a cubic polynomial defined means both endpoints are in the same
by a set of four control points. outside region (e.g., both are to the
left of the window).
3. Case 3: Clipping Required: If neither of the
The key feature of Cardinal splines is that they are
above conditions is met, the line segment
controlled by a single parameter, tension (t), which allows
intersects the window. This means one endpoint
the user to adjust the "tightness" of the curve. A high
is inside and one is outside, or both are outside
tension value makes the curve pass through the control
but cross the window.
points more sharply, while a low tension value makes it
4. Finding Intersections: For Case 3, the algorithm
smoother.Here's how it works:For a set of control points
iteratively clips the line. It chooses an endpoint
that is outside the window (has a non-zero
(P0,P1,P2,P3,...), a segment of the Cardinal spline that outcode). It then determines which boundary it
connects points Pkand$$P_{k+1}$$is defined by the four crosses (Top, Bottom, Left, or Right) based on its
surrounding points: outcode.
Pk−1,Pk,Pk+1,Pk+2.
b) Use the Cohen-Sutherland algorithm to clip line P1 (70,
Answer to Question 4 20) and P2 (100, 10) against a window lower left hand
corner (50, 10) and upper right hand corner (80, 40).
1. Define the clipping window and region codes: 5. Final check and conclusion:

 Clipping Window: The new line segment is from P1(70, 20) toP2′(80, 16.67).
o xmin=50,xmax=80*ymin=10,ymax=40
 Region Codes (Top-Bottom-Right-Left):  Outcode(P1) = 0000
o Top (T): y>40* Bottom (B):y<10* Right  Outcode(P2′) = The point (80, 16.67) is on the
(R):x>80* Left (L):x<50 right edge and within the y-range of the window
o 2. Determine the outcodes for P1 and (10≤16.67≤40). So, its outcode is 0000.
P2:
Both endpoints now have outcode 0000. The line segment
 P1 (70, 20): is trivially accepted.
o x=70: xmin≤70≤xmax(inside, not Left,
not Right) Conclusion: The clipped line segment is from (70, 20) to
o y=20: ymin≤20≤ymax(inside, not (80, 16.67).
Bottom, not Top)
o Outcode for P1 = 0000 (Inside)
2016- Question 1
 P2 (100, 10):
o x=100: 100>80(Right) -> Bit 1 is 1
o y=10: ymin≤10≤ymax(inside) -> Bit 2 is 1a) To illustrate the Bresenham line drawing algorithm,
0 digitize the line with endpoints (20, 10) and (30, 18). The
o Outcode for P2 = 0010 (Right) line has a slope of 0.8 with Δx=10 and Δy=8.

3. Analyze the line segment: The Bresenham line drawing algorithm is used to draw a
line by approximating the ideal line with pixels. We are
given the starting point (x0,y0)=(20,10) and the ending
 Outcode(P1) = 0000
point (x1,y1)=(30,18).
 Outcode(P2) = 0010
The change in x is Δx=x1−x0=30−20=10. The change in y is
Since the outcode for P1 is 0000, it is inside the window. Δy=y1−y0=18−10=8.
The outcode for P2 is not 0000, so it is outside. This means
the line segment intersects the right boundary of the
The initial decision parameter p0 is calculated using the
clipping window.
formula: p0=2Δy−Δx p0=2(8)−10 p0=16−10=6

4. Clip the line segment:


Now, we can iterate through the x-values from x0 to x1 to
determine the pixels to plot.
We need to find the intersection point of the line P1-P2
with the right edge of the window (x=80).
Next
Decisio
k xk yk pk Poin
 Line equation: y=m(x−x1)+y1* Slopem=x2−x1y2 n
t
−y1=100−7010−20=30−10=−31
p0>0,
 Substitute the values of P1 (70, 20) and the slope 2 1 (21,
0 6 so yk+1
into the line equation: y=−31(x−70)+20 0 0 11)
=yk+1
 Find the y-coordinate when x=80(the right edge):
p1=p0 p1>0,
2 1 (22,
1 +2Δy−2Δx=6+2(8)−2(10)=6+16−20= so yk+1
yint=−31(80−70)+20 1 1 12)
2 =yk+1
p2<0,
yint=−31(10)+20 2 1 (23,
2 p2=p1+2Δy−2Δx=2+16−20=−2 so yk+1
2 2 12)
=yk
yint=−310+360 p3>0,
2 1 (24,
3 p3=p2+2Δy=−2+16=14 so yk+1
3 2 13)
yint=350≈16.67 =yk+1
p4>0,
2 1 (25,
The new intersection point, let's call it P2′, is (80, 16.67). 4 p4=p3+2Δy−2Δx=14+16−20=10 so yk+1
4 3 14)
=yk+1
Next The new decision parameter is pk+1
Decisio =pk+2(xk−yk)+5.
k xk yk pk Poin
n 4. Symmetry: Once a pixel (x,y) is determined, the
t
other seven symmetric points are plotted as
p5>0,
2 1 (26, well:
5 p5=p4+2Δy−2Δx=10+16−20=6 so yk+1
5 4 15) o (x,y)
=yk+1
o (−x,y)
p6>0, o (x,−y)
2 1 (27,
6 p6=p5+2Δy−2Δx=6+16−20=2 so yk+1 o (−x,−y)
6 5 16)
=yk+1 o (y,x)
p7<0, o (−y,x)
2 1 (28,
7 p7=p6+2Δy−2Δx=2+16−20=−2 so yk+1 o (y,−x)
7 6 16)
=yk o (−y,−x)
p8>0, 5. Termination: The process continues until x is
2 1 (29, greater than or equal to y.
8 p8=p7+2Δy=−2+16=14 so yk+1
8 6 17)
=yk+1
p9>0, Solution to Question 2
2 1 (30,
9 p9=p8+2Δy−2Δx=14+16−20=10 so yk+1
9 7 18)
=yk+1 2a) Classify the projections. Explain the properties of
Export to Sheets each.

The digitized pixels for the line are: (20, 10), (21, 11), (22, Projections are methods used in computer graphics to
12), (23, 12), (24, 13), (25, 14), (26, 15), (27, 16), (28, 16), represent a 3D object on a 2D surface. They are broadly
(29, 17), (30, 18). classified into two main categories: Parallel Projections
and Perspective Projections.
1b) Explain midpoint circle drawing algorithm.
1. Parallel Projections: In parallel projections, the center
of projection is at an infinite distance from the view plane.
The midpoint circle drawing algorithm is an efficient
This means that all projection lines (projectors) are parallel
method for drawing a circle by plotting pixels. It uses the
to each other.
concept of a decision parameter to choose the next pixel
to plot. It is based on the equation of a circle: x2+y2=r2.
 Properties of Parallel Projections:
The algorithm works by focusing on one octant of the o Preserves Parallelism: Parallel lines in
circle and then using symmetry to plot the other seven 3D remain parallel in the 2D
octants. For a circle centered at the origin (0,0) with radius projection.
r, the process is as follows: o Does Not Preserve Size: The size of an
object in the projection does not
depend on its distance from the view
1. Initial Point: Start at the point (0,r). This is the plane.
first pixel to be plotted. o Useful for Engineering Drawings: This
2. Initial Decision Parameter: The decision property makes parallel projections
parameter is calculated to determine which of ideal for architectural and engineering
the two potential next pixels is closer to the true drawings where precise measurements
circle arc. The initial decision parameter, p0, is and relative proportions are crucial.
given by: p0=1−r o Types of Parallel Projections:
3. Iteration: The algorithm proceeds from x=0 to  Orthographic Projections:
x=y (or until x reaches the rounded value of r/2). The direction of projection is
At each step k, a decision is made based on the perpendicular to the view
current decision parameter, pk. The two plane. Examples include
candidate pixels are (xk+1,yk) and (xk+1,yk−1). multiview projections (e.g.,
o If pk<0: The midpoint is inside the front, top, and side views)
circle. The next pixel is (xk+1,yk). The and isometric projections.
new decision parameter is pk+1=pk
 Oblique Projections: The
+2xk+3.
direction of projection is not
o If pk≥0: The midpoint is outside or on perpendicular to the view
the circle. The next pixel is (xk+1,yk−1).
plane. A common example is
the Cavalier projection,
where lines perpendicular to with the origin (0,0) of the world coordinate
the view plane are projected system.
with no foreshortening. 2. Scaling: After translation, the window's
dimensions need to be scaled to match the
2. Perspective Projections: In perspective projections, the dimensions of the viewport. The scaling factors
center of projection is at a finite distance from the view are calculated as:
plane. All projection lines converge at this single point, o Sx=xw max−xw min xv max−xvmin
which is called the center of projection or viewpoint. o Sy=ywmax−ywminyvmax−yvmin where
(xwmin,ywmin) and (xwmax,ywmax)
are the coordinates of the window,
 Properties of Perspective Projections: and (xvmin,yvmin) and (xvmax,yvmax)
o Simulates Human Vision: Perspective are the coordinates of the viewport.
projections create a realistic view of 3. Translation (again): Finally, the scaled window,
objects, similar to how the human eye now at the origin, is translated to the lower-left
perceives the world. corner of the viewport. The translation is
o Does Not Preserve Parallelism: performed by adding the coordinates of the
Parallel lines in 3D that are not parallel viewport's lower-left corner to the scaled
to the view plane converge at a coordinates.
vanishing point in the 2D projection.
o Realistic but Lacks Precision: While
xv=(xw−xwmin)⋅xwmax−xwminxvmax−xvmin+xvmin yv
visually appealing, perspective
=(yw−ywmin)⋅ywmax−ywminyvmax−yvmin+yvmin
projections are not suitable for
engineering drawings because they do
not preserve true dimensions. 2c) Derive the viewing transformation matrix.
o Types of Perspective Projections:
Classified by the number of vanishing The viewing transformation, also known as the camera
points: transformation, transforms the world coordinates of an
 One-Point Perspective: One object into the camera's local coordinate system. This is an
set of parallel lines converges essential step before projection. The transformation is
to a single vanishing point. typically done by a rotation followed by a translation.
Used for viewing objects
straight on. 1. Define the Camera's Local Coordinate Axes:
 Two-Point Perspective: Two o z-axis (zcam): The view direction. This
sets of parallel lines converge is the unit vector pointing from the
to two different vanishing camera's position towards the "look
points. Used for viewing at" point.
objects from a corner. o x-axis (xcam): The "right" direction.
 Three-Point Perspective: This is a vector perpendicular to both
Three sets of parallel lines the view direction and the up vector.
converge to three different o y-axis (ycam): The new up direction.
vanishing points. Used for This is a vector perpendicular to both
viewing objects from above the view direction and the right
or below, giving a more direction.
dramatic or "bird's-eye" 2. Construct the Transformation Matrix: The
view. transformation from world coordinates (xw,yw
,zw) to camera coordinates (xcam,ycam,zcam)
2b) What are the basic transformation techniques used in involves two steps:
Window-to-Viewport Transformation? o Translation: Translate the origin of the
world coordinate system to the
Window-to-Viewport transformation is the process of camera's position.
mapping a rectangular area of the world coordinate 3. Rotation: Rotate the world coordinate axes to
system (the "window") to a rectangular area on a device align with the camera's axes. The rotation matrix
(the "viewport"). The basic transformations involved in R is constructed using the unit vectors of the
this process are: camera's axes as its rows.
4. Combine the Transformations: The final viewing
transformation matrix Mview is the product of
1. Translation: The first step is to translate the
the rotation and translation matrices: Mview
window so that its lower-left corner coincides
=R⋅T
This matrix transforms any point from world coordinates  Diagram 1: Initial State
to the camera's coordinate system, which is a crucial step o Draw a 3D Cartesian coordinate system
before projection and clipping. (x, y, z axes).
o Draw a line parallel to the x-axis at
2d) Explain why it is essential that clipping takes place y=y0 and z=z0. Label it "Rotation Axis".
before projection. o Draw a 3D object (e.g., a cube or a
cylinder) positioned in space, away
from the origin, ready to be rotated.
The statement that clipping takes place before projection
(specifically, perspective projection) is generally incorrect  Diagram 2: Translation to the Origin
for the standard graphics pipeline. Clipping is typically o Draw the same coordinate system.
performed after the perspective transformation but o An arrow indicates the translation of
before the final division by 'w'. This stage is known as clip the object along the y and z axes.
space. The correct order is: o The object is now drawn translated so
that the rotation axis lies on the x-axis
(i.e., at y=0 and z=0). This translation is
1. Modeling Transformation: Transforms object
represented by a matrix T(−y0,−z0).
coordinates to world coordinates.
2. Viewing Transformation: Transforms world
 Diagram 3: Rotation about the x-axis
coordinates to camera/view coordinates.
o Draw the coordinate system with the
object positioned as in the previous
3. Projection Transformation: Transforms camera
step.
coordinates to clip coordinates. This is where
perspective distortion is applied, but the division
o A curved arrow is drawn around the x-
axis, indicating the rotation.
by 'w' is not yet performed.
4. Clipping: The main reason for performing
o The object is shown in a rotated state.
This rotation is a standard 3D rotation
clipping at this stage (in clip space) is efficiency
about the x-axis by an angle θ. The
and accuracy.
matrix is Rx(θ).
o Efficiency:
5. Accuracy: After perspective transformation, lines  Diagram 4: Translation Back
that are parallel in world coordinates might no o Draw the coordinate system with the
longer be parallel. rotated object at the origin.
6. Perspective Division: After clipping, the o An arrow indicates the translation back
coordinates are divided by their w-component to to the original position.
obtain normalized device coordinates (NDC). o The object is shown in its final rotated
7. Viewport Transformation: Finally, the NDC are state, with the rotation axis returned
mapped to screen coordinates. to its original position at y=y0,z=z0.
This is represented by a translation
matrix T(y0,z0).
Therefore, clipping is a critical step that is optimally
performed in clip space, after the perspective
transformation but before the perspective division, for The final transformation matrix is the product of these
reasons of efficiency and accuracy. It ensures that only the three matrices: M=Tback⋅Rx(θ)⋅Torig.
visible parts of the scene are rendered, saving
computational resources and preventing rendering Solution to Question 4
artifacts.
4a) What are the steps involved in the Cohen-Sutherland
Question 3 algorithm for line clipping?

3c) Only with neat diagrams show the sequence of The Cohen-Sutherland algorithm is a very efficient and
transformations for rotating an object about an axis that popular line-clipping algorithm used to determine which
is parallel to the x-axis. parts of a line segment are visible within a rectangular
clipping window. The steps are as follows:
Rotating an object about an axis that is parallel to the x-
axis is a 3D transformation that requires a sequence of 1. Assign Region Codes (OutCodes):
three steps, similar to the 2D general pivot point rotation. o The clipping window divides the 2D
Let the rotation axis be a line defined by y=y0 and z=z0. plane into nine regions. Each region is
assigned a 4-bit code based on its
Diagrams: position relative to the clipping
window (top, bottom, right, left).
o The bits are assigned in the following  Canonical Viewing Space: Canonical viewing
order (from left to right): Top, Bottom, space (also known as normalized device
Right, Left. coordinates or NDC space) is a standardized,
o Bit 1 (Top): 1 if the point is above the device-independent coordinate system that a 3D
top edge (y>ymax), 0 otherwise. scene is transformed into before it is rendered to
o Bit 2 (Bottom): 1 if the point is below the screen. It is a cubic volume, typically defined
the bottom edge (y<ymin), 0 by the coordinates ranging from -1 to +1 on all
otherwise. three axes (x, y, and z).
o Bit 3 (Right): 1 if the point is to the  Sutherland-Hodgeman Algorithm for Polygon
right of the right edge (x>xmax), 0 Clipping: The Sutherland-Hodgeman algorithm is
otherwise. a method used to clip a polygon against a convex
o Bit 4 (Left): 1 if the point is to the left clipping polygon (in 2D) or a convex clipping
of the left edge (x<xmin), 0 otherwise. volume (in 3D, like the canonical cube). The
2. For a point (x,y), the code is determined by algorithm works by processing the polygon
comparing its coordinates to the window vertices against each clipping boundary in
boundaries. sequence.
3. Test the Line Segment:
o The algorithm checks the region codes
For clipping a polygon in canonical 3D space, the
of the two endpoints, P1 and P2.
algorithm clips the polygon against each of the
o Case 1: Trivial Acceptance: If the
six planes of the canonical view volume (x=-1,
region code for both endpoints is 0000
x=1, y=-1, y=1, z=-1, z=1). The process for each
(i.e., outcode1 == 0000 and outcode2
clipping plane is as follows:
== 0000), the entire line segment lies
within the clipping window. The line is
accepted and can be drawn. 1. Process a single boundary: Consider
o Case 2: Trivial Rejection: If the logical the polygon vertices one by one,
AND of the two region codes is non- moving from one vertex to the next.
zero (i.e., outcode1 & outcode2 != 2. Decision Rules for each edge: For an
0000), the entire line segment lies in edge from vertex v1 to v2, there are
one of the nine outer regions and is four possible cases:
completely outside the clipping 3. Iterative Clipping:
window.  Start with the original
4. Clipping (for Non-Trivial Cases): polygon vertices.
o If the line segment cannot be trivially  Clip this polygon against the
accepted or rejected, it intersects one first boundary (e.g., the left
or more of the clipping boundaries. plane, x=−1). The output is a
o An endpoint is chosen (e.g., the one new list of vertices for the
with a non-zero region code). clipped polygon.
o The algorithm determines which  Take this new list of vertices
boundary the line crosses based on the and use it as the input for
non-zero bit in its region code. clipping against the next
o The intersection point with that boundary (e.g., the right
boundary is calculated. plane, x=1).
o The portion of the line outside that  Repeat this process for all six
boundary is discarded, and the boundaries of the canonical
endpoint is replaced with the newly cube.
calculated intersection point.
o The new endpoint's region code is then 4c) Distinguish between Cohen-Sutherland and
recalculated. Sutherland-Hodgeman algorithms.
o The algorithm repeats steps 1 and 2
with the new, shorter line segment
until it can be either trivially accepted Sutherland-
Cohen-Sutherland
or rejected. Feature Hodgeman
Algorithm
Algorithm
4b) What is "canonical viewing space"? Describe in detail Primarily used for clipping Used for clipping
Purpose
the Sutherland-Hodgeman algorithm for clipping a line segments. polygons.
polygon to the view volume in this space. A single line segment with A polygon
Input
two endpoints. defined by an
Sutherland- The midpoint circle algorithm is an efficient method for
Cohen-Sutherland drawing a circle on a computer screen. For a circle
Feature Hodgeman
Algorithm centered at the origin, the first octant is from x=0 to x=y.
Algorithm
ordered list of
vertices. For a circle with radius r=10, we start at the initial point
(x0,y0)=(0,10).
A new polygon
A clipped line segment, or (or a set of
Output nothing if the line is polygons) The algorithm uses a decision parameter, pk, to determine
completely rejected. representing the whether the next pixel to be plotted should be (xk+1,yk) or
visible portion. (xk+1,yk−1).
Uses a 4-bit region code Clips the polygon
for each endpoint to against each The initial decision parameter is:p0=1−r=1−10=−9
Method perform a series of logical boundary of the
tests (AND, OR) for trivial clipping window Now, we will trace the algorithm step-by-step for the first
acceptance/rejection. sequentially. octant:
Can be less
efficient for Next
Very fast for trivial simple cases (like Curre Poin
acceptance and rejection a polygon fully New
nt Decision t
cases, which are common. inside the Ste Conditi New pk+1 Decision
Efficiency Point Paramet (xk+
Slower for lines that cross window) as it pk on Calculation Paramet
(xk,yk er pk 1
multiple boundaries due still needs to er pk+1
) ,yk+
to repetitive calculations. check every edge 1)
against every
(1,1 p0+2xk
boundary. 0 (0,10) p0=−9 pk<0 -6
0) +3=−9+2(0)+3
Can be slow for
(2,1 p1+2xk
Can be slow for complex polygons with a 1 (1,10) p1=−6 pk<0 -1
Performance 0) +3=−6+2(1)+3
scenes with many lines. large number of
vertices. (3,1 p2+2xk
2 (2,10) p2=−1 pk<0 6
0) +3=−1+2(2)+3
Requires care. It
can produce a p3+2(xk−yk
single, incorrect 3 (3,10) p3=6 pk≥0 (4,9) )+5=6+2(3−10 -3
Not an issue, as it )+5
Handling of polygon if a
operates on individual line
Concavity concave polygon p4+2xk
segments. 4 (4,9) p4=−3 pk<0 (5,9) 8
is clipped, as it +3=−3+2(4)+3
may create p5+2(xk−yk
unwanted edges. 5 (5,9) p5=8 pk≥0 (6,8) )+5=8+2(5−9) 5
More complex to +5
implement, p6+2(xk−yk
especially for 6 (6,8) p6=5 pk≥0 (7,7) )+5=5+2(6−8) 6
Conceptually simple for handling the four +5
Simplicity line segments. The region decision cases
Export to Sheets
coding system is intuitive. and correctly
generating the
output vertices We stop here because x≥y, and we have completed tracing
at each step. the pixels for the first octant. The points plotted are (0,
10), (1, 10), (2, 10), (3, 9), (4, 9), (5, 8), (6, 8), and (7, 7).

2019-Question 1: Question 2: Geometric Transformations

1.b) Given a circle radius r=10. Demonstrate the midpoint 2.a) Define Translation, Rotation and Scaling for two
circle drawing algorithm's determining position along the dimensional geometric transformations.
circle octant in the first quadrant from x=0 to x=y.
Geometric transformations are functions that change the
position, size, or orientation of an object in a coordinate
system.
1. Translation any point (x,y) after this translation become: xtrans=x−xp
ytrans=y−yp
Translation is the process of moving an object from one
location to another in a straight-line path without Step 2: Rotate the translated object about the origin.
changing its orientation or size. A translation is defined by Now that the pivot point is at the origin, we can apply the
a translation vector (tx,ty), where tx is the displacement in standard rotation matrix with the desired rotation angle
the x-direction and ty is the displacement in the y- θ.The new coordinates after rotation are: xrot=xtrans
direction. cosθ−ytranssinθ yrot=xtranssinθ+ytranscosθ

To translate a point P(x,y) to a new point P′(x′,y′), we use Substituting the translated coordinates: xrot=(x−xp
the following equations: x′=x+tx y′=y+ty )cosθ−(y−yp)sinθ yrot=(x−xp)sinθ+(y−yp)cosθ

In matrix form, this can be represented as:(x′y′)=(xy)+(txty) Step 3: Translate the rotated object back to its original
position. To complete the transformation, we translate
2. Rotation the rotated object back by a vector (xp,yp). This places the
pivot point back at its original location.The final
coordinates (x′,y′) are: x′=xrot+xp y′=yrot+yp
Rotation is the process of repositioning an object along a
circular path in the xy-plane. A rotation is defined by a
rotation angle θ and a rotation point (or pivot point). Substituting the rotation equations: x′=xp+(x−xp
)cosθ−(y−yp)sinθ y′=yp+(x−xp)sinθ+(y−yp)cosθ
To rotate a point P(x,y) to a new point P′(x′,y′) by an angle
θ counterclockwise around the origin, we use the 2.c) Explain how a shearing transformation can be used
following equations:x′=xcosθ−ysinθ y′=xsinθ+ycosθ to modify 3-dimensional object shapes.

In matrix form, this can be represented as:(x′y′)=(cosθsinθ Shearing is a transformation that distorts the shape of an
−sinθcosθ)(xy) object by "sliding" one or more of its faces along a given
direction. Unlike rotation or scaling, shearing does not
change the volume of the object. It can be performed
3. Scaling
along any axis, and in 3D, we can have shearing in the x, y,
or z directions, affecting the other two coordinates.
Scaling is the process of changing the size of an object.
This transformation can be used to either enlarge or shrink
A 3D shearing transformation changes the shape of a 3D
an object. It is defined by scaling factors sx and sy for the x
object by shifting a dimension's coordinate value by an
and y directions, respectively. Scaling is typically
amount proportional to the coordinate value of another
performed relative to the origin.
dimension.The transformation equations are:

To scale a point P(x,y) to a new point P′(x′,y′), we use the


$x' = x + sh_x_y \cdot y + sh_x_z \cdot z$ y′=y z′=z
following equations:x′=x⋅sx y′=y⋅sy In matrix form, this can
be represented as:(x′y′)=(sx00sy)(xy). If sx=sy, the scaling is
uniform (maintaining the object's proportions). If they are Here, shxy and shxz are the shear factors.
different, it is a non-uniform scaling (changing the object's
proportions).  shxy determines how much the x-coordinate
shifts as a function of y.
2.b) With neat diagrams, explain the general pivot-point  shxz determines how much the x-coordinate
rotation for two dimensional geometric transformations. shifts as a function of z.

When an object is rotated, it doesn't always rotate around In matrix form, a shear in the x-direction is represented as:
the origin. A pivot point is an arbitrary point (xp,yp) about
which the rotation occurs. To perform a rotation around a x′y′z′=100shxy10shxz01xyz
pivot point, we need to follow a three-step process:
Similarly, we can have a shear in the Y-direction with
Step 1: Translate the object so that the pivot point moves shear factors shyx and shyz: x′=x y′=y+shyx⋅x+shyz⋅z z′=z
to the origin. We translate the object by a vector (−xp,−yp
). This brings the pivot point to the origin, allowing us to
And a shear in the Z-direction with shear factors shzx and
use the standard rotation matrix.The new coordinates for
shzy: x′=x y′=y z′=z+shzx⋅x+shzy⋅y
3.b) Explain the process of window-to-viewport
coordinate transformation.
Question 3: Viewing Transformation and Clipping
The window-to-viewport transformation is a two-
3.a) Define 'window' and 'viewport' in 2-dimensional dimensional mapping that converts the world coordinates
viewing. of a scene within a specified window to the screen
coordinates of a designated viewport. This process ensures
that the selected part of the scene is correctly scaled and
In computer graphics, the concepts of 'window' and
positioned on the display.
'viewport' are fundamental to the process of displaying a
portion of a larger scene on a limited display area. They
define the mapping from the world coordinate system to The transformation is a composite of three steps:
the screen coordinate system.
1. Translate the window so its lower-left corner
1. Window coincides with the origin of the world coordinate
system.
2. Scale the translated window to match the size of
A window is a rectangular area in the world coordinate
the viewport.
system that defines the portion of the scene that is to be
3. Translate the scaled window to the location of
displayed. The world coordinate system is the application's
the viewport on the screen.
own coordinate system, where the objects in the scene are
defined. The window essentially acts as a clipping
boundary, defining what is "seen" by the virtual camera. Let's break down the mathematical process.

 Coordinates: The window is defined by its  Window coordinates: (xw,yw)


boundaries: (x_w_min, y_w_min) for the  Window boundaries: (xwmin,ywmin),(xwmax
bottom-left corner and (x_w_max, y_w_max) for ,ywmax)
the top-right corner.  Viewport coordinates: (xv,yv)
 Purpose: To select a specific area of the scene  Viewport boundaries: (xvmin,yvmin),(xvmax
for viewing. Any part of the scene that falls ,yvmax)
outside of this window is not displayed.
 Analogy: Think of the window as the opening of The transformation is a linear mapping, and the final
a camera lens. It determines the part of the real viewport coordinates (xv,yv) can be calculated directly
world that the camera captures. using the following formulas:

2. Viewport First, we calculate the scaling factors for both axes.

A viewport is a rectangular area on the display device  The width ratio: sx=xwmax−xwminxvmax−xvmin
(screen) where the contents of the window will be drawn.
 The height ratio: sy=ywmax−ywminyvmax−yvmin
The display device has its own coordinate system, often
with the origin at the top-left corner and coordinates
increasing downwards and to the right. Then, we apply the scaling and translation to transform
any point (xw,yw) from the window to its corresponding
point (xv,yv) in the viewport.
 Coordinates: The viewport is defined by its
boundaries: (x_v_min, y_v_min) for the bottom-
xv=xvmin+(xw−xwmin)⋅xwmax−xwminxvmax−xvmin
left corner and (x_v_max, y_v_max) for the top-
right corner.
 Purpose: To specify where on the screen the yv=yvmin+(yw−ywmin)⋅ywmax−ywminyvmax−yvmin
selected part of the scene (the window) will be
rendered. 3.c) Illustrate and explain the Weiler-Atherton polygon
 Analogy: Think of the viewport as the frame on clipping algorithm.
the screen where the final image is projected. It
can be a full-screen view or a smaller sub-region. The Weiler-Atherton polygon clipping algorithm is an
algorithm used to clip an arbitrary polygon against a
convex or non-convex clipping polygon. It is an extension
of the Sutherland-Hodgman algorithm and is notable for
its ability to correctly handle cases where the clipped
polygon's output is not a single polygon, but multiple, control points. Moving a single control
separate polygons. point will affect the curve's shape in
the immediate vicinity of that point.
The Algorithm Rules:
2. Approximation Splines
1. Start at the first vertex of the subject polygon
that is either inside the clipping polygon or at an An approximation spline is a curve that does not
intersection point. necessarily pass through any of its control points, except
2. Move along the subject polygon's boundary. possibly the first and last. The control points in this case
o If a vertex is inside the clipping act as a guide, pulling the curve toward them to
polygon, add it to the output list. "approximate" the overall shape.
o If a vertex is outside, and the line
segment from the previous vertex
 Characteristics:
crosses into the clipping polygon, an o The curve approximates the shape
intersection point is found. defined by the control points.
3. If a vertex is outside, and the line segment from
o The shape of the curve is less sensitive
the previous vertex crosses out of the clipping to the movement of a single control
polygon, an intersection point is found.
point, which can be useful for creating
4. Move along the clipping polygon's boundary. more fluid, intuitive shapes.
o If you are currently tracing the clipping o It is often used to smooth out data that
polygon and reach an intersection may contain noise.
point where the subject polygon's
boundary re-enters the clipping
polygon, add this intersection point to 4.b) What are the parametric continuity conditions to
the output list and switch back to ensure a smooth transition from one section of a precise
tracing the subject polygon. parametric curve to the next?
o If you reach an intersection point
where the subject polygon's boundary Parametric continuity is a condition that describes the
exits the clipping polygon, continue smoothness of a curve at the point where two segments
tracing the clipping polygon's are joined. A higher degree of continuity results in a
boundary. smoother, more visually pleasing curve. The main types of
parametric continuity are:

1. Zeroth-order Parametric Continuity (C0)


Question 4: Splines and Curve Continuity
 Condition: The end point of one curve segment
4.a) Define 'interpolation' and 'approximation' splines. must coincide with the start point of the next
segment.
Splines are flexible curves used in computer graphics and  Explanation: This is the most basic level of
other fields to create smooth, complex shapes. They are continuity. It ensures that the curve is
defined by a set of control points. The two main types of continuous and has no gaps or breaks, but it
splines are interpolation splines and approximation does not guarantee a smooth transition. The
splines. curve may have a sharp corner or a kink at the
joint.
1. Interpolation Splines
 Example: A piecewise linear function has C0
continuity at its joints.

An interpolation spline is a curve that is constructed to


2. First-order Parametric Continuity (C1)
pass directly through all of its given control points. The
term "interpolate" means that the curve connects or links
all the data points.  Condition: The first derivatives (tangent vectors)
of the curve segments must be equal at the joint.
 Characteristics:  Explanation: This ensures that both the position
o The curve is guaranteed to pass and the direction of the curve are continuous at
through every specified point. the joint. The curve is "tangent-continuous,"
o The shape of the curve is highly meaning it has no sharp corners. The curve flows
dependent on the location of the
smoothly from one segment to the next, as if it  At u=0, the curve starts at P1 and has a tangent
were a single, continuous line. vector equal to T1.
 Example: A Bezier curve is often designed to  At u=1, the curve ends at P4 and has a tangent
have C1 continuity at its joints. vector equal to T4.

3. Second-order Parametric Continuity (C2) How it works:

 Condition: The second derivatives of the curve  Each basis function acts as a weight, determining
segments must be equal at the joint. how much influence each control point or
 Explanation: This ensures that both the tangent tangent vector has on the final curve shape.
and the curvature are continuous. The rate of  As the parameter u varies from 0 to 1, the curve
change of the tangent vector is the same for is smoothly drawn from P1 to P4.
both segments at the joint. This results in an  The Hermite interpolation is a local control
extremely smooth curve with no abrupt changes method. Changing a point or tangent vector on
in curvature, giving it a very polished one segment only affects that segment, not the
appearance. entire curve.
 Example: B-spline curves typically provide C2
continuity, making them ideal for creating very 2015-Answering Question 1
smooth, flowing shapes.

Part B: Midpoint Circle Algorithm


4.c) State and explain the Hermite interpolation.

The midpoint circle algorithm is an efficient way to draw a


Hermite interpolation is a method for constructing a
circle on a raster display by only calculating points for one
smooth curve segment that is defined not only by its two
octant (one-eighth) of the circle. The points for the other
endpoints but also by the tangent vectors at those
seven octants can be found through symmetry.
endpoints. It is a powerful technique because it allows for
direct control over the shape and slope of the curve at its
beginning and end, thereby guaranteeing C1 continuity. Let's demonstrate this for a circle with radius r=10. The
initial point for the first octant is (0,r), which is (0,10). We
will calculate points until x is equal to y.
Statement: The Hermite interpolation curve, for a single
segment, is defined by two endpoints, P1 and P4, and their
corresponding tangent vectors, T1 and T4. The curve is a 1. Initialize:
polynomial function of a parameter u, typically ranging o Initial point: (x0,y0)=(0,10)
from 0 to 1, where u=0 corresponds to the starting point o Initial decision parameter: p0
P1 and u=1 corresponds to the ending point P4. =1−r=1−10=−9
2. Iterate: We will step through the x-values and
update the coordinates and decision parameter
Explanation: The Hermite curve is a cubic polynomial
based on the following rules:
curve defined by a set of basis functions. The general
equation for a point P(u) on the curve is:
o If pk<0, the next point is (xk+1,yk). The
new decision parameter is pk+1=pk
+2xk+3.
P(u)=H1(u)P1+H2(u)T1+H3(u)P4+H4(u)T4 o If pk≥0, the next point is (xk+1,yk+1).
The new decision parameter is pk+1
Here, H1,H2,H3, and H4 are the Hermite basis functions. =pk+2xk−2yk+5.
They are cubic polynomials in u:
Let's apply these rules in a table format:
 H1(u)=2u3−3u2+1
 H2(u)=u3−2u2+u Next Point
 H3(u)=−2u3+3u2 Point
k pk (xk+1,yk+1 2xk 2yk pk+1 Calculation pk+1
 H4(u)=u3−u2 (xk,yk)
)

The basis functions are designed to ensure that the curve 0 -9 (0, 10) (1, 10) 0 20 p0+2x0+3=−9+0+3 -6
satisfies the following conditions:

1 -6 (1, 10) (2, 10) 2 20 p1+2x1+3=−6+2+3 -1


Next Point In 2D computer graphics, differential scaling uses separate
Point scaling factors, Sx and Sy, for the x and y axes. The new
k pk (xk+1,yk+1 2xk 2yk pk+1 Calculation pk+1
(xk,yk) coordinates (x′,y′) are calculated from the original
)
coordinates (x,y) as:x′=x⋅Sx y′=y⋅SyIf Sx =Sy, the object will
be stretched or compressed along one axis, leading to a
2 -1 (2, 10) (3, 10) 4 20 p2+2x2+3=−1+4+3 6 distorted or "skewed" appearance. This is a common
technique for creating visual effects and for fitting objects
p3+2x3−2y3 into specific spaces.
3 6 (3, 10) (4, 9) 6 20 -3
+5=6+6−20+5
2.c. What is Shear as a 2D Geometric Transformation?
4 -3 (4, 9) (5, 9) 8 18 p4+2x4+3=−3+8+3 8
Shearing is a 2D geometric transformation that distorts
the shape of an object by shifting its coordinates in a
p5+2x5−2y5
5 8 (5, 9) (6, 8) 10 18 5 specific direction. It gives the object a slanted or "skewed"
+5=8+10−18+5
look, similar to what happens when you push the top of a
deck of cards sideways. An important property of shearing
p6+2x6−2y6 is that it preserves the area of the object.
6 5 (6, 8) (7, 7) 12 16 6
+5=5+12−16+5
There are two main types of 2D shearing:

The algorithm stops when the x-coordinate becomes  X-shear: The x-coordinates are shifted based on
greater than the y-coordinate. So the pixels for the first their y-coordinates. The y-coordinates remain
octant of a circle with a radius of 10 are: unchanged. x′=x+shx⋅y y′=y
 Y-shear: The y-coordinates are shifted based on
(0, 10), (1, 10), (2, 10), (3, 10), (4, 9), (5, 9), (6, 8), (7, 7) their x-coordinates. The x-coordinates remain
unchanged. x′=x y′=y+shy⋅x
2.a. What is a Translation Vector?
Shearing is used in computer graphics for effects like giving
In computer graphics, a translation vector is a an object a sense of motion or for creating certain artistic
mathematical tool used to move or "slide" an object from distortions.
one position to another without changing its size, shape,
or orientation. It is represented as a vector, typically a pair 3.a. Calculate the rotation of a point P(6,4) by an angle of
of values (tx,ty) in 2D space, which specifies the distance 30∘ counterclockwise.
and direction of the movement along the x and y axes.
To rotate a point P(x,y) by an angle θ counterclockwise
For a point with original coordinates (x,y), the new around the origin, we use the following rotation formulas:
translated coordinates (x′,y′) are calculated as:
x′=xcosθ−ysinθ y′=xsinθ+ycosθ
x′=x+tx y′=y+ty
Given:
Translation vectors are a fundamental part of 2D and 3D
transformations, allowing for the precise placement of  P(x,y)=(6,4)
objects in a scene, and are used extensively in animation
 θ=30∘
and modeling.

First, we need the values of sin30∘ and cos30∘:


2.b. What is Differential Scaling?

Differential scaling (or non-uniform scaling) is a type of  cos30∘=23≈0.866


geometric transformation that changes the size of an  sin30∘=21=0.5
object unequally along different axes. This is in contrast to
uniform scaling, where the size is changed by the same Now, substitute these values into the rotation formulas:
factor in all directions, thus preserving the object's
proportions.
 x′=6⋅(cos30∘)−4⋅(sin30∘) x′=6⋅23−4⋅21 x′=33−2
x′≈3⋅0.866−2=2.598−2=0.598
 y′=6⋅(sin30∘)+4⋅(cos30∘) y′=6⋅21+4⋅23 y′=3+23 1. Rotation Matrix (R): For a counterclockwise
y′≈3+2⋅0.866=3+1.732=4.732 rotation of an angle θ, the matrix is: R=cosθsinθ0
−sinθcosθ0001
So, the new rotated coordinates are approximately (0.598,
4.732). Given θ=45∘:

3.b. Find the reflection of a point P(2,5) about the line o cos45∘=21
y=−x. o sin45∘=21

The reflection of a point (x,y) about the line y=−x swaps R=21210−21210001
the coordinates and negates them. The formula for this
transformation is: 2. Scaling Matrix (S): For scaling with factors Sx and
Sy, the matrix is: S=Sx000Sy0001
x′=−y y′=−x
Given Sx=2 and Sy=3: S=200030001
Given the point P(2,5):
3. Concatenated Transformation Matrix (MTotal):
 x′=−5 The order of multiplication is MTotal=S⋅R.
 y′=−2 MTotal=20003000121210−21210001

The reflected point is P′(−5,−2). MTotal=2⋅21+0⋅21+00⋅21+3⋅21+002⋅(−21)+0⋅21


+00⋅(−21)+3⋅21+00001

3.c. Find the reflected position of a triangle with vertices


A(1,1), B(5,1), C(1,4) about the x-axis. MTotal=22230−22230001

Which simplifies to: MTotal=2230−2230001


When a point is reflected about the x-axis, its x-coordinate
remains the same, and its y-coordinate is negated. The
transformation rule is: 4.b. Explain the Homogeneous Coordinate System.

x′=x y′=−y The homogeneous coordinate system is a method used in


computer graphics to represent geometric
Let's apply this rule to each vertex of the triangle: transformations (like translation, rotation, and scaling) as a
single matrix multiplication. While standard 2D Cartesian
coordinates work well for scaling and rotation, translation
 Vertex A(1, 1): requires an addition operation, which cannot be
o A′(x′,y′)=(1,−1) represented by a simple 2x2 matrix multiplication.
 Vertex B(5, 1):
o B′(x′,y′)=(5,−1) By adding a third dimension (the "homogeneous
 Vertex C(1, 4): coordinate," usually denoted by w or h) to a 2D point, we
o C′(x′,y′)=(1,−4) can represent all affine transformations as a single matrix
multiplication.
The reflected positions of the triangle's vertices are
A′(1,−1), B′(5,−1), and C′(1,−4).  A 2D point (x,y) is represented in homogeneous
coordinates as (xh,yh,w), where the original
4.a. Find the concatenated transformation matrix for a coordinates are x=xh/w and y=yh/w.
triangle that undergoes the following sequence of  For simplicity, we typically set the homogeneous
transformations: a) a rotation of 45∘ counterclockwise, coordinate to 1, so a point (x,y) becomes (x,y,1).
and b) a scaling with Sx=2 and Sy=3.
2020-Question 2
The concatenated transformation matrix is the product of
the individual transformation matrices. The order of
2. (a) Given points P1(1,2,0), P2(3,6,20), and P3(2,4,6) and
multiplication is crucial: the transformations are applied in
a view point C(0,0,-10), determine which points obscure
reverse order from how they appear in the problem
the others when viewed from C.
statement.
To determine which points obscure others from a  Is CP3=k⋅CP1? (2,4,16)=k(1,2,10)
viewpoint C, we can use a depth-based approach. The o k=2/1=2
point that is "closer" to the viewpoint along the line of o k=4/2=2
sight will obscure the point that is "further away." o k=16/10=1.6 Since k is not consistent,
the points C, P1, and P3 are not
We are given: collinear.

 Viewpoint C=(0,0,−10) Final Answer: Since C, P1, and P2 are collinear, and P1 is
closer to C (d12=105) than P2 (d22=945), point P1
 Point P1=(1,2,0)
obscures point P2 when viewed from C. Point P3 is not on
 Point P2=(3,6,20)
the same line of sight as P1 or P2, so it does not obscure
 Point P3=(2,4,6) them.

The squared distance from a point P=(x,y,z) to the 2. (b) What is the maximum number of objects that can
viewpoint C=(xc,yc,zc) is given by: d2=(x−xc)2+(y−yc be presented by using Z-buffer algorithm?
)2+(z−zc)2
The Z-buffer algorithm (also known as the depth-buffer
Let's calculate the squared distances for each point from C: algorithm) is a technique used in computer graphics to
manage image depth coordinates in 3D space, generally to
 Distance of P1 from C: d12 render objects on a 2D screen. It resolves the visibility of
=(1−0)2+(2−0)2+(0−(−10))2 d12 multiple overlapping objects by storing a depth value for
=12+22+102=1+4+100=105 each pixel in a separate buffer (the Z-buffer) alongside the
 Distance of P2 from C: d22 color buffer.
=(3−0)2+(6−0)2+(20−(−10))2 d22
=32+62+302=9+36+900=945 The maximum number of objects that can be presented
 Distance of P3 from C: d32 using the Z-buffer algorithm is theoretically infinite.
=(2−0)2+(4−0)2+(6−(−10))2 d32
=22+42+162=4+16+256=276 2. (c) The matrix (1 b a 1) defines a transformation called
a simultaneous shearing or shearing for short. The special
Comparing the squared distances: case when b=0 is called shearing in the x-direction. When
a=0, we have shearing in the y-direction. Illustrate the
effect of shearing transformations on the square A(0,0),
 d12=105
B(1,0), C(1,1), and D(0,1) when a=2 and b=3.
 d22=945
 d32=276
The transformation matrix is given by M=(1ba1). The
transformation of a point (x,y) is given by: (x′y′)=(1ba1)(xy
Sorting them in increasing order: 105<276<945. This )=(x+aybx+y)
means P1 is the closest point to C, followed by P3, and
then P2 is the farthest.
We are given the square with vertices:

 P1 is the closest.
 A = (0, 0)
 P3 is the second closest.
 B = (1, 0)
 P2 is the farthest.
 C = (1, 1)
 D = (0, 1)
 CP1=(1−0,2−0,0−(−10))=(1,2,10)
 CP2=(3−0,6−0,20−(−10))=(3,6,30) We need to illustrate the effect for two separate cases:
 CP3=(2−0,4−0,6−(−10))=(2,4,16)
1. Case 1: Shear in the x-direction (b=0) with a=2.
Let's check for scalar multiples: The transformation matrix is Mx=(1021). The
new coordinates are:
 Is CP2=k⋅CP1? (3,6,30)=k(1,2,10) o x′=x+2y
o k=3/1=3 o y′=y Let's find the new coordinates for
o k=6/2=3 each vertex:
o k=30/10=3 Since k=3 is consistent, the o A′=(0+2(0),0)=(0,0)
points C, P1, and P2 are collinear. o B′=(1+2(0),0)=(1,0)
o C′=(1+2(1),1)=(3,1)  ymin and ymax for the vertical boundaries.
o D′=(0+2(1),1)=(2,1) The new shape is a
parallelogram with vertices A'(0,0), A point P(x,y) is inside the clipping window if the following
B'(1,0), C'(3,1), and D'(2,1). The base two conditions are met:
remains on the x-axis, and the top is
shifted horizontally.
2. Case 2: Shear in the y-direction (a=0) with b=3. 1. xmin≤x≤xmax
The transformation matrix is My=(1301). The 2. ymin≤y≤ymax
new coordinates are:
o x′=x If either of these conditions is not met, the point is outside
o y′=3x+y Let's find the new coordinates the window and is clipped (i.e., not drawn).
for each vertex:
o A′=(0,3(0)+0)=(0,0) 3. (b) Define clipping and clip window.
o B′=(1,3(1)+0)=(1,3)
o C′=(1,3(1)+1)=(1,4)
Clipping: Clipping is the process of removing parts of a
o D′=(0,3(0)+1)=(0,1) The new shape is a
scene, objects, or primitives (like points, lines, or polygons)
parallelogram with vertices A'(0,0),
that lie outside a designated area. This area is known as
B'(1,3), C'(1,4), and D'(0,1). The side on
the clipping window or clipping region. In computer
the y-axis remains vertical, and the
graphics, clipping is a fundamental operation performed
other vertical side is shifted.
before rendering to ensure that only the visible parts of an
image are processed and displayed, which can save
Since the question asks to illustrate the effect when a=2 computation time and memory.
and b=3 simultaneously, we need to apply the full
transformation matrix: Mshear=(1321) The transformation
Clip Window: A clip window, also called a clipping
is given by:
rectangle or viewing window, is a rectangular or polygonal
area in the 2D or 3D world space that defines the region of
 x′=x+2y interest for rendering. Any graphical element that falls
 y′=3x+y partially or entirely outside this window is either partially
or completely removed (clipped). The clip window acts as
Now, let's find the new coordinates for the vertices of the a boundary that determines what parts of the scene are
square: visible to the user.

3. (c) State and explain the Cohen-Sutherland line


 Vertex A(0,0): xA′=0+2(0)=0 yA′=3(0)+0=0
clipping procedure.
A′=(0,0)
 Vertex B(1,0): xB′=1+2(0)=1 yB′=3(1)+0=3
B′=(1,3) The Cohen-Sutherland algorithm is a widely used and
efficient line-clipping algorithm that divides the 2D plane
 Vertex C(1,1): xC′=1+2(1)=3 yC′=3(1)+1=4
into nine regions, with the clipping window at the center.
C′=(3,4)
It quickly determines whether a line segment is completely
 Vertex D(0,1): xD′=0+2(1)=2 yD′=3(0)+1=1
visible, completely invisible, or partially visible.
D′=(2,1)

The algorithm assigns a 4-bit region code (or outcode) to


Solution to Question 3
each endpoint of a line segment. This code represents the
endpoint's location relative to the clipping window's four
3. (a) What is the condition for point clipping? boundaries. The bits are arranged as follows:

Point clipping is the simplest form of clipping in computer Bit Position Condition
graphics. It determines whether a given point is inside or
outside a defined clipping window. The condition for point Bit 1 (Left) 1 if x<xmin
clipping is straightforward: a point is considered inside the Bit 2 (Right) 1 if x>xmax
clipping window and should be displayed if and only if its Bit 3 (Bottom) 1 if y<ymin
coordinates fall within the boundaries of the window.
Bit 4 (Top) 1 if y>ymax
Export to Sheets
Let the clipping window be defined by the coordinates:

 xmin and xmax for the horizontal boundaries.


The region code is calculated for each endpoint, and then The shape of the torus can vary based on the relationship
these codes are used to make clipping decisions based on between its radii:
three simple cases:
 If R>r, the torus is the familiar ring shape.
1. Trivial Acceptance:  If R<r, the torus self-intersects, creating a
"spindle torus."
 If the region codes for both endpoints of the line  If R=r, the torus touches itself at the central axis,
segment are both 0000, it means both endpoints forming a "horn torus."
are inside the clipping window.
 In this case, the entire line segment is Tori are fundamental objects in 3D computer graphics and
completely inside the window, so it is trivially are often used for modeling:
accepted and can be drawn.
 Mechanical parts like washers, O-rings, or bolts.
2. Trivial Rejection:
 Architectural elements such as pillars or
decorative rings.
 If the result of a bitwise AND operation on the  Other objects that have a circular, ring-like
two endpoint region codes is not 0000, it means structure.
that both endpoints share at least one boundary
on the same side of the window (e.g., both are In a 3D modeling context, a torus can be represented
to the left of the left boundary). parametrically, which makes it easy to generate the
 In this case, the entire line segment lies surface using two angles. A common parametric
completely outside the clipping window. It is representation is:
trivially rejected and discarded.

 x(u,v)=(R+rcosv)cosu
3. Need for Clipping:
 y(u,v)=(R+rcosv)sinu
 z(u,v)=rsinv where u and v are parameters that
 If neither trivial acceptance nor trivial rejection is range from 0 to 2π.
possible, the line segment is partially inside and
partially outside the clipping window.
4. (b) Define "Convex hull" and "Control graph" for
 In this case, the algorithm must perform an specifying a spline curve.
intersection calculation. The intersection point
of the line with one of the clipping boundaries is
calculated, and the endpoint that lies outside the Convex Hull: The convex hull of a set of points is the
window is replaced with this new intersection smallest convex polygon or polyhedron that contains all of
point. the points. In the context of spline curves, the control
points of the curve (the points that define its shape) form
a set of points whose convex hull provides a useful
Solution to Question 4
geometric property. It is very helpful in computer graphics
for several reasons:
4(a) In 3D object representations what do you
understand by "Torus"?
 Bounding: The convex hull provides a simple
bounding volume for the curve, which can be
A Torus is a 3D geometric shape defined by a surface of used for quick clipping tests. If the convex hull is
revolution. It is formed by rotating a circle around an axis outside the viewing volume, the entire curve can
that is coplanar with the circle but does not pass through be clipped without further calculation.
the circle's center. The shape resembles a donut or an  Approximation: It gives a rough visual
inner tube. approximation of the curve's shape before
detailed rendering.
A torus is defined by two radii:  Control: It helps users intuitively understand the
range of influence of the control points. Moving
 Major radius (R): The distance from the center a control point will only affect the curve within
of the hole to the center of the tube. the hull, making it predictable.
 Minor radius (r): The radius of the circular cross-
section of the tube itself. Control Graph: A control graph, also known as a control
polygon, is a set of connected line segments formed by
the control points of a spline curve. The control points are Pk−1,Pk,Pk+1,Pk+2. The polynomial can be expressed using
the anchor points that determine the shape of the curve, a matrix form: P(t)=T⋅MCardinal⋅G where:
but the curve itself does not necessarily pass through
them (except for the first and last points in a Bezier curve).
 T=(t3t2t1)
It provides a skeleton or a cage that guides the shape of
the spline.
 G=Pk−1PkPk+1Pk+2 (the geometry vector)
 MCardinal=21−(1−τ)2(1−τ)−(1−τ)02−ττ−302
τ−23−τ1−τ01−τ−(1−τ)00
 Bezier Curves: The control graph for a Bezier
curve is a simple polygon connecting the control
2023-Question 1: Solution
points in order.
 B-Splines: For B-splines, the control graph can be
a more complex structure, but it still connects 1. (a) What do you mean by Interactive Computer
the control points in sequence. Graphics? What are the applications of computer
graphics?
The control graph is crucial for interactive design and
editing of spline curves. Interactive Computer Graphics refers to a field of
computer graphics that allows users to directly manipulate
or control images on a computer screen in real time. This
4. (c) State and explain the "Cardinal splines" as a
manipulation is typically achieved through input devices
method for interpolating piecewise cubics.
like a mouse, keyboard, joystick, or a touchscreen. The
system provides immediate feedback to the user's actions,
Cardinal Splines are a type of interpolating spline that uses creating a dynamic and engaging experience. A classic
a single tension parameter to control the tightness of the example is a video game, where the player's movements
curve. The term "interpolating" means that the curve are instantly reflected in the character's actions on screen.
passes directly through each of the given control points,
unlike approximating splines like Bezier or B-splines, which The applications of computer graphics are vast and can be
are influenced by but do not necessarily pass through their found in nearly every industry. Here are some of the most
control points. Cardinal splines are a method for creating a prominent examples:
smooth, continuous curve from a set of data points.

Properties and Explanation:


 Entertainment: Video games, animated movies
(like those from Pixar or Disney), and special
effects in films (e.g., CGI characters, explosions,
 Interpolating: The defining characteristic of a and environments).
Cardinal spline is that it passes through every  Design and Simulation: Computer-Aided Design
control point Pi. (CAD) for engineering and architecture, virtual
 Piecewise Cubic: The curve is a collection of reality (VR) and augmented reality (AR) for
cubic polynomial segments. Each segment training and visualization, and flight simulators
connects two adjacent control points, and its for pilot training.
shape is defined by its endpoints and the two  Scientific Visualization: Creating visual
surrounding control points (one on either side). representations of complex data sets in fields
 Tension Parameter (τ): Cardinal splines are like meteorology, medicine (MRI and CT scans),
defined by a tension parameter, τ, which and astronomy.
controls how tightly the curve follows the  Education: Interactive learning software,
control points. simulations of physical phenomena, and creating
 Tangents: The tension parameter effectively digital models of historical artifacts.
controls the magnitude of the tangent vectors at  Business and Marketing: Advertising, data
each control point, which in turn dictates the visualization (charts and graphs), and creating
shape of the curve between the points. The product prototypes.
tangent vector at a point Pk is proportional to
 User Interfaces: The graphical user interfaces
the vector from the previous point Pk−1 to the (GUIs) of nearly all modern operating systems
next point Pk+1. (like Windows, macOS, and Android) are a
o Tangent at Pk: Tk=21−τ(Pk+1−Pk−1) fundamental application of computer graphics.

Mathematical Formulation: A single segment of a Cardinal 1. (b) Differentiate between raster and random scan
spline between two points Pk and Pk+1 is defined by a displays. What do you mean by scan conversion?
cubic polynomial. The segment is defined by four points:
Raster vs. Random Scan Displays A frame buffer is the portion of video memory that holds
the information for every pixel on the screen.
Raster Scan Random Scan
Feature Formula: Frame Buffer Size (in bytes) = (Horizontal Pixels *
Display (Vector) Display
Vertical Pixels * Bits per Pixel) / 8
Draws an image Draws an image by
by scanning the moving the electron
Drawing entire screen line beam directly Part (i): Frame buffer size for 12 bits per pixel
Method by line, from top between the
to bottom, like a endpoints of each line 1. System 1 (640 x 480): (640 * 480 * 12) / 8 =
television. segment in the image. 368,640 bytes
A grid of pixels (a 2. System 2 (1280 x 1024): (1280 * 1024 * 12) / 8 =
bitmap). The A set of line-drawing 1,966,080 bytes
Image 3. System 3 (2560 x 2048): (2560 * 2048 * 12) / 8 =
image's resolution commands and their
Representation 7,864,320 bytes
is fixed by the coordinates.
number of pixels.
Can display Part (ii): Storage required for 24 bits per pixel
realistic images Produces sharp, clean
Image Quality with solid colors lines and is excellent 24 bits per pixel is equivalent to 3 bytes per pixel (since 24
and complex for line drawings. bits / 8 bits per byte = 3 bytes).
shapes.
Requires a large 1. System 1 (640 x 480): (640 * 480 * 24) / 8 =
Requires a display list
frame buffer 921,600 bytes
or refresh buffer to
(video memory) 2. System 2 (1280 x 1024): (1280 * 1024 * 24) / 8 =
Memory store the drawing
to store the color 3,932,160 bytes
commands for each
of every pixel on 3. System 3 (2560 x 2048): (2560 * 2048 * 24) / 8 =
line.
the screen. 15,728,640 bytes
Refreshes the
screen by Refreshes the screen Question 2: Solution
Refresh
continuously by redrawing each
Method
scanning the line in the display list. 2. (a) What is the basic concept of line drawing? Explain
entire pixel grid. DDA Line Drawing Algorithm with example.
Obsolete for general
use but was The basic concept of line drawing in computer graphics is
Used in most
historically used in to determine the optimal set of pixels to turn on between
modern displays,
early graphics two given endpoints, (x1,y1) and (x2,y2), to create a
including TVs,
Primary Use terminals and still has straight line. Since the pixels on a screen form a discrete
computer
niche applications in grid, an algorithm is needed to approximate a continuous
monitors, and
some laser light shows line. The goal is to select the pixels that are closest to the
smartphones.
and specialized ideal line to minimize jagged or stair-step effects. The
oscilloscopes. output of the algorithm is a series of integer coordinates
(x,y) that represent the pixels to be illuminated on the
Scan Conversion is the process of converting a geometric display.
object's description (like a line, circle, or polygon) into the
format required by a raster display. This involves Digital Differential Analyzer (DDA) Line Drawing
determining which pixels on the screen should be Algorithm
illuminated to represent the object. For example, to draw
a line, the scan conversion algorithm calculates the precise
The DDA algorithm is one of the simplest and oldest line-
coordinates of the pixels that lie along the line segment
drawing algorithms. It works by incrementally calculating
and then sets their color values in the frame buffer.
the pixel coordinates along the line. It avoids complex
multiplication by using floating-point arithmetic to find the
1. (c) Consider three different raster system with next pixel's position based on the slope of the line.
resolutions of 640 x 480, 1280 x 1024, and 2560 x 2048. (i)
What size is frame buffer (in bytes) for each of these
The Algorithm Steps:
systems to store 12 bits per pixel? (ii) How much storage
(in bytes) is required for each system if 24 bits per pixel
are to be stored?
1. Read the two endpoints of the line: P1(x1,y1) Current Rounded Rounded Plotted
and P2(x2,y2). Step Current y
x x y Pixel
2. Calculate the differences in x and y:
5 14+1=15 22+0.5=22.5 15 23 (15, 23)
o dx=x2−x1
o dy=y2−y1 6 15+1=16 22.5+0.5=23 16 23 (16, 23)
3. Determine the number of steps or iterations.
This is the larger of the absolute values of dx and The DDA algorithm plots the pixels (10, 20), (11, 21), (12,
dy. 21), (13, 22), (14, 22), (15, 23), and (16, 23).
o steps = max(|dx|, |dy|)
4. Calculate the increment values for x and y.
2. (b) Compare and contrast DDA and Bresenham’s line
These represent the amount to add to the
drawing algorithms.
current x and y values at each step.
o xincrement=dx/steps
o yincrement=dy/steps Bresenham's
Feature DDA Algorithm
5. Initialize the starting coordinates: Algorithm
o x=x1 Uses floating-point Uses only integer
o y=y1 arithmetic arithmetic (addition,
6. Plot the first point: Plot the pixel at (multiplication and subtraction, and bit
(round(x),round(y)). The round() function is used Calculation Type
division) to shifting). Avoids
because the coordinates are floating-point calculate the next floating-point
values and need to be converted to integers for point. operations.
pixel plotting.
Slower due to the
7. Loop for steps iterations:
use of floating-
o Update the current x and y
point operations, Much faster as it
coordinates:
which are relies on simple
 x=x+xincrement Speed
computationally integer additions
 y=y+yincrement more expensive and subtractions.
o Plot the next pixel: Plot the pixel at
than integer
(round(x),round(y)).
operations.
Results in rounding
Example of DDA Algorithm: More precise and
errors from
accurate because it
floating-point
Draw a line from P1(10,20) to P2(16,23). makes decisions
arithmetic, which
Precision based on an integer
can sometimes
decision parameter,
1. Endpoints: x1=10,y1=20 and x2=16,y2=23. lead to
which exactly tracks
2. Calculate differences: inaccuracies or
the error.
o dx=16−10=6 gaps in the line.
o dy=23−20=3 More complex to
3. Determine steps: understand the
o steps = max(|6|, |3|) = 6 Simpler to underlying logic (the
4. Calculate increments: Implementation understand and decision parameter)
o xincrement=dx/steps=6/6=1 Complexity implement but is
o yincrement=dy/steps=3/6=0.5 conceptually. straightforward to
5. Initialize coordinates: implement once
o x=10 understood.
o y=20 Very efficient,
6. Plotting Loop:
making it the
Less efficient due preferred choice for
Current Rounded Rounded Plotted to its reliance on hardware
Step Current y Efficiency
x x y Pixel costly floating- implementations
0 10 20 10 20 (10, 20) point operations. and in most
computer graphics
1 10+1=11 20+0.5=20.5 11 21 (11, 21)
applications.
2 11+1=12 20.5+0.5=21 12 21 (12, 21)
Produces a set of Produces a set of
3 12+1=13 21+0.5=21.5 13 22 (13, 22) pixel coordinates pixel coordinates
Output
4 13+1=14 21.5+0.5=22 14 22 (14, 22) that are an that are an exact
approximation of approximation
Bresenham's  Else (p1 >= 0): The
Feature DDA Algorithm next pixel is
Algorithm
Southeast.
the line. based on the
decision parameter.  x=x+1
 y=y-1
 p1 = p1 +
2. (c) Write the algorithm for ellipse generating 2 * r_y^2
algorithm. *x-2*
r_x^2 * y
The most common algorithm for drawing an ellipse is the + r_y^2
Midpoint Ellipse Algorithm, which is a variant of the 3. Region 2 (from the end of Region 1 to (rx,0)):
Midpoint Circle Algorithm. It's a highly efficient method o Initialize the decision parameter for
that uses a decision parameter to choose the next pixel in this region. The final x and y from
the path of the ellipse. Region 1 are the starting points.
o Loop while y >= 0:
Midpoint Ellipse Algorithm  Plot the current pixel and its
symmetric points.
 Check the decision
This algorithm is based on the ellipse's symmetric
parameter p2:
properties. We only need to calculate the pixel positions
 If p2 > 0: The next
for one quadrant, and the rest can be found using
pixel is South.
symmetry. The algorithm works in two regions: Region 1
 y=y-1
(where the slope is between 0 and -1) and Region 2 (where
the slope is between -1 and -infinity).
 p2 = p2 -
2 * r_x^2
*y+
Given: The center of the ellipse (xc,yc) and the semi-major r_x^2
and semi-minor axes, rx and ry.  Else (p2 <= 0): The
next pixel is
Steps: Southeast.
 y=y-1
1. Initialize variables:  x=x+1
o Start at the top-most point on the  p2 = p2 +
ellipse: (x,y)=(0,ry). 2 * r_y^2
o Initialize the decision parameters for *x-2*
both regions: r_x^2 * y
 p1_initial = r_y^2 - r_x^2 * + r_x^2
r_y + 0.25 * r_x^2 (for Region 4. Symmetry: For each point (x,y) calculated, plot
1) all four symmetrical points relative to the center
 p2_initial = r_y^2 * (x + (xc,yc):
0.5)^2 + r_x^2 * (y - 1)^2 - o (xc+x,yc+y)
r_x^2 * r_y^2 (for Region 2) o (xc−x,yc+y)
o Plot the first point and all symmetrical o (xc+x,yc−y)
points relative to the center (xc,yc). o (xc−x,yc−y)
2. Region 1 (from (0,ry) to the point where the
slope is -1): Question 3: Solution
o Loop while (r_y^2 * x) < (r_x^2 * y)
 Plot the current pixel (xc 3. (a) Write the differences between geometric
+x,yc+y) and its symmetric transformations and coordinate transformations.
points.
 Check the decision
parameter p1: Geometric Coordinate
Feature
 If p1 < 0: The next Transformations Transformations
pixel is East. The geometric The coordinate
 x=x+1 object itself is system itself is
 p1 = p1 + What is moved, scaled, or changed relative to
2 * r_y^2 Transformed rotated relative to a the objects. The
*x+ fixed coordinate points of the object
r_y^2 system. The points remain fixed, but
Geometric Coordinate The combined transformation matrix M is the product of
Feature these three matrices in reverse order of application:
Transformations Transformations
M=T−1cdotR(theta)cdotT
of the object change their coordinate
their position, while values change to
the coordinate reflect the new Applying this matrix M to any point (x,y) on the line will
system remains system. give the new, rotated point (x′,y′).
static.
A change in the Derivation of the Rotation Matrix
A change in the way
position or
we describe the
Perspective orientation of an Let's derive the 2D rotation matrix for a point P(x,y)
location of an
object within a rotated by an angle theta around the origin to get the new
object.
scene. point P′(x′,y′).
The inverse
A transformation is
Mathematical applied directly to
transformation is  Assume the original point P has polar
applied to the coordinates (r,phi), where:
Representation the coordinates of
coordinate system o x=rcosphi
the object's vertices.
axes. o y=rsinphi
Changing from a  After rotating by angle theta, the new polar
Cartesian coordinates for P′ will be (r,phi+theta).
Moving a square 5
Example units to the right on
coordinate system  Using these new polar coordinates, the new
(x, y) to a Polar Cartesian coordinates (x′,y′) are:
a screen.
coordinate system o x′=rcos(phi+theta)
(r,theta). o y′=rsin(phi+theta)
Used to manipulate  Now, use the trigonometric sum identities:
objects in a scene, Used to define o cos(alpha+beta)=cosalphacosbeta−sina
Purpose in such as moving a different levels of lphasinbeta
Graphics car, rotating a representation for o sin(alpha+beta)=sinalphacosbeta+cosal
character, or objects. phasinbeta
resizing a window..  Apply these identities to the expressions for x′
and y′:
3. (b) Discuss how a line is rotated against a pivot point. o x′=r(cosphicostheta−sinphisintheta)
Also derive the rotation matrix. o y′=r(sinphicostheta+cosphisintheta)
 Distribute the r:
Rotation of a Line against a Pivot Point
o x′=(rcosphi)costheta−(rsinphi)sintheta
o y′=(rsinphi)costheta+(rcosphi)sintheta
 Substitute the original x and y values back in
Rotating a line about a pivot point (or an arbitrary point)
(x=rcosphi and y=rsinphi):
that is not the origin requires a sequence of three basic
o x′=xcostheta−ysintheta
transformations:
o y′=ycostheta+xsintheta

1. Translation: Translate the entire line and the


3. (c) How many times the area of a rectangle will be
pivot point so that the pivot point moves to the
increased if scaling factors are S_x=3,S_y=3?
origin (0,0).
2. Rotation: Rotate the line about the origin by the
desired angle theta. Let the original rectangle have a length L and a width W.
3. Reverse Translation: Translate the line back by
the same amount used in the first step. This  Original Area (A_original) = LtimesW
moves the pivot point back to its original
position. Now, the scaling factors are S_x=3 and S_y=3. This means
the new dimensions of the rectangle will be:
Let the line have endpoints P_1(x_1,y_1) and
P_2(x_2,y_2), and the pivot point be P_p(x_p,y_p).
 New Length (L′) = S_xtimesL=3L
 New Width (W′) = S_ytimesW=3W
 Step 1: Translate to Origin
 Step 2: Rotate about Origin The new area of the scaled rectangle (A_new) will be:
 Step 3: Translate Back
 A_new=L′timesW′=(3L)times(3W)=9times(Ltimes o T=[t3t2t1] is the parameter vector
W) o MB is the Bézier Basis Matrix
o GB is the Bézier Geometry Vector
Since LtimesW is the original area, we can write: 2. Explicit Form (using Blending Functions): This
form represents the curve as a weighted average
of the control points, where the weights are the
 A_new=9timesA_original Bernstein blending functions.

The area of the rectangle will be increased by a factor of P(t)=i=0∑nBi,n(t)Piwhere Bi,n(t) are the
9. Bernstein polynomials.

Question 4: Solution The relationship between the Geometry Vector and the
Basis Matrix is a direct mathematical one.
4. (a) Differentiate between Interpolation and
approximation in spline representations.  The Bézier Geometry Vector (GB) is a column
vector containing the coordinates of the control
Feature Interpolation Approximation points. It defines the geometry of the curve. For
a cubic curve, it is: GB=P0P1P2P3
The curve must pass The curve does not have
Curve's
through all the given to pass through the  The Bézier Basis Matrix (MB) contains the
Behavior coefficients of the Bernstein polynomials. It
control points. given control points.
transforms the geometry vector into the
To generate a smooth
To create a smooth coefficients of the polynomial that defines the
curve that represents
curve that exactly curve. For a cubic curve, it is: MB=−13−313−630
Purpose the general shape
connects a series of −33001000
defined by a set of
data points.
control points.
The relationship is that the basis matrix acts as a
Direct control over Provides more intuitive
Control transformation on the geometry vector. When multiplied
the curve is limited. and flexible control.
together, they generate the coefficients of the polynomial
Cardinal splines and that define the curve.
B-splines and Bézier
Examples Hermite splines are
curves are examples of
of Splines examples of
approximating splines. 4. (c) Explain Hermite Interpolation.
interpolating splines.
High precision at the Less precise at the
Hermite interpolation is a method for generating a
control points, as control points, but
Precision smooth curve segment between two endpoints by
the curve must meet provides greater overall
specifying the position and the tangent (or derivative) at
them exactly. shape flexibility.
each endpoint. Unlike simple linear interpolation, which
only considers the endpoints' positions, Hermite
4. (b) How the Bézier geometry vector (GB) and the interpolation takes into account the "direction" of the
Bézier basis matrix are related? Explain. curve at its start and end. This gives the user more control
over the shape and continuity of the curve.
The Bézier curve is defined by a set of control points P0,P1
,...,Pn. Its parametric form is a polynomial expression. This Key Components of a Hermite Curve Segment:
expression can be written in two ways:
1. Two Endpoint Positions: P1 and P2.
1. Polynomial Form (using the Basis Matrix): This 2. Two Tangent Vectors: R1 and R2. These vectors
form represents the curve as a product of the specify the slope and direction of the curve at
geometric vector, the basis matrix, and the points P1 and P2, respectively.
parameter vector.
The Hermite Curve Equation:
For a cubic Bézier curve (n=3), the equation is:
A Hermite curve is a cubic polynomial defined by the
P(t)=T⋅MB⋅GB where: following equation:

o P(t)=[x(t)y(t)] is the point on the curve P(t)=P1⋅H0(t)+P2⋅H1(t)+R1⋅H2(t)+R2⋅H3(t)


at parameter t
where t ranges from 0 to 1, and Hi(t) are the Hermite
blending functions (or basis functions).

 H0(t)=2t3−3t2+1
 H1(t)=−2t3+3t2
 H2(t)=t3−2t2+t
 H3(t)=t3−t2

Explanation:

 At t=0, H0(0)=1 and all other basis functions are


0. So P(0)=P1.
 At t=1, H1(1)=1 and all other basis functions are
0. So P(1)=P2.
 The derivatives of the blending functions ensure
that at the endpoints, the curve's tangent
matches the specified tangent vectors R1 and R2
. For instance, taking the derivative with respect
to t, we find that P′(0)=R1 and P′(1)=R2.

Advantages of Hermite Interpolation:

 Local Control: Changing the position or tangent


of one endpoint only affects that specific curve
segment. This makes it easy to construct a
complex curve by piecing together multiple
segments.
 Continuity: By matching the tangent vectors at
the endpoints of adjacent segments (R2 of the
first segment equals R1 of the next), it's possible
to achieve C1 continuity, resulting in a visually
smooth join.

You might also like