Professional Documents
Culture Documents
DDA algorithm provides us mechanism of construction of lines lying in either m<1 region or m>=1
region. So, slope of the line is an important factor. On the basis of it we will follow two cases:-
Case 1: When slope of line is less than one Case 2: When slope of line is greater than one
(m<1) i.e. (X1-X0 >Y1-Y0) and X1-X0 >0 (m>1) i.e. (Y1-Y0 > X1-X0) and X1-X0 >0
In this we assume that x is increased by unit one In this we assume that y is increased by unit one
every time and we calculate the value of y for every time and we calculate the value of x for
every next pixel. every next pixel.
𝑑𝑦 𝑑𝑦
𝑚 = 𝑑𝑥 𝑚 = 𝑑𝑥
𝑚 = y1-y0/x1-x0 𝑑𝑦
𝑚 = 𝑌i+1 − 𝑌i / 𝑋i+1 𝑋i 𝑑𝑥 =
𝑚
𝑚 × ∆𝑥 = 𝑌i+1 − 𝑌i ∆𝑌
𝑌i+1 = 𝑚 + 𝑌i Xi+1 − 𝑋i =
𝑚
∆Y
𝑋i+1 = 𝑚 + 𝑋i
Note: For m<1 (horizontal span is more than 1
vertical span). Change in X-direction is more than 𝑋i+1 = + 𝑋i ⟦∴ ∆𝑦 = 1⟧
𝑚
the change in Y-direction.
Note: For m>1 (vertical span is more than
horizontal span). Change in Y-direction is more
than the change in X-direction.
DDA PSEUDO-CODE
DISADVANTAGE OF ALGORITHM
1. Accumulation of round-off errors can make the pixelated line drift away from what was intended.
2. The rounding operations and floating point arithmetic involved are time consuming.
𝑑𝑦
𝑚 = 𝑑𝑥 -----------------------------2
Putting equation 2 in 1
𝑑𝑦
Y=𝑑𝑥 𝑥 + 𝑏
Y 𝑑𝑥 =𝑑𝑦𝑥 + 𝑏 𝑑𝑥
F x, y 𝑑𝑦𝑥 -Y 𝑑𝑥 +𝑏 𝑑𝑥 =0
𝑑 = 𝑎𝑥 + 𝑏𝑦 + 𝑐
Case 1: when east point is chosen after plotting Case 2: when north-east point is chosen after
east pixel (if the midpoint is above the line) plotting east pixel (if the midpoint is below the
line)
ALGORITHM/FUNCTION
Void midline (int x0, int y0, int x1, int y1, int value)
{
Int x=x0;
Int y=y0;
Int 𝑑𝑥 = x1-x0;
Prepared By: Shilpa Taneja
IITM\ BCA-303 \ COMPUTER GRAPHICS\ UNIT- I
Int 𝑑𝑦 = y1-y0;
Int 𝑑 = 2𝑑𝑥 − 𝑑𝑦;
𝑑E=2𝑑y;
𝑑NE=2(𝑑y-𝑑x);
Putpixel(x,y,value);
While(x<=x1)
{
If (d<=0)
{
d=d+ 𝑑E;
}
Else
{
d=d+𝑑NE;
Y++;
}
X++;
Putpixel(x,y,value);
}
Example: Suppose we want to draw a line starting at pixel (20, 10) and ending at pixel (30,
18)
– Δx: 10 K Pk (xk +1, yk +1)
– Δy: 8 0 6 (21,11)
– 2Δy: 16 1 2 (22,12)
– 2Δy - 2Δx: -4 2 -2 (23,12)
– p0 = 2Δy – Δx = 6 3 14 (24,13)
4 10 (25,14)
5 6 (26,15)
6 2 (27,16)
7 -2 (28,16)
8 14 (29,17)
9 10 (30,18)
1. High accuracy: Comparing to Basic Incremental algorithm (especially if the slope were > 1.)
2. High speed: Comparing to Digital Differential algorithm.
𝑠 = 𝑦 − 𝑦𝑖 //s is distance
𝑡 = (𝑦𝑖 + 1) − 𝑦 //t is distance
On subtracting 2 from 1
𝑑𝑖 + 1 − 𝑑𝑖 = 2𝑑𝑦(𝑥𝑖 + 1 − 𝑥𝑖) − 2𝑑𝑥(𝑦𝑖 + 1 − 𝑦𝑖) [∴ 𝑥𝑖 + 1 = 𝑥𝑖 + 1]
𝑥𝑖 + 1 − 𝑥𝑖 = 1 [∴ 𝑑𝑖 + 1 = 𝑑𝑖 + 2𝑑𝑦 − 2𝑑𝑥(𝑦𝑖 + 1 − 𝑦𝑖)]
ADVANTAGE OF ALGORITHM
1. The Bresenham algorithm is fast incremental scan conversion algorithm
2. It uses only integer calculations
𝑥2 + 𝑦2 = 𝑟2
d = 𝑥2 + 𝑦2 − 𝑟2
𝐼𝑓 𝑑 > 0, 𝑡ℎ𝑒𝑛 𝑚𝑖𝑑𝑝𝑜𝑖𝑛𝑡 𝑙𝑖𝑒𝑠 𝑜𝑢𝑡𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒
𝒔𝒐, 𝒔𝒆𝒍𝒆𝒄𝒕 𝑺𝑬 Pixel
𝐼𝑓 𝑑 < 0, 𝑡ℎ𝑒𝑛 𝑚𝑖𝑑𝑝𝑜𝑖𝑛𝑡 𝑙𝑖𝑒𝑠 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒
𝒔𝒐, 𝒔𝒆𝒍𝒆𝒄𝒕 𝑬 Pixel
𝐼𝑓 𝑑𝑖 = 0, 𝑡ℎ𝑒𝑛 𝑚𝑖𝑑𝑝𝑜𝑖𝑛𝑡 𝑙𝑖𝑒𝑠 𝑜𝑛 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒
𝒔𝒐, 𝒔𝒆𝒍𝒆𝒄𝒕 𝑨𝑵𝒀 Pixel
yk
midpoint
yk-1
1
First Midpoint is (𝑥𝑝 + 1, 𝑦𝑝 − )
2
1
Second Midpoint is (𝑥𝑝 + 2, 𝑦𝑝 − )
2
𝐝𝐄 = 𝟐𝒙𝒑 + 𝟑
CASE 2: 𝑰𝒇 𝒅 > 𝟎 𝒂𝒏𝒅 𝒘𝒆 𝒏𝒆𝒆𝒅 𝒕𝒐 𝒔𝒆𝒍𝒆𝒄𝒕 𝐒𝐨𝐮𝐭𝐡 − 𝑬𝒂𝒔𝒕 𝒑𝒊𝒙𝒆𝒍 𝒂𝒇𝒕𝒆𝒓 𝒔𝒆𝒍𝒆𝒄𝒕𝒊𝒏𝒈 𝑬𝒂𝒔𝒕 𝒑𝒊𝒙𝒆𝒍
yk
midpoint
yk-1
1
First Midpoint is (𝑥𝑝 + 1, 𝑦𝑝 − 2)
3
Second Midpoint is (𝑥𝑝 + 2, 𝑦𝑝 − 2)
1 2
so, dold = (𝑥𝑝 + 1)2 + (𝑦𝑝 − ) − 𝑟 2
2
3 2
so, dnew = (𝑥𝑝 + 2) + (𝑦𝑝 − ) − 𝑟 2
2
2
2
3 1 2
dSE = (𝑥𝑝 + 2)2 + (𝑦𝑝 − ) − 𝑟 2 − [(𝑥𝑝 + 1)2 + (𝑦𝑝 − ) − 𝑟 2 ]
2 2
1
If the starting point for drawing the circle is (0,r) the coordinate for first midpoint will be (1, 𝑟 − 2)
1 2
So, dstart = (1)2 + (𝑟 − 2) − 𝑟 2
5
dstart = − r
4
𝐝𝐬𝐭𝐚𝐫𝐭 = 𝟏 − 𝐫
𝒅𝒔𝒕𝒂𝒓𝒕 = 𝟏 − 𝒓
𝐝𝐄 = 𝟐𝒙𝒑 + 𝟑
𝐝𝐒𝐄 = 𝟐𝒙𝒑 − 𝟐𝒚𝒑 + 𝟓
𝒅𝒊 = 𝑫(𝑺𝑬) + 𝑫(𝑬)
𝑑𝑖 = 𝐷(𝑆𝐸) + 𝐷(𝐸)
𝑑𝑖 = (𝑥𝑝 + 1)2 + (𝑦𝑝)2 − 𝑟 2 +
(𝑥𝑝 + 1)2 + (𝑦𝑝 − 1)2 − 𝑟 2
𝑑𝑖 + 1 = (𝑥𝑝 + 2)2 + (𝑦𝑝)2 − 𝑟 2 +
(𝑥𝑝 + 2)2 + (𝑦𝑝 − 1)2 − 𝑟 2
𝐸𝐴𝑆𝑇 = 𝑑𝑖 + 1 − 𝑑𝑖
𝑬𝑨𝑺𝑻 = 𝟒𝐗𝐏 + 𝟔
𝑑𝑖 = 𝐷(𝑆𝐸) + 𝐷(𝐸)
𝑑𝑖 = (𝑥𝑝 + 1)2 + (𝑦𝑝)2 − 𝑟 2 +
(𝑥𝑝 + 1)2 + (𝑦𝑝 − 1)2 − 𝑟 2
𝑑𝑖 + 1 = (𝑥𝑝 + 2)2 + (𝑦𝑝 − 1)2 − 𝑟 2 +
(𝑥𝑝 + 2)2 + (𝑦𝑝 − 2)2 − 𝑟 2
𝑆𝑂𝑈𝑇𝐻𝐸𝐴𝑆𝑇 = 𝑑𝑖 + 1 − 𝑑𝑖
𝑺𝑶𝑼𝑻𝑯𝑬𝑨𝑺𝑻 = 𝟒(𝐗𝐏 − 𝐘𝐏) + 𝟏𝟎
Consider case 1:
E (6,5) Consider case 2:
SE (6,4) E (6,5)
R (6,3.9) SE (6,4)
R (6,4.8)
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void disp();
float x,y;
int xc,yc;
void main()
{
int gd=DETECT,gm;
int a,b;
float p1,p2;
clrscr();
initgraph(&gd,&gm,"");
scanf("%d%d",&xc,&yc);
scanf("%d%d",&a,&b);
x=0;y=b;
disp();
p1=(b*b)-(a*a*b)+(a*a)/4;
while((2.0*b*b*x)<=(2.0*a*a*y))
{
CLIPPING
APPLICATIONS OF CLIPPING
1. Extracting part of a defined scene for viewing.
2. Identifying visible surface in 3D views.
3. Analyzing line segments or object boundaries.
4. Creating object using solid modeling procedures.
5. Drawing and painting operations that allow part of picture to be selected foe copying, moving,
erasing or duplicating.
Available algorithms for clipping on following Cohen primitives are:
1. Point clipping
2. Line clipping
3. Area clipping
4. Curve clipping
5. Text clipping
(Note: if in step2, both P1 and P2 are invisible, we have to first divide the line, take a visible point and
then repeat the algorithm twice for both the segments)
PL P1
PL
PE
PE
P0
• Because of horizontal and vertical clip lines:
– Many computations reduce
– Normals: (-1, 0), (1, 0), (0, -1), (0, 1)
• Pick constant points on edges
• solution for t:
– -(x0 - xleft) / (x1 - x0)
– (x0 - xright) / -(x1 - x0)
– -(y0 - ybottom) / (y1 - y0)
– (y0 - ytop) / -(y1 - y0)
Comparison
• Cohen-Sutherland
– Repeated clipping is expensive
– Best used when trivial acceptance and rejection is possible for most lines
• Cyrus-Beck
– Computation of t-intersections is cheap
– Computation of (x,y) clip points is only done once
– Algorithm doesn’t consider trivial accepts/rejects
Best when many lines must be clipped
INTRODUCTION TO CG
It is system software which is concerned with representing real and imaginary objects in the form of pictures.
This implies that CG is related to generation of pictures, defining it, storing it and presenting with the help of
algorithms. It performs conversion, transformation, projection, illumination, shading etc.
Computer Graphics allows communication through pictures, charts and diagrams. In today’s world person
does not have time to read huge number of pages; for e.g., to know the performance of business over a time
period. This problem can be solved using CG. A huge database can be represented by pictures; like bars, pie
charts which enables a person to understand the concept just at a glance.
IMAGE PROCESSING
This term is often related with CG but it is quite different from it. Image processing is concerned with
enhancing the quality of an image i.e. adjusting color, brightness, contrast etc.
Advantages: -
a) It eliminates more expensive mistakes.
b) User is able to view object in various forms such as wire-frame (skeleton view), or over all
view.
2. GIS (Geographic Information System): - It is a technique used for assembly, integration and
analysis of text, tabular data about natural and man-made feature and facilities for purpose of
better understanding, efficient analysis and faster decision making.
High level conceptual framework of interactive graphics consists of two main components; software
and hardware component where software part deals with application model, application program
and graphic system and hardware deals with computer devices like monitor, input and output
devices.
Application Model – It captures the object which is to be displayed on screen and it also maintains
the data about this object in a repository called as Application Database. This Application Database is
further referred by the application program. It is independent of display system.
Application Program – It creates application and it communicates with it to store the data and to
receive the data in the form of commands. It is also responsible for handling input and output
devices. It receives the input from user via input devices and then sends the command to graphics
system to display the object. It basically consists of the logic which tells what to display on screen.
Program extracts geometry and converts it to series of commands primitives of graphics system
Graphics system – It is responsible for actual displaying the object. I act as an interface between user
and hardware. It provides the user interface through which user can communicate easily with the
In simple black and white systems each screen point in either turned on or off. It requires only 1 bit
per pixel to control intensity of screen position. Additional bits are needed when colors are to be
displayed. For this purpose, 24 bits per pixel is used in high quality systems. If we are using 1 bit per
pixel then frame buffer is called as BitMap and if multiple bits are being used then it is known as
PixMap.
To draw any image frame buffer location is matched with screen positions. Screen origin may be
defined at lower left corner. X will get increase from left to right and y will get increased from bottom
to top. The first line which is scanned starts from top left corner of the screen i.e., from (0, y max) to (xmax,
ymax). Then y gets decremented for every next scan line. In the same manner x gets incremented by 1
for every scanned pixel. To scan whole line for this purpose video controller maintains x and y registers
to store coordinates of screen pixels. These all values are stored in frame buffer and are retrieved by
video controller to draw any image on screen starting from scanning first line to last line in each frame.
Screen is refreshed at 60 times per second. To speed up pixel processing video controller can retrieve
multiple pixel processing video controller can retrieve multiple values from refresh buffer on each pass.
In high resolution system two frame buffers are maintained. It is also used to perform transformations.
Disadvantage
To overcome second disadvantage a separate port has been given to access the frame buffer.
Raster display system with peripheral display processor.
This employs a separate graphic processor to perform graphics function such as scan conversion. It
also has a separate frame buffer. System holds data and those programs that run on CPU such as
application program. Display processor memory holds data plus program that perform scan
conversion and raster graphics operations.
Disadvantage
1. CPU does not have direct access to frame buffer.
2. To perform any change in graphics double buffering is required.
Figure: Aliased lines caused by the finite pixel size (left) and anti-aliased lines (right). Notice that the
anti-aliasing algorithm produces a somewhat "blurred" image.
There are several algorithms developed for anti-aliasing, the simplest is to increase the resolution.
Doubling the resolution in horizontal and vertical direction, will make the jags half in size and double
their numbers. They will look smoother, but this will quadruple the use of graphical memory, which
is expensive. There are other and cheaper ways to handle the problem. The simplest is called
unweighted area sampling. Consider lines (which are infinitely thin), they can be approximated as a
one pixel wide quadrilateral. The pixel values are given by the coverage of the quadrilateral. For each
pixel, the pixel value is given by A = A * degree-of coverage.
BASIC OPERATION
Primary component of an electron gun are heated metal cathode and a control grid. Heat is supplied
to the cathode by directing current through wire. Due to this free and negatively charged electrons
are accelerated towards phosphorus coated screen by a high positive voltage. The high positive
voltage is generated with a positively charged metal near the phosphorus screen or accelerating
anode can be used.
Intensity of electron beam is controlled by setting voltage level on control grid which is metal
cylinder that fits over cathode. Since amount of light emitted by phosphorus coating depends on no.
of electrons striking the screen. We can control brightness of display by varying voltage on control
grid.
Focusing system is required to force the electron beam to converge into a small spot. Otherwise
electrons would repel each other and beam would spread out. Focusing system is accomplished with
either electric magnetic field.
Additional focusing hardware is used in high precision system. The distance that beam travels to
different points on the screen varies. As the beam moves to outer edge of screen displaying image
becomes blurred. To compensate this system can adjust focusing according to screen position of the
beam.
1. Different kinds of phosphorus are available. Major difference between them exists due to
PERSISTENCE i.e., how long they continue to emit light after CRT beam is removed. It may also be
defined as time taken by emitted light from screen to decay to one tenth of original intensity. Lower
persistence phosphorus requires higher refresh rate to maintain a picture on the screen without
flicker.
2. Maximum no. of points that can be displayed without overlap on CRT is referred to as
RESOLUTION. It is no. of points per centimeters that can be plotted horizontally and vertically.
Resolution depends on type of phosphorus, intensity to be displayed focusing and deflection system.
3. ASPECT RATIO: - the no. gives the ratio of vertical points to horizontal points that are necessary
to produce equal length lines in both directions. Three fourth means that vertical line plotted with
three points has same length as a horizontal line plotting with four points.
COLOR CRT
Color CRT is based on either of two methods to emit light.
1. Beam penetration
This method is used in random scan monitors. It works in same way as normal CRT works but it uses
combinations of phosphorus to produce range of colors. In this CRT uses two layers of phosphorus
which are usually red and green. Displaying color depends upon how far the electron beam
penetrates into the phosphorus layers. Beam of slow electrons excites only red layers and that of fast
type electrons penetrates through red layer and excites inner green layer. At intermediate beam
speed orange and yellow colors are produced. So color depends upon beam acceleration voltage.
Advantage
1. Inexpensive
Disadvantage
1. Only four colors can be produced.
2. Quality of image is not good.
2. Shadow mask
Prepared By: Shilpa Taneja
IITM\ BCA-303 \ COMPUTER GRAPHICS\ UNIT- I
This method is used in raster scan system. This type of CRT uses 3 phosphorus color dots at each
pixels position to produce wide range of colors where one phosphorus element emits red, other green
and third blue color. I.e., it uses 3electron guns one for each color dot. It uses shadow mask grid
which is placed just behind phosphorus coated screen.
Delta-delta shadow mask method is used commonly. In this 3electron beam are deflected and
focused as a group onto shadow mask which contains series of holes aligned with the dot.
Combinations of these 3beam activate a dot triangle which appears as a small spot on screen.
Another method used is known as inline. In this method colored guns and dots are arranged along
one scan line. This is much easier way and is used high resolution CRT. Color variation is obtained
with the help of varying the intensity level of 3electron beams. By turning off red and blue we will
get only green color. Colors also depend on amount of excitation RGB phosphorus for e.g., white is
produced when equal intensity of RGB is used. Yellow is produced when only green and red are
used.
DIRECT VIEW STORAGE TUBE (DVST)
DVST provides us an alternative method for maintaining the screen image that is to store that image
inside CRT itself instead of refreshing the screen.
For this purpose DVST uses two electron guns one for storing the picture and another for maintain
the display by emitting low speed electrons which does not affect the picture being displayed but
actually provides strength.
ADVANTAGES
1. No refreshing is required.
2. Complex picture can be displayed without flickering.
DISADVANTAGE
1. It cannot display colors.
NON- EMMISIVE
1.) LCD (liquid crystal display)
It display picture either by passing polarized light from surrounding or it uses internal light source
through liquid crystal material. It uses compounds which have crystalline arrangement of molecules
but they flow like liquid. It uses two glass plates when one has vertical conductor and other has
horizontal conductor and in between these plates we have liquid material which produces light when
voltage is supplied to conductors. Refresh rate used is 60.