Computer Graphics Notes
Computer Graphics Notes
A vector, on the other hand, is defined as the difference between two point positions. Thus, for a
two-dimensional vector, we have
where the Cartesian components (or Cartesian elements) V, and V, are the projections of V onto
the x and y axes. Given two point positions, we can obtain vector components in the same way
for any coordinate reference frame.
We can describe a vector as a directed line segment that has two fundamental properties:
magnitude and direction.
The direction for this two-dimensional vector can be given in terms of the angular displacement
from the x axis as
A vector has the same properties (magnitude and direction) no matter where we position the
vector within a single coordinate system. And the vector magnitude is independent of the
coordinate representation. Of course, if we change the coordinate representation, the values for
the vector components change.
C=a+b
Vector addition is illustrated geometrically in Figure above. We obtain the vector sum by placing
the start position of one vector at the tip of the other vector and drawing the sumination vector as
in figure above.
Vector multiplication
where ᶿ is the angle between the two vectors as in figure. This product is called the scalar product
(or dot product) of two vectors. It is also referred to as the inner product.
Cross product is another vector multiplication operation, usually used only for 3D vectors. The
direction of axb is orthogonal to both a and b. The magnitude is equal to the area of the
parallelogram formed by the two vectors. It is given by-
Segments are a fundamental concept in computer graphics, used to represent the basic
building blocks of a graphical scene. They are commonly used in 2D graphics to
represent lines or curves that connect two or more points.
An introduction segment is defined by two endpoints, which are specified using their
(x,y) coordinates in a 2D Cartesian coordinate system. Once defined, the introduction
segment can be used to represent a variety of different shapes and objects, depending on
its length, curvature, and orientation.
One common use of introduction segments is in the rendering of vector graphics, where
they are used to represent the individual lines and curves that make up a complex
image. In this context, introduction segments are often referred to as “paths”, and can
be used to represent everything from simple shapes like squares and circles, to complex
curves like bezier curves or splines.
Another common use of introduction segments is in computer-aided design (CAD)
applications, where they are used to represent the basic building blocks of 2D and 3D
models. In this context, introduction segments can be used to represent everything from
straight edges and curves to more complex shapes like spirals and helixes.
To view an entire image or a part of image with various attributes, we need to organize
image information in a particular manner since existing structure of display file does
not satisfy our requirements of viewing an image. To achieve this display, file is
divided into Segments. Each segment corresponds to a component and is associated
with a set of attributes and image transformation parameters like scaling, rotation.
Presence of Segment allows :
Subdivision of picture.
Visualization of particular part of picture.
Scaling, rotation and translation of picture.
Types of Segments :
Posted Segment : When visible attribute of segment is set to 1, it is called Posted
segment. This is included in active segment list.
Unposted Segment : When visible attribute of segment is set to 0, it is called
Unposted segment. This is not included in active segment list.
Uses of Segment :
1. Drawing lines and curves: Segments are commonly used to represent lines and
curves in 2D graphics. By connecting two or more points with a series of line
segments, you can create a variety of shapes and objects, including geometric
shapes, symbols, and illustrations.
2. Vector graphics: In vector graphics, segments are used to define the paths of shapes
and objects. By defining a series of interconnected segments, you can create
complex curves and shapes that can be resized and transformed without losing their
clarity or resolution.
3. Computer-aided design (CAD): Segments are widely used in CAD applications to
define the edges and curves of 2D and 3D models. By connecting a series of
segments together, you can create complex shapes and objects that can be
manipulated and transformed in a virtual environment.
4. Animation: Segments are used extensively in animation to create smooth, fluid
motion. By defining a series of keyframes and connecting them with segments, you
can create animations that mimic the movement of real objects and characters.
5. Computer vision: Segments are often used in computer vision applications to identify
and track objects in real-time video. By defining a set of reference points on an
object and tracking their movement using segments, you can create a model of the
object’s motion and use it to track it in a video stream.
Issues in Segment :
Here are a few of the main issues to consider:
1. Aliasing: When using segments to represent lines or curves, aliasing can occur if the
segments are not defined with sufficient detail. This can result in jagged edges or
rough curves that do not accurately represent the intended shape.
2. Performance: If segments are used extensively in a graphics application, it can
impact performance and slow down rendering times. This can be especially
problematic in real-time applications, such as video games, where fast frame
rates are essential for a smooth user experience.
3. Memory usage: Depending on the complexity of the scene being rendered,
segments can require a significant amount of memory. This can be a concern in
applications with limited memory resources, such as mobile devices or
embedded systems.
4. Accuracy: While segments can be used to represent complex shapes and objects,
their accuracy is limited by the number of segments used to define them. To
achieve a high level of accuracy, a large number of segments may be required,
which can impact performance and memory usage.
5. Rendering artifacts: When using segments to create complex shapes or objects,
rendering artifacts can occur if the segments are not connected properly. This can
result in visible gaps or overlaps between segments, which can be distracting or
visually unappealing.
While creating and using the segments in a program we can make one or more
programming displays with the five functions:
1. opensegment
2. closesegment
3. deletesegment
4. postsegment
5. unpostsegment
By issuing wrong function calls and parameter passing there will occur some errors
cause of these default programming mistakes as:
2. closesegment(n)
If no segment is currently open, no effect will be there.
3. Deletesegment(n)
Any currently open segment is closed, if segment n does not exist no further effect.
4. postsegment(n)
Any currently open segment is closed, if segment n is nonexistent or already posted, no
effect.
5. unpostedsegment(n)
Any currently open segment is closed, if segment n is nonexistent or already unposted,
no effect.
Adding a new drawing or picture to the existing segment is called appending to the
segment. By adding new drawing to existing segment, we can change the picture at run
time.
For example to display the result of two concurrent processes in the form of two graphs
plotted on the same axes as shown in the following figure;
In every two minute each process generates a new data point and the graph are
extended. One method of writing such programs would be to create a new segment for
each addition made to be either graph. This would be a time consuming on the other
hand any alternative approach such as the use of single statement for each graph could
involve reconstructing the entire segment after every step.
Clipping
Clipping: Any procedure that identifies those portions of a picture that are either inside
or outside of a specified region of space is referred to as a clipping algorithm or simply
clipping. The region against which an object is to be clipped is called a clip window.
Clipping is the process to identify the picture either inside or outside of the displaying
area.
Application of clipping includes extracting part of a defined scene for viewing,
identifying visible surface in three-dimensional views, object boundary, creating objects
using solid modelling procedures, displaying a multi-window environment and drawing
and painting operations, moving, cursing depending on the application, the clip window
can be general polygon or it can have curved boundaries.
For the viewing transformation, we want to display only those picture parts that are
within the window area. Everything outside the window is discarded. Clipping
algorithm can be applied in world co-ordinates, so that only the contents of the window
interior are mapped to device co-ordinates.
Types of Clipping :
These are the main types of clipping
1. Point clipping.
2. Line clipping (straight line segment).
3. Area clipping (polygons) or curve clipping.
Line and polygon clipping routines are standard components of the graphics package,
but many packages accommodate curved objects.
1. Point Clipping: Assuming that the clip window is a rectangle in the standard position
we have a point P = (x, y) for display, if the following conditions are satisfied :
Where the edges of the clip window (Xw min , Xw max, Yw min, Yw max ) can be
either the world co-ordinate window boundaries or viewport boundaries. If anyone of
these four conditions is not satisfied the point is clipped.
For Example: Point clipping can be applied to the scene involving explosions that are
modelled with particles (points) distributed in some region of the scene.
2. Line Clipping: A line clipping procedure involves several parts. First, we can test a
given line segment to determine whether it lies completely inside the clipping window if
it does not, we try to determine whether it lies completely outside the window.
3. Area Clipping (Polygons) or Curve Clipping: Area with curved boundaries can be
clipped with methods similar to point clipping and line clipping. Curve clipping
procedures will involve non-linear equations and this requires more processing than for
object with linear boundaries.
The bounding rectangle for a circle or other curved object can be used first to test the
overlap with a rectangular clip window. If the bounding rectangle for the object
completely inside the window, we save the object. If the rectangle is determined to be
completely outside the window, we discard the object.
If the bounding rectangle test fail, we can look for other computation saving approaches.
For a circle, we can use co-ordinate extent of individual quadrants and then octants for
testing before calculating curve window intersections.
Filled Area Primitives
Filled Area primitives are used to filling solid colors to an area or image or polygon. Filling the
polygon means highlighting its pixel with different solid colors. Following are two filled area
primitives:
In this seed fill algorithm, we select a starting point called seed inside the boundary of the
polygon. The seed algorithm can be further classified into two algorithms: Flood Fill and
Boundary filled.
In this flood-fill algorithm, a seed point is taken inside the polygon. The flood fill algorithm is
used when the polygon has multiple color boundaries. In this method, the related pixels are
replaced with the selected color using fill color. The selected pixel values before are reassigned
with the selected color value. This can be done using two approaches either 4-connected or 8-
connected.
Algorithm:
Disadvantages:
The boundary fill algorithm uses polygon boundaries. It is also called an edge fill algorithm. In
this method, a seed point is taken in the polygon boundary and checks whether the adjacent or
neighboring pixel is colored or not. If the adjacent pixel is not colored then, fill it. This can be
done using two approaches: 4-connected or 8-connected.
Algorithm:
Function boundaryfill(x, y, color, color1)
int c;
c = getpixel(x ,y);
if (c! =color) & (c!=color1)
{
setpixel (x, y, color);
boundaryfill( x+1, y, color, color1);
boundaryfill( x-1, y, color, color1);
boundaryfill( x, y+1, color, color1);
boundaryfill( x, y-1, color, color1);
}
Advantages:
Disadvantages:
Scan fill algorithm is an area-filling algorithm that fill colors by scanning horizontal lines. These
horizontal lines intersect the boundaries of the polygon and fill colors between the intersection
points. Its main purpose is to fill colors in the interior pixels of the polygon.
Advantages:
Scan fill algorithm fills the polygon in the same order as rendering.
It takes advantage of coherence thus, a fast algorithm.
Disadvantages:
Polygon is an ordered list of vertices as shown in the following figure. For filling polygons with
particular colors, you need to determine the pixels falling on the border of the polygon and those
which fall inside the polygon. In this chapter, we will see how we can fill polygons using
different techniques.
This algorithm works by intersecting scanline with polygon edges and fills the polygon between
pairs of intersections. The following steps depict how this algorithm works.
Step 1 − Find out the Ymin and Ymax from the given polygon.
Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name each
intersection point of the polygon. As per the figure shown above, they are named as p0, p1, p2,
p3.
Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. p0,p1, p1,p2,
and p2,p3.
Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate pairs.