0% found this document useful (0 votes)
1 views

Computer Graphics (1)

The document discusses various computer graphics concepts including polygon clipping, cubic splines, line drawing algorithms, scaling, shearing, illumination, shading, and hidden line removal. It explains algorithms like Sutherland-Hodgman and Cohen-Sutherland for clipping, the use of cubic splines for smooth interpolation, and different shading techniques such as constant, interpolated, and grounded shading. Additionally, it covers the roles of ambient, diffused, and specular light in rendering, along with the importance of hidden line removal for clarity in 3D scenes.

Uploaded by

vigilantswirles6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Computer Graphics (1)

The document discusses various computer graphics concepts including polygon clipping, cubic splines, line drawing algorithms, scaling, shearing, illumination, shading, and hidden line removal. It explains algorithms like Sutherland-Hodgman and Cohen-Sutherland for clipping, the use of cubic splines for smooth interpolation, and different shading techniques such as constant, interpolated, and grounded shading. Additionally, it covers the roles of ambient, diffused, and specular light in rendering, along with the importance of hidden line removal for clarity in 3D scenes.

Uploaded by

vigilantswirles6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Polygon Clipping:

Polygon clipping is removing parts of a polygon that are outside a given boundary.
For example, if a triangle extends beyond the edges of a window, polygon clipping would
trim the triangle to fit inside the window.

Polygon clipping has several applications, including:


● Extracting desired parts
● Identifying visible and invisible areas in 3D objects
● Creating objects using solid modelling
● Drawing operations
● Operations related to the pointing of an object
● Deleting, copying, and moving part of an object

The Sutherland-Hodgman polygon clipping algorithm clips a polygon against


each edge of the window, one at a time. The algorithm inputs a list of vertices
for each window edge and outputs a new list of vertices. This new list is then
submitted to the algorithm for clipping against the next window edge.

Cubic Spline:
A cubic spline is a continuous function representing the relationship between two numeric
variables. It is a piecewise cubic function that has two continuous derivatives everywhere.

● Piecewise Cubic Functions: A cubic spline is made up of a series of third-order


polynomials that are fit together in a piecewise fashion. The first and second
derivatives are equal at every point where two polynomials meet. This makes for a
smooth-fitting line.
If there are n data points, the corresponding cubic spline will consist of n-1 intervals,
resulting in n-1 cubic polynomials.

