CG Chapter 3
CG Chapter 3
-Pixel is the smallest addressable element of raster device. It is derived from the “Picture
Element”.
-The number of pixel of a display device determines the resolution of the device, and
therefore higher number of pixels is preferred for graphics applications.
-These coordinates identify pixel or point. To draw any image or object, some of pixels are
activated by setting some intensity. In other words, the pixels turned on.
-For example, to draw a straight line segment the adjacent pixels between two points are
turned on.
-As in the figure Point A has been positioned in the XY-plane and (x1, y1) is the position of
point A.
-To define the line we need an equation. A random point P(xi,yi) is said to be on the line l1
if and only if it satisfies the equation of the line.
-The equation of a straight line can be derived with the help of slope of a straight line.
- y=mx+b is a straight line equation which is also called slope- Intercept line equation.
slope of a line: It is the rate at which an ordinate of a point on a plane changes with
respect to a change in the horizontal coordinate.
-slope is denoted by m.
-slope(m) = vertical distance between two points / Horizontal distance between two
points.
Types of Slope.(Feb-2020)
-So the slope of any line can be one of four types:
the straight line 1) with positive slope, 2) with negative slope, 3) with zero slope and 4)
with undefined slope.
Chapter-3: Line Generation
1) DDA Algoritm
2) VECGEN Algoritm
3) Bresenham Algorithm
Step 1 − Get the input of two end points(X0 ,Y0 ) and (X1 ,Y1 ).
dx = X1 - X0
dy = Y1 - Y0
Step 3 − Based on the calculated difference in step-2, you need to identify the number of
steps to put pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y
coordinate.
Steps = absolute(dx);
else
Chapter-3: Line Generation
Steps = absolute(dy);
Step 5 − Put the pixel by successfully incrementing x and y coordinates accordingly and
complete the drawing of the line.
x = x + Xincrement;
y = y + Yincrement;
putpixel(Round(x), Round(y));
Advantages of DDA:
-It is simple to implement
-It is faster than direct line equation
-We can not use multiplication method
Disdvantages of DDA:
-Round-off is time consuming
- The line equation works well for gentle slope but when the slope is sharp the role of x
and y are interchanged as well as slope m replaced by 1/m. This method is known as
VECGEN method.
Chapter-3: Line Generation
Step: 1 If the slope is less than or equal to 1, the unit x intervals dx=1 and compute each
successive y values.
dx=1
m = dy / dx
m = ( y2 - y1 ) / 1
m = ( yk + 1 – yk ) /1
Subscript k takes integer values starting from 1,for the first point and increment by 1 until
the final end point is reached.
Step: 2 If the slope is greater than 1, the roles of x any y at the unit y intervals dy=1 and
compute each successive y values.
dy=1
m= dy / dx
m= 1/ ( x2-x1 )
m = 1 / ( xk+1 – xk )
xk+1 = xk + ( 1 / m ) ------( 3 )
Equation 2 and Equation 3 that the lines are to be processed from left end point to the
right end point.
dx= -1
m= dy / dx
m = ( y2 – y1 ) / -1
yk+1 = yk - m -------- ( 4 )
m= dy / dx
Chapter-3: Line Generation
m = -1 / ( x2 – x1 )
m = -1 / ( xk+1 – xk ) \
xk+1 = xk + ( 1 / m ) -------- ( 5 )
Equation 2 and Equation 5 used to calculate pixel position along a line with –ve slope.
Step-3: If abs(Δx) > abs(Δy) then step = abs(Δx) else step = abs(Δy)
Step-4: We have xinc = Δx / steps and yinc = Δy / steps [Find total intermediate points]
Advantage of VECGEN:
1) It is a faster method for calculating pixel position then simple line algorithm.
Disadvantage of VECGEN:
1) Round off error in successive additions can cause the pixel positions to drift away from
the true line path for long line segments.
2) The rounding operations and floating point arithmetic are still time consuming.
only lines but also used to display circles and other curves.
-As we can see in fig:2.4 last turned on pixel is (2,b) and the problem is which pixel should
be turned on next,(3,c) or (3,d)?
-According to the Bresenham’s algorithm the pixel closest to the line to be drawn will be
chosen. For this he has defined a decision parameter, so let understand what is this
decision parameter?
-Let us assume that we are drawing a line y = mx+b that passes through a point (x0,y0).
Here 0 < m < 1. Let us also assume that the last pixel turned on is (xk,yk) and the decision
to be made is for the next step that is for the vertical distance xk+1 as in fig:2.5.
-Now let us assume a vertical row of pixels which passes through horizontal distance xk+1.
Chapter-3: Line Generation
-There are three vertical points, (xk+1, yk), (xk+1, y) and (xk+1, yk+1), fall on this assumed
line.
-In addition the assumed distance between (xk+1, yk) and (xk+1, y) is d1 and distance
between (xk+1, y) and (xk+1, yk+1) is d2 in figure.
Step 2: Calculate constants dx=x2-x1, dy=y2-y1, 2dx, 2dy, and 2dy – 2dx,
Step 3: obtain the starting value for the decision parameter as Pk = 2dy - dx
If Pk < 0, the next point to plot is (xk +1, yk) and Pk +1 = Pk + 2dy
Otherwise, the next point to plot is (xk +1, yk +1)and Pk +1 = Pk + 2dy - 2dx
Terms Description
Circumference The boundary of the circle is known as the circumference
The line from the centre “O” of the circle to the circumference of the circle
Radius
is called the radius and it is denoted by “r”
The line that passes through the centre of the circle and touches the two
Diameter points on the circumference is called the diameter and
it is denoted by the symbol “D”
Arc is the part of the circumference where the largest arc is called the ma-
Arc
jor arc and the smaller one is called the minor arc
Chord The straight line that joins any two points in a circle is called a chord
Circle Formulas:
Equation of Circle, x2 + y2 = radius2
Area of a circle, A = πr2
The circumference of a circle = 2πr
Diameter = 2 x Radius
The foci(focus) are two fixed points equidistant from the center of the ellipse.
- Dashed lines and dotted lines are generated by just a minor modification in our standard
DDA algorithms.
- A dashed line can be generated by inter-dash spaces between the dashes. Generally,
dashes and inter-dash spaces are equal in length whereas a dotted line can be generated
by very short length dashes.
- By using different characters in this method, different line styles can be created.
Chapter-3: Line Generation
Let p1(x1,y1) and p2(x2,y2) be the end points of a line segment with width w , which is to
be drawn. Here two parallel line segments will be drawn from a central line(x1,y1) and
- It creates an angle at the joining end. Joint of two such lines is shown in the figure below:
- The discreteness that occurs while joining two thick lines can be removed from the poly-
lines by adding some additional portion to the joint as some specific types of joining
process.
Chapter-3: Line Generation
- There are three basic techniques or caps which are used in graphics applications: 1) butt
cap, 2) round cap, and 3) projecting square cap.
1)Butt Cap: In the butt cap the end positions of the thick lines are adjusted in such a way
that the line segment appears with square ends. The ends of such thick lines are
perpendicular to the original line segment.
2) Round Cap:In the round cap, the upper and lower line boundaries are joined by a
circular arch with a semi-circle of the diameter of the width of the thick line segment.
3) Projecting square Cap:In the projecting square cap, the portion of line segment is just
extended to give a line segment an effect of square.
1) Miter Joint
2) Round Joint
3) Bevel Joint.
Chapter-3: Line Generation
1) Miter Joint: The miter joint is one in which the exterior boundaries of two thick line
segments are extended up to their intersection point – the point where these two line
segments meet each other, if they are extended.
2) Round Joint: In the round joint, the exterior boundaries are connected with a circular
arch with a diameter of total thickness of two thick lines, which are joined.
3) Bevel Joint: The bevel joint is one where butt cap is used to draw line segment and the
little triangle that is created at the joint is filled with color of these two line segments.
- Different color is also used with different shapes of pens and brushes. Some of the
brushes and pens are shown in the following figure.
-This type of effect is an error in line segment of image. This error is called aliasing.
(jagged line are known as aliasing).
-There are many aliasing error that are observed in practice. Most common aliasing
effects are jagged profile, disappeared or improper line details, and disintegrating
texture.
-Jagged profile or jagged line is the most probable and known effect.
-The process of removing aliasing error is called anti-aliasing. In other words, the process
of making image boundary smoother, is called anti-aliasing process.
1) Super-sampling:
-samples at higher resolution, then filters down the resulting image
2) Area sampling:
-sample primitives with a box (or Gaussian, or whatever) rather than spikes
-Requires primitives that have area (lines with width) -Sometimes referred to as pre-
filtering
Fill pixels according to the proportion of their square covered by the line
weight the contribution according to where in the square the primitive falls
Chapter-3: Line Generation
Short Questions
Que-1: What is line segment? How to find a slope of line segment?(Feb-2020,
Feb-2018)
Ans: -Any two points specified in the Plane will define a line, which means that for
defining the line we must have to specify two points.
slope of a line: It is the rate at which an ordinate of a point on a plane changes with
respect to a change in the horizontal coordinate.
-slope is denoted by m.
-slope(m) = vertical distance between two points / Horizontal distance between two
points.
-slope is denoted by m.
-slope(m) = vertical distance between two points / Horizontal distance between two
points.
-Chord: The straight line that joins any two points in a circle is called a chord
- The foci(focus) are two fixed points equidistant from the center of the ellipse.
Chapter-3: Line Generation
1) Major axis: The major axis is the longest diameter of the ellipse, going through the
center from one end to the other, at the broad part of the ellipse. Half of major axis is
called semi-major axis
2) Minor Axis: the minor axis is the shortest diameter of ellipse, crossing through the cen-
tre at the narrowest part. Half of minor axis is called semi-minor axis.
-This type of effect is an error in line segment of image. This error is called aliasing.
(jagged line are known as aliasing).
-The process of removing aliasing error is called anti-aliasing. In other words, the process
of making image boundary smoother, is called anti-aliasing process.
-Methods of Anti-aliasing:
1) Super-sampling
2) Area sampling