Computer Graphics (1)
Computer Graphics (1)
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.
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.
● 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
𝑓(𝑥) = 𝑎𝑥 + 𝑏𝑥 + 𝑐𝑥 + 𝑑
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.
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-
Step-1:
● ΔX = Xn – X0 = 8 – 5 = 3
● ΔY =Yn – Y0 = 12 – 6 = 6
● M = ΔY / ΔX = 6 / 3 = 2
Step-2:
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.
Sx =
The rotation matrix for rotating about a point (a, b) by an angle θ is:
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
A scaling matrix in homogeneous coordinates typically represents the scaling operation. For
a 2D scaling matrix, it looks like:
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.
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.
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.
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
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.
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.
● 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):
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.
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.
● 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.
● 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.