● Smooth Interpolation with Cubic Splines: A cubic spline interpolates a set of data
points and guarantees smoothness at the data points.
● System of Linear Equations: The coefficients of the cubic polynomials are
determined by solving a system of linear equations.
Each cubic polynomial has four coefficients (a, b, c, and d in the form
3 2
𝑓(𝑥) = 𝑎𝑥 + 𝑏𝑥 + 𝑐𝑥 + 𝑑

● Coefficient Determination in Cubic Splines: To determine the coefficients of each


cubic function, the constraints are written out explicitly as a system of linear
equations with 4(n-1)

DDA:
The Digital Differential Analyzer (DDA) algorithm is a line drawing algorithm used in
computer graphics. It is an incremental method of scan conversion of lines.

DDA Algorithm:
Given
● Starting coordinates = (Xo, Yo)
● Ending coordinates = (Xn, Yn)

The points generation using DDA Algorithm involves the following steps-

Step-1:
Calculate ΔX, ΔY and M from the given input.

These parameters are calculated as


· ΔX = Xn - Xo
· ΔΥ=Υn - Υo
· Μ= ΔΥ /ΔΧ

These parameters are calculated as


· ΔX = ΔΥ/M
· ΔΥ= M.ΔΧ

Step-2:
Suppose the current point is (X,Y ) and the next point is (Xp+1, Y p +1). Find the next point by
following the below three cases-
Step-3:
Keep repeating Step-2 until the endpoint is reached or the number of generated new
points (including the starting and ending points) equals the step count.

Q. Calculate the points between the starting point (5, 6) and ending
point (8, 12).
Solution-
Given-

● Starting coordinates = (X0, Y0) = (5, 6)


● Ending coordinates = (Xn, Yn) = (8, 12)

Step-1:

Calculate ΔX, ΔY and M from the given input.

● ΔX = Xn – X0 = 8 – 5 = 3
● ΔY =Yn – Y0 = 12 – 6 = 6
● M = ΔY / ΔX = 6 / 3 = 2

Step-2:

As M > 1, so case-03 is satisfied.

Now, Step-2 is executed until Step-3 is satisfied.


Q: Give an explicit form of a 3*3 matrix representation of the
transforming scaling factor 2 in the x direction and then rotate about
(2,1)

Ans:
To represent the transformation of scaling by a factor of 2 in the x-direction followed by a
rotation about the point (2,1) in a 3x3 matrix, you can use a sequence of transformation
matrices.

The scaling matrix for scaling by a factor of 2 in the x-direction is:

Sx =

The rotation matrix for rotating about a point (a, b) by an angle θ is:

So, for a rotation about (2,1), the rotation matrix becomes:

R(2,1) =
The overall transformation matrix (T) can be obtained by multiplying these matrices in the
order of scaling followed by rotation:
T = R(2,1)*Sx

Q: What is Scaling and Shearing?


Ans:
Scaling in computer graphics refers to the transformation of objects by altering their size.
This transformation is applied to objects in a two-dimensional or three-dimensional space.
Scaling can be uniform (equal scaling in all dimensions) or non-uniform (scaling by different
factors in different dimensions).

A scaling matrix in homogeneous coordinates typically represents the scaling operation. For
a 2D scaling matrix, it looks like:

For a 3D scaling matrix:

Here, Sx , Sy, Sz are scaling factors along the x, y, and z axes, respectively. Applying this
matrix to the coordinates of an object scales it accordingly.
Scaling is an important operation in computer graphics because it allows for the
manipulation of the size and proportions of objects, contributing to the overall visual
composition of a scene or animation.
Shearing is a transformation in computer graphics that distorts the shape of objects, altering
their orientation along one of the coordinate axes. This transformation is applied to objects in
two-dimensional or three-dimensional spaces. Shearing can be performed along the x-axis,
y-axis, or both, and it is characterised by the shearing factors, which determine the amount
of shearing in each direction.
In 2D graphics, shearing along the x-axis is represented by a shearing matrix as follows:

Sx =

Here, shx is the shearing factor along the x-axis. When applied to the coordinates of a 2D
object, this matrix shears the object horizontally.

Similarly, shearing along the y-axis is represented by a shearing matrix as follows:

Sy =
Here, shy is the shearing factor along the y-axis. When applied to the coordinates of a 2D
object, this matrix shears the object vertically.

In 3D graphics, shearing can occur along any of the coordinate axes, and the shearing
matrices become more complex. For example, shearing along the x-axis in 3D space is
represented by the following matrix:

Sx =

Here, shxy and shxz are the shearing factors along the x-axis in the y and z directions,
respectively.

Shearing is used in computer graphics for various purposes, including:

● Creating Perspective: Shearing can be used to simulate perspective effects in 3D


scenes.
● Texturing and Mapping: Shearing is applied in texture mapping and terrain
modelling.
● Animation: Shearing can contribute to dynamic and interesting transformations in
animations.
It's important to note that shearing introduces a non-uniform transformation that distorts the
shape of objects, and it is often employed for specific visual effects rather than general
scaling or rotation.

Interpolated Spline:
Interpolation is the process of drawing two-dimensional Curves. The artist places key points,
and the computer algorithm uses these points to create a smooth curve that passes through
or near the points.
When polynomial sections are filled so that a curve passes through each control point, that
resulting curve is said to have an interpolated set of control points.
● Spline interpolation is a method that fits low-degree polynomials to small subsets of
values. For example, it can fit nine cubic polynomials between each pair of ten
points.
● An interpolating curve is a curve that passes through each control point. A curve that
passes near the control points, but not necessarily through them, is called an
approximating curve.
● Cubic spline interpolation is a method for finding a curve that connects data points
with a degree of three or fewer.

Piecewise spline:
Piecewise splines in computer graphics refer to a method of representing curves or surfaces
using multiple polynomial functions, known as "pieces," that are joined together at specific
points to form a smooth and continuous curve or surface. This approach is particularly useful
for creating complex shapes and animations in computer graphics.

Advantages of Piecewise Splines:


1. Local Control: Piecewise splines allow for local control over the shape of the curve.
Each piece only influences a specific region, making it easier to modify and control
the overall shape of the curve.
2. Smoothness and Continuity: By carefully choosing the degree of the polynomial
and the placement of control points, piecewise splines can ensure smooth transitions
between the pieces, providing a visually appealing and continuous curve.

Types of Piecewise Splines


1. Bézier Splines: These are often used in computer graphics and animation. Bézier
curves are defined by control points, and each piece of the spline is a Bézier
segment.
2. B-Spline (Basis Spline): B-Splines are defined by a set of control points and a
degree. They offer more flexibility in adjusting the shape of the curve and maintaining
local control.

Applications in Computer Graphics


1. Animation and Modeling: Piecewise splines are widely used in 3D computer
graphics for character animation, object modelling, and creating smooth transitions
between keyframes.
2. CAD (Computer-Aided Design): In CAD applications, piecewise splines are used
for designing curves and surfaces with precision.
Cohen-Sutherland line clipping algorithm:
The Cohen-Sutherland line clipping algorithm is a computer graphics algorithm that cuts
lines into portions that are within a rectangular area. It eliminates lines that are outside the
area of interest and clips lines that are partially inside.

Pseudocode:
1. Assign the region codes for the two endpoints.
2. If both endpoints have region codes are 0000 then the line accepted completely.
3. else perform logical AND/OR operations for both region codes.
● if the result ≠ 0
● the line is outside
● else
● The line is partially inside

● p0 OR p1 = 0000 then completely accepted


● else
● p0 AND p1 ≠ 0000 then rejected
● else
● the line is partially inside

4. y = y1+m(x-x1) else x = x1+ 1/m(y-y1)


5. Verify xmin <= x <= xmax and ymin <= y <= ymax

Problem:
Sol:
Illumination:
Illumination in computer graphics replicates the interaction of virtual light sources with
surfaces, modelling the reflection and absorption of light to calculate pixel brightness
and colour in a 3D environment.

● Simulation of Light Interaction:


○ Illumination in computer graphics involves simulating how virtual light
sources interact with surfaces in a 3D environment.
○ It models the reflection, refraction, and absorption of light by different
materials.

● Calculation of Pixel Attributes:


○ The process includes calculating the brightness, colour, and shading of each
pixel in a rendered image.
○ Algorithms, such as the Phong reflection model, are commonly used to
determine pixel values based on lighting conditions.

Shading:
Shading involves determining the colour and intensity of individual pixels on surfaces,
contributing to realism by considering factors such as surface normals and material
properties, and employing models like Phong shading for smooth transitions in
rendered images.
● Determination of Pixel Color:
○ Shading focuses on determining the colour or intensity of individual pixels on
a surface.
○ It takes into account factors such as the angle of incidence, surface normals,
and material properties.

● Enhancement of Realism:
○ Shading contributes to the realism of rendered images by providing visual
cues about the three-dimensional nature of objects.
○ Different shading models, such as Gouraud shading or Phong shading, are
employed to create smooth transitions in colour and brightness across
surfaces.

There are three types of shading. They are the following-

1. Constant Shading (Flat Shading):

● Methodology: The colour and brightness values for an entire polygon are
calculated based on a single normal vector, typically at the polygon's centre.

● Result: The same colour is applied to all pixels within the polygon, leading to
a flat appearance.
● Advantages: It's computationally less intensive compared to other shading
methods.
2. Interpolated Shading (Gouraud Shading):

● Methodology: Color values are interpolated across vertices of a polygon


using the intensities at each vertex.
● Result: Smoother shading effects are achieved, capturing changes in
illumination across the surface.
● Advantages: Provides a more visually appealing appearance than constant
shading, especially for curved surfaces.

3. Grounded Shading (Phong Shading):

● Methodology: Phong shading calculates the colour of each pixel by


interpolating normals across the surface of a polygon.
● Result: This method produces realistic highlights and reflections, accounting
for the specular component of light reflection.
● Advantages: Offers high-quality visual results, capturing intricate lighting
effects and providing a more accurate representation of surface reflections.

Ambient Light:
Ambient light in computer graphics refers to the background or environmental light that is
present uniformly across a scene, independent of the position and orientation of surfaces. It
represents the overall illumination from various indirect sources such as reflections, multiple
light bounces, or global illumination.

Purpose in Rendering:
● Ambient light contributes to the base level of brightness in a scene, ensuring that
objects are visible even in areas not directly illuminated by primary light sources.
● It helps to reduce the starkness of shadows and adds a sense of realism by
simulating the indirect lighting present in real-world environments.

Implementation in Shading Models:


● In shading models like the Phong reflection model, ambient light is often considered
as a constant term that contributes to the overall colour of a surface.
● The ambient reflection term is added to the diffuse and specular reflection
components, providing a more comprehensive representation of how light interacts
with surfaces.

Diffused Light:
Diffused light, in the context of computer graphics and illumination, refers to the scattered
and even distribution of light on a surface. It occurs when light interacts with a rough or
matte surface, causing the light to reflect in various directions.
● Surface Interaction:
○ Diffused reflection occurs on surfaces that do not exhibit a smooth, mirror-like
behaviour. Instead, light penetrates the surface and scatters in multiple
directions due to microscopic variations in the surface structure.
○ Materials like paper, plaster, or unpolished wood exhibit diffused reflection.
● Appearance in Shading Models:
○ In shading models, the diffused reflection component represents the scattered
light on a surface. It is often calculated using the Lambertian reflection model,
which assumes that the intensity of the diffused reflection is proportional to
the cosine of the angle between the incoming light and the surface normal.
○ Diffused light contributes to the perceived brightness and colour of an object
and is a key element in providing a realistic appearance in
computer-generated imagery.

Specularly Reflected Light:


Specularly reflected light in computer graphics refers to the mirror-like reflection of light off a
surface. Unlike diffuse reflection, which scatters light in various directions, specular reflection
produces a concentrated and shiny highlight at specific viewing angles.

● Surface Characteristics:
○ Specular reflection occurs on smooth and polished surfaces, where the
incoming light reflects predominantly in a single direction.
○ The reflective properties of materials like glass, metal, or water are examples
of surfaces that exhibit specular reflection.

● Role in Shading Models:


○ Shading models, such as the Phong reflection model, incorporate a specular
reflection component to simulate the highlight caused by direct reflection of
light sources.
○ This component is highly dependent on the viewing angle and the position of
the light source relative to the surface normal.
○ The specular reflection contributes to the perception of shininess and
glossiness in materials, adding realism to the appearance of surfaces.

Hidden Line Removal:


Hidden line removal is a technique used in computer graphics to eliminate the display of
lines that are hidden or obscured by other objects in a 3D scene.

● Purpose: It enhances the clarity of a rendered image by showing only the visible
lines, allowing viewers to better understand the spatial relationships between objects.
● Methods: Techniques like depth-buffering, z-buffering, or scanline algorithms are
employed to determine which lines are visible and should be displayed.

Hidden Surface Removal:


Hidden surface removal is a process in computer graphics that determines which surfaces or
polygons are visible and should be rendered, while obscuring surfaces are omitted.
● Purpose: It ensures that only the surfaces facing the viewer are displayed,
preventing visual artefacts and improving the realism of 3D scenes.
● Algorithms: Various algorithms, such as the Painter's algorithm, z-buffering, and the
scanline algorithm, are used to identify and render visible surfaces. These algorithms
consider factors like depth, occlusion, and visibility to prioritize the drawing order of
surfaces.

You might also like