SlideShare a Scribd company logo
PROGRAM NO – 01

OBJECT

Date……………………

TO DEVELOP THE CONCEPT OF COMPUTER GRAPHICS USING „C‟.
INTRODUCTION
Computer Graphics is one of the most powerful and interesting facet of computer.
There is a lot that one can do in graphics apart from drawing figures of various shapes.
All video games, animations, multimedia predominantly works using Computer Graphics.
This introductory too will give feeling of how some of these things are achieved using
C. The aim is to make the readers comfortable with the basic concepts in graphics,
Introduce themselves with standard library graphics functions and then let them explore
On their own to implement certain algorithm of elementary drawing using Computer
Graphics.

Instead of discussing each Standard Library, graphics function in detail, most
Commonly use functions and standard library files are put in the following program.

SAMPLE PROGRAM
#include<graphics.h>
#include<conio.h>

void main()
{
int gd=DETECT,gm,x,y;
int array[]={540,220,590,270,320,510,320,490,270,540,220};
initgraph(&gd,&gm,””);
x=getmaxx();
y=getmaxy();

setcolor(WHITE);
rectangle(x/30+15,y/20,x/5,y/4);
outtextxy(x/30+15,y/8+5,”Rectangle”);

circle(x/2,y/6,75);
putpixel(x/2,y/6,WHITE);
outtextxy(x/2-textwidth(“Circle”)/2,y/6+10,”Circle”);

arc(x/1.2,y/6,300,90,80);
outtextxy(x/1.2,y/6,”Arc”);

line(x/30,10*y/15,x/6.10*y/15);
outtextxy(x/30+10,10*y/15+10,”Line”);

ellipse(x/2,10*y/17,0,360,100,50);
putpixel(x/2,10*y17,WHITE);
outtextxy(x/2-textwidth(“Ellipse”)/2,10*y/17+10,Ellipse”);

getch();
closegraph();
restorecrtmode();
return;
}//End of main function

DESCRIPTION OF PROGRAM
Whenever any drawing is started in graphics mode a header file „GRAPHICS.H‟
And library file „GRAPHICS.LIB‟ is required. The header file contains definitions and
Explanation of all the functions and constants whereas the graphics functions are kept in
The graphics library file. Both of these files are provided as part of TURBOC.

Before any drawing can be carried out, it is required to switch over to the
Graphics mode from the text mode. Switching depends on the adapter and monitor may
Be available with us. These modes have been given numbers. Out of all the modes
Available, we would like to switch over to the one which offers the best possible
Resolution.
The number of dots or picture elements or pixels available to us on the screen in
The graphics is known as the resolution. The greater the number of dots, the higher will

be the resolution. It means more the dots available clearer would be our picture.

To switch over to the graphics mode that offers the best resolution we need to call
The function initgraph(). It figures out the best resolution and puts the number
Corresponding to that mode in the variable “gm”. The „gm‟ number tell us which monitor
We are using, and its resolution, the number of video pages it supports and the colors that
are available.
A color monitor driven by VGA adapter, the maximum resolution of which is
640 x 480 (i.e. 640 pixels from left to right and 480 pixels from top to bottom).

To understand „gd‟ we need to understand the concept of device drivers. Device
Drivers are small programs, which talk directly to the hardware. Since we can‟t be
machine dependent at any time, we need program to communicate with in a standardized
way. These programs in turn communicate with the machine. The intermediary
programs are known as device drivers.

Graphics drivers are a subset of device drivers and are applicable only in the
graphics mode. They work in the above fashion to execute whatever task we have
assigned them. TURBOC offers certain graphics drivers. These are the files with a BGI
extension. Depending on what adapter is used, one of these drivers gets selected. The
sample programs have been developed on the VGA adapter. Thus EGAVGA.BGI files
are required as graphics drivers.

In the above program „gd‟ has been assigned the value DETECT. There by asking
Initgraph() to figure out which BGI file is needed. This file is then loaded into
Memory. If we do not initiate with DETECT macro then it is our responsibility to set up
„gd‟ and „gm‟ with appropriate value.

The moment we change over to the graphics mode two things happens. Firstly,
The cursor disappears, since the graphics mode does not support the conventional cursor.
Secondly, a coordinate system is established whereby thetop left corner to the screen is
treated as origin (0, 0). As usual, the x – axis goes horizontally across, and the y-axis
goes vertically downward.

The basic tools we will need for drawing shapes are functions like putpixel(),
Line(), ellipse(), arc(), drawpoly() etc. All these functions have been used in the above
Sample program. Their general form is as follows:

Table 1.0 Details of the Function

SN

Function

Meaning

01

getmaxx()

Fetches max value of x coordinate

02

getmaxy()

Fetches max value of y coordinate

03

setcolor

Sets the color for objects

04

rectangle()

Draws rectangle using top left and right bottom
Screen coordinates

05

circle()

Draws circle using x,y coordinate of center and
Radius

06

ellipse()

Draw ellipse using x,y coordinate of the
Intersection of major minor axis, start angle, end
Angle, x radius and y radius

07

arc()

Draws are using x,y coordinate of the center, start
Angle, end angle and radius of arc

08

Line()

Draws line using end point of the line

09

drawpoly()

Draws polygon using no of vedrtices and their
Coordinates
10

putpixel()

Put a pixel at given location using the given color

11

outtextxy()

Writes a string at the given location

Note: Two functions getmaxx() and getmaxy() have ben used in the above sample
Program, readers may change it and make user interactive before switching to the
Graphic mode imposing the limitation of the maximum resolution of given graphics
Adapter.

INPUT

OUTPUT

GRAPH

THEORETICAL QUESTIONS
1)
2)
3)
4)
5)

Write the syntax of function initgraph().
What is the significance of function initgraph()?
What is a pixel ?
What is maximum resolution of a VGA adapter ?
What is the syntax of function closegraph() and why is it used ?

OBJECTIVE QUESTIONS
1) DETECT is a
a)functions b) macro c) subroutine d) procedure 2) getmaxx() fetches
maximum a) x-coordinate b) y-coordinate c) z-coordinate d) r-O
coordinate 3) No of arguments passed to the function putpixel () is a)1 B)2
c)3 d) 4
4) The value of the third parameter passed to the function circle() related
to
a) x-coordinate of center b) radius of circle c) y-coordinate of circle d)
diameter of circle
5) To draw a rectangle which function can be used instead of rectangle ()
function a) circle b) ellipse c) line d) drawpoly
PROGRAM NO. 02
OBJECT

Date……………....

WAP TO IMPLEMENT THE DDA LINE DRAWING ALGORITHM
ALGORITHM
An algorithm is a well-defined sequential set of mathematical and logical
operations which, when implemented (or performed), produces the
solution of a given mathematical problem.
In feeding numerical data and in processing – which involves
implementation of algorithms and the final output of the result – two types
of errors are generally introduced. They are truncation errors and
rounding off errors. Besides these, errors in the implementation of the
algorithm must be taken into account. (nm/6)
1. Read the line end point (x1,y1) and x2,y2) such that they are not equal.
(if
Equal then plot that point and exit)
2. dx = |x2 –x1| and dy = |y2-y1|
3. if (dx>=dy) then
length = dx
else
length = dy
endif
4. dx = (x2-x 1)/length
dy = (y2-y1)/length
(This makes either dx or dy equal to 1 because length is either |x2-x1| or
|y2-y|. Therefore, the incremental value for either x or y is one)
5. x = x1 + 0.5* sign(dx)
y= y1 + 0.5* sign(dy)
(here,sign function make s the algorithm work in all quadrant. It
returns
-1,0,1 depending on whether its argument is <-,=0,>0 respectively.
The
Factor 0.5 makes it possible to round the values in the integer function
rather than truncating them).
6. i=1 (Begins the loop, in this loop points are plotted)
While (i<=length)
{ plot (integer(x), integer (y))
x=x+dx
y=y+dy
i=i+1 }
7. Stop

SAMPLE PROGRAM
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float x,y,x1,y1,x2,y2,dx,dy,length;
int i,gd,gm;
int xref=0,yref=400;
clrscr();
/*Read two end points one line
------------------------------------*/

printf(“Enter the value of x1 :t”);
scanf(“%of”.x1);
printf(“Enter the value of y1 :t”;
scanf(“%of,&y1)
printf(“Enter the value of x2 :t”);
scanf(“%of,&x2);
printf(“Enter the value of y2 :t”);
scanf(“%of,&y2);

/* Initialise graphics mode
------------------------------ */
detectgraph(&gd &gm);
initgraph(&gd,&gm””);

dx=abs(x2-xx1);
dy=abs(y2-y1);
if (dx >=dy)
{
length = dx;
}
Else
{
length =dy;
}
dx = (x2-x1)/length;
dy = (y2-y1)/length;
x = x1 + 0.5; /* Factor 0.5 is added to round the values */
y = y1 + 0.5;/* Factor 0.5 is added to round the values */

i =1; /* Initialise loop counter */
while (i<=length)
{
putpixel(x-xref,yref-y,15);
x = x+ dx;
y = y+dy;
i= i + 1:
delay(100);/* Delay is purposely inserted to see
Observe the line drawing process*/
}
getch();
closegraph();
}
INPUT
OUTPUT
GRAPH
THEORETICAL QUESTIONS
1.
2.
3.
4.
5.

What are the merits of DDA algorithm ?
What are the limitations of DDA algorithm ?
Name any other line drawing algorithm
What is aliasing ?
Can the equation y = mx + C be used effectively to calculate
the pixel position ? Explain

OBJECTIVE QUESTIONS
1. DDA is a technique for
a) Scan conversion b) Image conversion c) Graphics conversion d) All of
these……………… of a line
2. Which parameter decides the selection of equation for the
calculation of coordinates in DDA algorithm.
a)m b)|m| c) +m d)-m
3.

The name of algorithm used for line drawing is
a) Bresenham b) Cohen sutherland c) Z-buffer d) Liang Barsky
4.

DDA algorithm is faster than
a) Conventional method (y = mx + C) b) Bresenham‟s Line drawing algo
c) Bresenham‟s circle d) Mid point circle algo

5.

Pixel position of various coordinate are calculated using
a) Absolute referencing b) Relative referencing
c) Logarithmic referencing d) Exponential referencing
PROGRAM NO. 03
OBJECT

Date………………..

WAP TO IMPLEMENT BRESENHAM‟S LINE DRAWING ALGORITHM
ALGORITHM
1. Read the line end points (x1,y1) and (x2,y2) such that they are not equal. (If equal
then
Plot that point and exit)
2. dx =|x2-x1| and dy = |y2-y1|
3. Initializing starting point
X = x1
Y = y1
4. E = 2 * dy – dx
(Initialize value of decision variable or error to compensate for non zero intercepts)
5. I= 1 (initialize couter)
6. Plot (x,y)
7. While (e>=0)
{
y+1
e = e-2 *dx
}
x= x+1
e=e+2* dy
8. 1=1+1
9. If (1<=dx then to step 6
10. Stop
SAMPLE PROGRAM
#include<stdio.h>
#include <graphics.h>
#include<math.h>
#include<dos.h>
main()
{
float x,y,x1,x2,y2,dx,dy,e;
int I,gd,gm;
int xref=0,yref = 400;
clrscr();
/* Read two end points of line
………………………………….. */
printf (“Enteer the value of x1;t);
scanf(“%of,&x1);
printf(“Enter the value of y1 :t”):
scanf(„%of,&y1;
printf(„Enter the value of x2 :t‟)
scanf(„%of &x2);
printf(„Enter the value of y2 :t”);
scanf(“%of &y2);
/* Initialise graphics mode
…………………………………*/
detectgraph(&gd,&gm);
initgraph(&gd,&gm,””);
dx=abs(x2-x1);
dy=abs(y2-y1);
/*Initialise starting point
…………………………….. */
x=x1;
y=y1;
/* Initialise decision variable
…………………………………. */
e=2*dy-dx;
i=1;/*Initialise loop counter */
do
{
putpixel(x-xref,yref,15);
While (e>=0)
{ y=y+1;
e=e-2 *dx;
}
x=x+1
e=e+2*dy:
i=i+1;
delay(100)
}while (i<=dx);
getch();
closegraph();
}
INPUT
OUTPUT
GRAPH
THEORETICAL QUESTIONS
1. What are the merits of Bresenham‟s algorithm over the DDA algorithm?
2. Write the equation of decision parameter used in Bresenham‟s line drawing
algorithm.
3. What are the limitations of Bresenham‟s line drawing algorithm/
4. Name three line drawing algorithm
5. What type of calculations are used in the Bresenham‟s line drawing algorithm/
OBJECTIVE QUESTIONS
1. The proposed algorithm is applicable for the range of values of m
a) -1 to 1 b) 0 to 1 c) 1 to 0 d) 0 to -1
2. The line algorithm which can be generalized easily for ellipse and conic
a)Bresenham b)DDA c)Midpoint d) Franklin

3. Bresenham line drawing algorithm is faster than
a) DDA b) Conventional method 9y = mx + C) c) Polar method d) All of these

4. The use of Bresenham algorithm avoids
a) Round Function b) Floating point addition c) Both a & b d) Either of a and b

5. Which is not a line drawing algorithm
a) Bresenham b) DDA c) Mid point d) End point
PROGRAM NO. 4
OBJECT

Date………………...

WAP TO IMPLEMENT BRESENHAM‟S CIRCLE DRAWING ALGORITHM
ALGORITHM
1. Read the radius ® of the circle.
2. d =3-2r(Initialize starting point)
3. x=0 y=r (Initialize starting point)
4. Do
{
Plot (x,y)
If (d<0) then
{
D = d+4x+6
}
Else
{
d=d+4(x-y)+10
Y=y-1
}
X=x+1
While (x<y)
5. Stop

SAMPLE PROGRAM
#include<stdio.h>
#include<graphics.h>
#include<math.h>
void main()
{
float d;
int gd,gm,x,y;
int r,tim;
clrscr();
/*Read the radius of the circle
………………………………. */
printf(“Enter the radius of a circle :”);
scanf(“%d”,&r);
printf(“Enter the Time delay (milli second):”);
scanf(“%d”,&tim);
/*Initialise graphics mode
-----------------------------*/
detectgraph(&gd,&gm);
initgraph(&gd,&gm,” ”);
/*Initialise starting points
-----------------------------*/
x=0;
y=r;
/*initialise the decision variable
-----------------------------*/
d = 3 – 2 *r;
do
{

putpixel(200+x,200+y,15);

putpixel(200+x,200+y,15);
putpixel(200+y,200+x,15);
putpixel(200+y,200-x,15);
putpixel(200+x,200-y,15);
putpixel(200-x,200-y,15);
putpixel(200-y,200-x,15);
putpixel(200-y,200+x,15);
putpixel(200-x,200+y,15);
if(d<=0)
{
d=d+4*x+6;
}
Else
{
d =d+4*x+6;
}
d=d+4(x-y)+10;
y= y-1;
}
x = x+1;
delay(tim); /*Delay is purposely inserted to see
observe the line drawing process */
}
while(x<y);
getch();
closegraph();
return;
}
Note:- The algorithm plots 1/8 of the circle.
INPUT
OUTPUT
GRAPH
THEORETICAL QUESTIONS
1. What is the generalized equation of a circle with center at origin and radius „r‟ ?
2. Write trigonometric equation to draw a circle.
3. What is the difference between Bresenham‟s circle drawing algorithm and other
Conventional equations?
4. Name any other algorithm for circle drawing.
5. Write the equation of decision parameter for circle drawing using Bresenham‟s
Circle drawing algorithm?
OBJECTIVE QUESTIONS
1. In the above algorithm pixel positions are calculated for
a) Semi-quarter circle b) Quarter circle
b) Half circle d) Full circle
2. Which not a circle drawing algorithm
a)Bresenham b) DDA c) Mid point d) Franklin
3.

To draw complete circle using Bresenham‟s circle drawing algorithm
a) 8 – way symmetry b) 4 – way symmetry
c) 2 – way symmetry d) 1-way symmetry

4.

The above method generates the pixel position for a circle having it center at
a) Origin b) x-axis c) y-axis d) At the center of reference frame

5.

Which of the following transformation may be required to calculate the pixel
Position of the circumference of a circle whose center is not at origin
a) Flip b) Move c) Rotate

d) Scale
PROGRAM NO. 05
OBJECT

Date………………………

WAP TO IMPLEMENT MID – POINT CIRCLE DRAWING ALGORITHM
ALGORITHM
u
1. Read the radius ® of the circle
2. Initialize starting position as
x=0
y=0
3. Calculate initial value of decision parameter as
P = 1.25 – r
4. do
{
Plot(x,y)
If (d <0)
{
x=x+1
y=y
d = d + 2x + 1
else
{
x = x+1
y=y–1
d = d + 2x + 2y + 1
}
while (x <y)
5. Determine symmetry points
6. Stop
SAMPLE PROGRAM
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float p;
int i,gd,gm,x,y;
int r;
/* initialize graphics
……………………….. */
detectgraph(&gd,&gm);
initgraph(&gd,gm,””);
/* Read the radius
……………………. */
printf(“Enter the radius of the circle ;”);
scanf(“%d”,&r);
x=0;
y=r;
p=1.25 – r;
do
{
putpixel(200+x,200+y,15);
putpixel(200+y,200+x,15);
putpixel(200+x,200-y,15);
putpixel(200+y, 200-y,15);
putpixel(200-x,200-y,15);
putpixel(200-x,200+y,15);
putpixel(200-y,200+x,15);
putpixel(200-y,200-x,15);
if (p < 0)
{
x+ x+1;
y=y
p=p+2*x + 2;
}
else
{
x =x+1
y=y-1
p=p+2*(x-y)+1;
}
delay(10000);
}
while(x <y);
getch();
closegraph();
}
INPUT
OUTPUT
GRAPH
THEORETICAL QUESTION
1.
2.
3.
4.
5.

What is Staircase effect?
Write the equation of decision parameter used in Mid-Point circle drawing algorithm
What is the difference between this and Bresenham‟s circle drawing algorithm?
Name the method is used to draw a full circle in mid-point circle drawing algorithm?
Name any two circle drawing algorithm.
OBJECTIVE QUESTIONS
1. The pixel positions calculated using this and Bresenham‟s circle algorithm are
a) Exactly same b) Different c) Partially different
d) Depends on origin selection

2. Which of the following algorithm can be easily extended to ellipse and conic sections
a) Mid-Point
b) Bresenham
c)DDA
d) All of these
3. The ill effects of the scan conversion is removed by
a) Anti-aliasing b) aliasing c) Staircase d) Jaggies
4. The functional value at the mid point between two pixels is evaluated to determine
which
Pixel out of the two should be plotted in
a) Bresenham b) DDA c) Mid-point d)Hodgman algorithm
5. Which is not a method of Anti-aliasing
a) Increrasing resolution
b) Weighted are sampling c) pixel phasing d) Decreasing
resolution.
PROGRAM NO.06
Date ………………..

OBJECT
WAP TO DRAW BEZIER CURVE
ALGORITHM

1. Read no control points
2. Read the coordinate of control points
3. Generate Parametric equation to calculate
4. A) x – coordinate of the curve
5. B)y – coordinate of the curve
6. Using the Generalized equation for the Bezier curve
7. Select suitable increment in the parameter „u‟.
8. Iterate to get the various points of curve using equation 3a) and 3b).
9. Store the points in array
10. Plot the points.
11. Stop
The Generalized Parametric Equation of the Bezier Curve is

Where
1.
2.
3.
4.
5.

0< = u <=1
N = Degree of Polynomial
n =No of control points
N=n-1
Pk = The x/y coordinate of control

SAMPLE PROGRAM
#include<stdio.h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<process.h>
#include<iostream.h>

Point.
#include<math.h>

void Init Graph();
void Draw Point (int x, int y, int clr);
double fact (double x);

void main()
{
int i,k,counter;
float u,incr,factor;
/*
float Px[5]={60,80,150,180,0};
float Py[5]={20,100,90,50,0};
*/
/*
//Parabola
floatPx[5]={9,0,9,180,0}
float Py[5]={-6,0,6,50,0};
*/
//Circle
float Px[11]={10,8,6,7,0,-7.07,-10,-7.07, 0,7.07,8.6,10};
float Py[11]={0,5,7.07,10,7.07, 0,-7.07,-10,-7.07,-5,0}
//Give Due care to Control Points
int ctrl-pt;
float tPx,tPy;
int Xo,Yo;
float Sx,Sy;
FILE *fp;

Clrscr();
//Variable initialization
Incr = 0.01;

ctrl –pt=11;

Sx=15; Sy=15;

tPx=Px[0];

tPy=Py[0];

counter=1;

xo=100;

Yo=250;

fp=fopen(“bzr.txt”,”w”)
// Note we are initializing the tPx and tPy with the starting value of the
//control point because pow(0,0)give domain error and also it is useless
//to do calculation for the first point

//End of variable initialization
Ctrl pt--;

//Because counting starts from zero;

Init-Graph();
for u=incr;

u<=1;

u+=incr)

{
fprintf(fp,”%4d X=%8.2f| Y=%8.2fn”,counter++,tPx,tPy);
Draw Point (Xo+Sx*tPx,Yo-Sy*tPy,9);
tPx=0; tPy=0

//Resetting the tPx,tPy for the next calculation

for9K=0; k<=ctrl-pt; k++)
{
Factor=fact(ctrl-pt)/(fact(k) * fact(ctrl-pt-k));
tPx+=factor*pow(u,k) *Px[k]* pow(1-u),(ctrl-pt-k));
tPy+=factor*pow(u,k)*Py[k]* pow(1-u),(ctrl-pt-k));
}//End of inner for loop
}//End of outer for loop
fclose(fp);
getch();
return;
}//End of the main

double fact(double x)
{
If (x<1)

Return 1;
double factorial;
factorial = x
while (x > 1)
factorial = factorial*(--x);
return factorial;
}//End of the function
void Init-Graph()
{
int xmax,ymax,
int gdriver = DETECT, gmode, errorcode;
/*initialize graphics and local variables */
initgraph(&gdriver,&gmode,”c.turboc”);

/*read result of initialization */
errorcode = graphresult();
/*an error occurred */
If (errorcode !=grOk)
{
printf(“Graphics error: %sn”, grapherrormsg(errorcode));
printf(“Press any key to halt:”);
getch();
exit(1);
}
setbkcolor(0);
return;
}
void Draw Point (int x, int y, int clr)
{
putpixel(x,y,clr);
putpixel(x+1,y,clr);
putpixel(x-1,y,clr);
putpixel(x,y-1clr);
putpixel(x,y+1,clr);
}
INPUT
OUTPUT
GRAPH
THEORETICAL QUESTIONS
1.
2.
3.
4.
5.

What are the properties of Bezier curve?
What is the difference between the Bezier curve and Splines?
Write the parametric equation for ellipse, parabola and hyperbola.
Write the parametric equation of Bezier curve using four control points
Write the Generalized parametric equation for Bezier curve.

OBJECTIVE QUESTIONS
1. Bezier curve always passes through
a) First and last control point b)First and second control point
c)Only mid control point d) Any control point except mid
2. The relation between degree of polynomial (DOP) and the no of control points (noc) is
a) DOP=noc+1

b) DOP = noc-1 c)DOP=In(noc)

d) DOP =noc

3. The no.of control points in a cubic Bezier curve will be
a)1

b)2

c)3

d)4

4. The two basic type of parametric curves are
a) Interpolation and approximation

b) Extrapolation and approximation

c) Interpolation and extrapolation

d)Approximation & substraction

5. Bezier curve is an example of
a) Interpolation
d)Substraction

b)Approximation

…………type of parametric curve.

c)Extrapolation
PROGRAM NO.07
Date…………………

OBJECT

WAP TO IMPLEMENT COHEN SUTHERLAND LINE CLIPPING ALGORITHM

ALGORITHM
1. Read two end points of the line say P1(x1,y1) and P2(x2,y2).
2. Read two corners (left-top and right bottom) of the window, say (Wx1,Wy1 and
Wx2,Wy2).
3. Assign the region code for two end points P1 and P2 using following steps
;

Initialize code with bits 0000
Set Bit 1 – if (x < Wx1)
Set Bit 2 – if (x > Wx2)
Set Bit 3 – if (y < Wy2)
Set Bit 4 – if (y > Wy1)
4. Check for visibility of line P1 P2
a) If region codes for both tow endpoints P1 and P2 are zero then
the line is completely visible. Hence draw the line and go to
step 9.
b) If region codes for endpoints are not zero and the logical
ANDing of them is also nonzero then the line is completely
Invisible, so reject the line and go to step 9.
c) If region codes for two endpoints do not satisfy the conditions in
4a) and 4b) the line is partially visible.
5. Determine the intersecting edge of the clipping window by inspecting the region
codes of
two endpoints.
a) If region codes for both the end points are non zero, find
Intersection points P1‟ and P2‟ with boundary edges of clipping
window with respect to point P1 and Point2 respectively.
b) If region code for any one end point is non zero then find
Intersection point P1 or P2‟ with the boundary edge of the
Clipping window with respect to it.
6. Divide the line segment considering intersection points
7. Reject the line segment if any one end point of it appears outside the clipping
window.
8. Draw the remaining line segment.
9. Stop.
SAMPLE PROGRAM
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<math.h>
#include<graphics.h>
/* Defining structure for end point of line */
typedef struct coordinate
{
int x,y;
char code [4];
} PT;
void draw window ()
void draw line (PT p1, PT p2, int cl);
PT setcode(PT p);
int visibility (PT p1,PT p2);
PT resetendpt(PT p1,PT p2);
main()
{
int gd=DETECT,GM,V;
PT p1,p2,ptemp;
intigraph(&gd,gm,””)
cleardevice();
printf(“nnttENTER END POINT 1 (x,y):”);
scanf(“%d,%d,&p1,x,&p1.y);
printf(“nntt ENTER END POINT 2 (x,y):”);
scanf(“%d”&p2.x,&p2.y);
cleardevice();
drawwindow();
getch();
drawline(p1,p2,15);
getch();
p1 = setcode(p1);
p2=setcode(p2);
v=visibility(p1,p2);
switch(v)
{
case 0: cleardevice();/* Line completely visible */
drawwindow();
drawline(p1,p2,15);
break;
case 1: cleardevice();/* Line completely invisible */
drawwindow();
break;
case 2: cleardevice(); /* line partly visible */
p1 = resetendpt(p1,p2);
p2=resetendpt(p2,p1);
drawwindow();
drawline(p1,p2,15);
break;
getch();
closegraph();
return(0);
}
/*Function to draw window */
void drawwindow()
{
/*Function to draw line between two points
……………………………………………………….*/
void drawline (PT p1,PT p2, int cl)
{
setcolor

(RED);

line(150,100,450,100);
line(450,100,450,350);
line(450,350,150,350);
line(150,350,150,100);
}
/*Function to draw line between two points
----------------------------------------------------*/
void drawline(PT p1,PT p2,int cl)
setcolor(cl);
line(p1.x,p1.y,p2.x,p2.y);
}
/*Function to set code of the coordinates
…………………………………………………………..*/
PT setcode(PT p)
{
PT ptemp;
If (p.y<100)
ptemp.code[0]=‟1‟;/*TOP*/
else
ptemp.code[0]=‟0‟;
if (p.y<350)
ptemp.code[1]=‟1‟;/*BOTTOM*/
else
ptemp.code[1]=‟0‟;
if(p.x>450)
ptemp.code[2]=‟1‟/* RIGHT */
else
ptemp.code[2]=‟0‟
if (p.x<150)/* LEFT */
ptemp.code [3]=‟1‟
else
ptemp.code[3]=‟0‟
ptemp.x=p.x;
ptemp.y=p.y;
return(ptemp);
}
/* Function to determine visibility of line
……………………………………………. */
int visibility (PT p1, PT p2)
{
int i, flag=0;
for(i=0;i<4;i++)
{
if(pl.code[i]!=‟0‟)||(p2.code[i]!=‟0‟))
flag=1;
}
if(flag= =0)
return (0);
for(i=0;i<4;i++)
{
if(p1.code[i]=p2.code[i]) &&(p1.code[i]=‟1‟))
flag=0;
if (flag =0)
return(1);
return(2);
}
/* Function to find new end points
…………………………………………….*/
PT resetendpt (T p1,PT p2)
{
PT temp;
int x,y,I;
float m,k;
if (pl.code[3]=‟1‟/*Cutting LEFT Edge */
x=150;
If(pl.code[2]=‟1‟)/*Cutting RIGHT Edge */
x=450
If(pl.code[3]=‟1‟)||(pl.code[2]=‟1‟))
{
m=(float)(p2.y-pl.y)/(p2.x-pl.x);
k=(pl.y+(m*(x-pl.x)));
temp.y=k;
temp.x=x;
for(i=0;i<4;i++)
temp.code[i]=pl.code[i];
if(temp.y<350&&temp.y>=100)
return(temp);
}
If (p1.code[0]=‟1‟)/*Cutting TOP Edge */
y=100;
if(pl.code[1[=‟1‟)/* Cutting BOTTOM Edge */
y=350;
{
If(pl.code[0]=‟1)||(pl.code[1]=1))
{
m=(float)(p2.y-p1.y)/(p2.x-p1.x);
k=(float)pl.x+(float)(y-pl.y)/m;
temp x=k;
temp.y=y;
for(i=0;i<4;i++)
temp.code[i]=p1.code[i];
return(temp);
}
else

return(p1);
}

INPUT
OUTPUT
GRAPH
THEORETICAL QUESTIONS
1.
2.
3.
4.
5.

What is point clipping ?
What is line clipping ?
Name any two line clipping algorithm ?
What is Region code or Outcodes ?
What is Scissoring ?
OBJECTIVE QUESTIONS
1. The process of selecting and viewing the picture with different views is called
a) Windowing b) Clipping c) Normalizing
d) Viewing
2. A process which divides each element of the picture into its visible and invisible
portion, allowing the invisible portion to be discarded is called
a) Windowing b) Normalizing
c) Clipping d) Viewing
3. Cohen-Sutherland‟s 2D line clipping approach is a
a)Parametric approach
b) Non-Parametric approach
c)Geometric approach
d)Logarithmic approach
4.

The no of bit used to generate Outcode for a given coordinates are
a) 2

b)4

c)6

d)8

5. Cohen Sutherland line clipping algorithm computes the Outcode of
a) End Points

b) Mid point c) Any two consecutive point

d)Both a and b …..of a line
PROGRAM NO.08
Date………………

OBJECT

WAP TO IMPLEMENT MID POINT SUB-DIVISION LINE CLIPPING
ALGORITHM
ALGORITHM
1. Read two end points of the line say P1(x1,y1) and P2(x2,y2)
2. Read two corners (left – top and right bottom) of the window, say (Wx1, Wy1 and
Wx2,Wy2).
3. Assign region codes for two end points using following steps:
Initialize code with bits 0000

Set

Bit 1

-

if (x<Wx1)

Set

Bit 2

-

if (x> Wx2)

Set

Bit 3

-

if (y< Wy1)

Set

Bit 4

-

if (y> Wy2)

4. Check for visibility of line
a) If region codes for both endpoints are zero then the line is completely visible.
Hence
Draw the line and go to step 6.
b) If region codes for endpoints are not zero and the logical ANDING of them is
also
Non-zero then the line is completely invisible, so reject and the line and go to step
6.
c) If region code for two endpoints do not satisfy the conditions in 4a) and 4b) the
line is
Partially visible.
5. Divide the partially visible line segment in equal parts and repeat steps 3 through 5
for both
Subdivided line segments until you get completely visible and completely invisible
line segments.
6. Stop.
SAMPLE PROGRAM
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<math.h>
#include<graphics.h>
/* Defining structure for end point of line */
Typed of struct coordinate

{
int x,y;
char code[4];
} PT;
void drawwindow();
void drawline (PT p1, PT p2, int cl);
PT setcode(PT p);
int visibility (PT p1, PTp2);
PT resetendpt(
main()
{
Int gd=DETECT,gm,v.
PT p1,p2,ptemp;
intigraph(&gd,gm,‟‟);
cleardevice();
printf(„nnttENTER END POINT 1(x, y”);
scanf(“%d,%d”.&p1,x,&pl.y);
printf(“nntENTER END POINT 2 (x, y):”)
scanf(“%d,%%d,”,&p2,x,&p2.y);
cleardevice()
drawwindow();
getch();
drawwindow()
midsub(p1,p2);
getch();
closegraph();
return(0);
}
midsub(PT p1,PT p2)
{
PT mid;
int v;
p1=setcode(p1)
p2=setcode(p2);
v=visibility(p1,p2);
switch(v)
{
case 0;/*Line completely visible *//
drawline(p1,p2,15);
break;
case 1: /* Line completely invisible */
break;
case 2: /* line partly visible */
mid.x=p1.x + (p2.x-p1.x)/2;

mid.y=p1.y + (p2.y-p1.y)/2;
midsub(p1,mid);
mid.x=mid.x+1:
mid.y=mid,y+1;
midsub(mid,p2);
break;
}
}
/*Function to draw window */
void drawwindow()
{
setcolor(RED);
line(150,100,450,100);
line(450,100,450,400);
line(450,400,150,400);
line(150,400,150,100);
/* Function to draw line between two points
-------------------------------------------------*/
void drawline (PT p1,PT p2,int cl)
{
setcolor(cl);
line(p1.x,p1.y,p2.x,p2.y);
}
/* Function to set code of the coordinates
---------------------------------------------*/
PT setcode(PT p)
{
PT ptemp;
if(p.y<=100)
ptemp.code[0]=,1,;/*TOP*/
else
ptemp.code[0]=‟0‟
if(p.y>=400)
ptemp[1]=‟1‟;/*BOTTOM*/
else
ptemp.code[1]=‟0‟
if(p.x>=450)
ptemp.code[2]=‟1‟;/* RIGHT *else
ptemp.code[2]=‟0
‟
if(p.x<150) /* LEFT * /

ptemp.code[3]=‟1‟;
else
ptemp.code[3]=‟0‟;
ptemp.x=p.x;
ptemp.y=p.y;
return(ptemp);
}
/* Function to determine visibility of the line
-------------------------------------------------- */
int visibility (PT p1,PT p2)
{
int i, flag=0;
for(i=0;i<4;i++)
{
If(p1.code[i]!!=‟0‟||(p2.code[i]!=‟0‟))
flag=1;
}
if(flag==0)
return(0);
for(i=0;i<4;i++)
{
if(p1.code[i]==p2.code[i]&&(p1.code[i]==‟1‟))
flag=0;
}
if(flag==0)
return(1);
return(2);
}
INPUT
OUTPUT
GRAPH
THEORETICAL QUESTIONS
1.
2.
3.
4.
5.

What is Mid Point line clipping algorithm ?
What are the various type of coordinates ?
Which method is used to clip circle and ellipse by taking their extents.
Which line clipping algorithm is applicable only for the convex window region.
What is window and viewport ?

OBJECTIVE QUESTIONS
1. The Mid Point Subdivision algorithm is a special case of
a) Liang Berksy
b) Brute – Force
b) Cohen Sutherland
d) Sutherland & Hodgman
2. Clipping is done
a) Before scan conversion b)After scan conversion
c)In mid way

d) Any of these

3. The combination of Clipping Scan conversion is known as
a) Scissoring B) Viewing c) Windowing d) Normalizing
4. Which is not line clipping algorithm
a)Cohen – Sutherland

b) Mid point Subdivision c) Z-Buffer d) Liang – Barskey

5. Which is more efficient than Cohen Sutherland line clipping algorithm
a) Mid-Point Subdivision b) Liang – Barksey
c) Brute – Force

d) Sutherland – Hodgman
PROGRAM NO – 09

Date …………………….

OBJECT

WAP TO MULTIPLY TWO GIVEN MATRICES
ALGORITHM
1.
2.
3.
4.
5.
6.
7.
8.
9.

Initialize First Matrix let it be A(m)(n).
Read the order of First Matrix, let m=3,n=3
Input Data to the elements of the First Matrix
Initialize Second Matrix let it be (q)(r)
Read the order of Second Matrix, let q=3,r=3
Input Data elements of the Second Matrix
Check the Possibility of Multiplication between two matrices
If possibility exists apply the following formula
C(i)(j)=c(i)(j) + a(i)(k) * b(k)(j)
And Store the values into a New matrix, let it be C(m)(r)
10. Otherwise terminate the program messaging that multiplication is not possible.
11. Print the Result on Console.
12. Stop.

SAMPLE PROGRAM
# include<stdio.h>
#include<conio.h>
void main()
{
Int i,j.k;
int a[3][3],b[3][3],c[3][3];
clrsr();
printf(“Enter values for the First Array ROW WISE n”);
for(i=0;i<3;i++)
{
printf(“Enter value for a [%d][%d]=”,i+1,j+1);
scanf(“%d”,&a[i][j]);
}//End of inner for loop
}
printf(“enter values for the Second Array ROW WISE n”);
for(i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
printif(“Enter value for a {%d}[%d]=”.i+1.j+1;
scanf(%d”,&b[i][j];
}

//End of inner for loop

}
printf(“nn”);
//Multiplication of Above Two Array and Storing the values into another Array C
printf(Multiplication of the above Two Matrices is nn”);
printf(“************************************************************************
******
nnn”);
for(i=0;i<3;i++)
{
c[i][j]=0
for(int k=0;k<3;k++)
{
C[i][j]=c[i][j] + a[i][k] * b[k][j];
}
}
}
//printing of the Multiplied array
for(i=0;i<3,i++)
{
//printing of Array A[i][j]
printf (“|”);
for(j=0;j<3;j++)
{
printf(“%5d”,a[i][j];
}
printf(“|”);
If(i==0)
printf(“*”);
else
printf(“”);
//Printing of Array B[i][j]
printf(“|”)
for(j=0;j<3;J++)
{
printf (“%5d”,b[i][j][j];
}
printf(“|”);
//Printing of Array C[i][j]

If (i==0)
printf(“ =”);
Else
printf(“ “);
printf(“ | “);
for(j=0;j<3;j++)
{
printf(“%5d”,c[i][j]);
}
printf(“|n”);
}//End of Outer for loop
printf(“nnn”******************************************************************
**********nnn”);
gotoxy(1,48);
printf(“Press Any Key to Continue….”);
getch();
return;
}//End of the Main()
INPUT
OUTPUT
THEORETICAL QUESTIONS
1.
2.
3.
4.
5.

What is Subscripted Variable ?
What is One dimensional array variable ?
What is Two Dimensional array variable ?
What is the necessary condition for the two Matrix to be Multiplied ?
What is the use of Matrix ?

OBJECTIVE QUESTIONS
1. The declaration of an array variable like A[10] is an example of
a) 1 b)2
c)3
d)4
….dimensional array.
2. The declaration of an array variable like B[10][10] is an example of
a)1 b)2 c)3
d)4
…. Dimensional array.

3. The declaration of an array variable like C[10][10] is an example of
a)1
b)2
c)3
d)4
……dimensional array.

4. The no.of elements in the variable declaration like intA[5] will be
a)2
b)5
c)4
d)10

5. The no.of elements in the variable declaration like int A[5][5] will be
a)10
b)25
c)20 d)50
PROGRAM NO-10
Date………………………

OBJECT
WAP TO DRAW CUBIC SPLINE
ALGORITHM
1.
2.
3.
4.

Initialize the values of coefficients
Initialize the value of parameter u,
Set a proper increment
Calculate the coordinate of various points using the parametric equation of CUBIC
SPLINE
i.e
X=a0 + a1 * u + a2 * u2 +a3 * u3 and
Y= b0 + b1 * u + b2 * u2 + b3 * u3
5. Plot the different values on the graphics mode
6. Stop

SAMPLE PROGRAM
# include < stdio.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
#include<graphics.h>
#include<math.h>

Void initialize – Graphics();
Void Draw _ Axis(int dx,int dy);
Int datum_y=450;
Int datum _x=10;
//Start of the main()
void main()
{
float a[4];
float b[4];
float x,y;

printf(“Enter the value of Coefficients for x Co-ordinaten”);
for(int i=0;i<4;i++)
{
printf(“Enter the value of a(%d) = “.a[i];
scanf (“% of”,&a[i]);
}
printf (“Enter the value of Coefficients for y Co-ordinate n”);
/* initialize graphics mode */
initgraph (&gdriver,&gmode,”d;tcc”);
/*read result of initialization */
Errorcode = graphresult();
if (errorcode ! = grOk) /* an error occurred * /
{
printf (“Graphics error: %sn”, grapherrorms(errorcode));
printf(“Press any key to halt:”);
getch();
exit(1);

/* return with error code */

}
/*draw a line */
outtextxy(250,40,”CUBIC SPLINE”);
/* clean up */
}
void Draw_Axis(int dx, int dy)
{
for(int i=0;i<620,i++)
putpixel(dx+i,dy,WHITE); //Draw Horizontal Line
for(i=0;i<400;i++)
putpixel(dx,dy-i,WHITE); //Draw Vertical Line
return;
}

INPUT
OUTPUT
GRAPH
THEORETICAL QUESTIONS
1.
2.
3.
4.
5.

What is a Cubic Spline ?
What are the applications of the Cubic Spline ?
What is the range of value of parameter „u‟ in case of Cubic Spline?
How it is different from Bezier Curve?
How multisegment Cubic Splines are made ?
OBJECTIVE QUESTIONS
1. The value of parameter „u‟ in case of cubic spline will be
A1
b)2
c)3
d)4
2. No.of Control points in a Cubic Spline is
a)1
b)2
c)0
d)4
3. The equation y = a0 + a1 * X2 +a3 *X3 is
a)Cartesian

b) Polar

c)Parametric d)Complex

… form of equation.

4.The equation y=y= a0 +a1 * X +a2 * X2 + a3 *X3, where X is a parameter
………………………………is a
a) Cartesian b) Polar
c) Paramertic
…………………….. form of equation.

5. Y=a1 + a2 X + a3 X2 is the equation of
a) Slope

b) Normal

of a Cubic Spline.

c) Asymptote None of these

d)Complex

More Related Content

What's hot

Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics Concepts
SHAKOOR AB
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
baabtra.com - No. 1 supplier of quality freshers
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
shafiq sangi
 
C graphics programs file
C graphics programs fileC graphics programs file
C graphics programs file
shubham kanojia
 
Graphics in C programming
Graphics in C programmingGraphics in C programming
Graphics in C programming
Kamal Acharya
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Ankit Kumar
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
Rafi_Dar
 
Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
Abhishek Sharma
 
Turbo C Graphics and Mouse Programming
Turbo C Graphics and Mouse ProgrammingTurbo C Graphics and Mouse Programming
Turbo C Graphics and Mouse Programming
Huzaifa Butt
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
Priya Goyal
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
Vivek Kumar Sinha
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORT
vineet raj
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
Vivek Kumar Sinha
 
1 introduction computer graphics
1 introduction computer graphics1 introduction computer graphics
1 introduction computer graphics
cairo university
 
Image Processing Using MATLAB
Image Processing Using MATLABImage Processing Using MATLAB
Image Processing Using MATLAB
Amarjeetsingh Thakur
 
Class[5][9th jul] [three js-meshes_geometries_and_primitives]
Class[5][9th jul] [three js-meshes_geometries_and_primitives]Class[5][9th jul] [three js-meshes_geometries_and_primitives]
Class[5][9th jul] [three js-meshes_geometries_and_primitives]
Saajid Akram
 

What's hot (20)

Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics Concepts
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
C graphics programs file
C graphics programs fileC graphics programs file
C graphics programs file
 
Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)
 
Graphics in C programming
Graphics in C programmingGraphics in C programming
Graphics in C programming
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
 
Turbo C Graphics and Mouse Programming
Turbo C Graphics and Mouse ProgrammingTurbo C Graphics and Mouse Programming
Turbo C Graphics and Mouse Programming
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORT
 
Matlab
MatlabMatlab
Matlab
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 
1 introduction computer graphics
1 introduction computer graphics1 introduction computer graphics
1 introduction computer graphics
 
Image Processing Using MATLAB
Image Processing Using MATLABImage Processing Using MATLAB
Image Processing Using MATLAB
 
Class[5][9th jul] [three js-meshes_geometries_and_primitives]
Class[5][9th jul] [three js-meshes_geometries_and_primitives]Class[5][9th jul] [three js-meshes_geometries_and_primitives]
Class[5][9th jul] [three js-meshes_geometries_and_primitives]
 

Viewers also liked

Circle drawing algo.
Circle drawing algo.Circle drawing algo.
Circle drawing algo.Mohd Arif
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
Kandarp Tiwari
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algoMohd Arif
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Saikrishna Tanguturu
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of Pune
Bhavesh Shah
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.Mohd Arif
 
1 c – graphic designs
1 c – graphic designs1 c – graphic designs
1 c – graphic designs
Haseeb Patel
 
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 GraphsA Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
京都大学大学院情報学研究科数理工学専攻
 
ppt of solid modeling for cad
ppt of solid modeling for cadppt of solid modeling for cad
ppt of solid modeling for cad
Ayush Upadhyay
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
Adri Jovin
 
Lesson 14 a - parametric equations
Lesson 14 a - parametric equationsLesson 14 a - parametric equations
Lesson 14 a - parametric equationsJean Leano
 
Hidden lines & surfaces
Hidden lines & surfacesHidden lines & surfaces
Hidden lines & surfaces
Ankur Kumar
 
Cohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmCohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithm
Shilpa Hait
 
Three dimensional transformations
Three dimensional transformationsThree dimensional transformations
Three dimensional transformations
Nareek
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clippingavelraj
 
Solid modelling cg
Solid modelling cgSolid modelling cg
Solid modelling cg
Nareek
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
Griffinder VinHai
 

Viewers also liked (20)

Circle drawing algo.
Circle drawing algo.Circle drawing algo.
Circle drawing algo.
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algo
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of Pune
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 
Bresenham circle
Bresenham circleBresenham circle
Bresenham circle
 
1 c – graphic designs
1 c – graphic designs1 c – graphic designs
1 c – graphic designs
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 GraphsA Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
 
ppt of solid modeling for cad
ppt of solid modeling for cadppt of solid modeling for cad
ppt of solid modeling for cad
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Lesson 14 a - parametric equations
Lesson 14 a - parametric equationsLesson 14 a - parametric equations
Lesson 14 a - parametric equations
 
Hidden lines & surfaces
Hidden lines & surfacesHidden lines & surfaces
Hidden lines & surfaces
 
Cohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmCohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithm
 
Three dimensional transformations
Three dimensional transformationsThree dimensional transformations
Three dimensional transformations
 
Straight lines
Straight linesStraight lines
Straight lines
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clipping
 
Solid modelling cg
Solid modelling cgSolid modelling cg
Solid modelling cg
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 

Similar to Computer graphics

Chapter 1
Chapter 1Chapter 1
Chapter 1
kparthjadhav
 
Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphics
LOKESH KUMAR
 
Circles graphic
Circles graphicCircles graphic
Circles graphic
alldesign
 
unit1_updated.pptx
unit1_updated.pptxunit1_updated.pptx
unit1_updated.pptx
RYZEN14
 
Graphics software
Graphics softwareGraphics software
Graphics softwareMohd Arif
 
An35225228
An35225228An35225228
An35225228
IJERA Editor
 
computer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcodecomputer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcode
Bhavya Chawla
 
A 3D printing programming API
A 3D printing programming APIA 3D printing programming API
A 3D printing programming API
Max Kleiner
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docx
PayalJindal19
 
Graphics pipelining
Graphics pipeliningGraphics pipelining
Graphics pipelining
Areena Javed
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
HIMANKMISHRA2
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
HIMANKMISHRA2
 
VisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalVisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalMasatsugu HASHIMOTO
 
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
JinTaek Seo
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
💻 Anton Gerdelan
 
Skia & Freetype - Android 2D Graphics Essentials
Skia & Freetype - Android 2D Graphics EssentialsSkia & Freetype - Android 2D Graphics Essentials
Skia & Freetype - Android 2D Graphics Essentials
Kyungmin Lee
 
Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Csc406 lecture7 device independence and normalization in Computer graphics(Co...Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Daroko blog(www.professionalbloggertricks.com)
 
05-Debug.pdf
05-Debug.pdf05-Debug.pdf
05-Debug.pdf
KalaiselviDevaraj
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools
Mark Billinghurst
 

Similar to Computer graphics (20)

Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphics
 
Circles graphic
Circles graphicCircles graphic
Circles graphic
 
unit1_updated.pptx
unit1_updated.pptxunit1_updated.pptx
unit1_updated.pptx
 
Graphics software
Graphics softwareGraphics software
Graphics software
 
An35225228
An35225228An35225228
An35225228
 
computer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcodecomputer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcode
 
A 3D printing programming API
A 3D printing programming APIA 3D printing programming API
A 3D printing programming API
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docx
 
Graphics pipelining
Graphics pipeliningGraphics pipelining
Graphics pipelining
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
VisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalVisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_Final
 
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
Skia & Freetype - Android 2D Graphics Essentials
Skia & Freetype - Android 2D Graphics EssentialsSkia & Freetype - Android 2D Graphics Essentials
Skia & Freetype - Android 2D Graphics Essentials
 
Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Csc406 lecture7 device independence and normalization in Computer graphics(Co...Csc406 lecture7 device independence and normalization in Computer graphics(Co...
Csc406 lecture7 device independence and normalization in Computer graphics(Co...
 
05-Debug.pdf
05-Debug.pdf05-Debug.pdf
05-Debug.pdf
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools
 
Praseed Pai
Praseed PaiPraseed Pai
Praseed Pai
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 

Computer graphics

  • 1. PROGRAM NO – 01 OBJECT Date…………………… TO DEVELOP THE CONCEPT OF COMPUTER GRAPHICS USING „C‟. INTRODUCTION Computer Graphics is one of the most powerful and interesting facet of computer. There is a lot that one can do in graphics apart from drawing figures of various shapes. All video games, animations, multimedia predominantly works using Computer Graphics. This introductory too will give feeling of how some of these things are achieved using C. The aim is to make the readers comfortable with the basic concepts in graphics, Introduce themselves with standard library graphics functions and then let them explore On their own to implement certain algorithm of elementary drawing using Computer Graphics. Instead of discussing each Standard Library, graphics function in detail, most Commonly use functions and standard library files are put in the following program. SAMPLE PROGRAM #include<graphics.h> #include<conio.h> void main() { int gd=DETECT,gm,x,y; int array[]={540,220,590,270,320,510,320,490,270,540,220};
  • 3. return; }//End of main function DESCRIPTION OF PROGRAM Whenever any drawing is started in graphics mode a header file „GRAPHICS.H‟ And library file „GRAPHICS.LIB‟ is required. The header file contains definitions and Explanation of all the functions and constants whereas the graphics functions are kept in The graphics library file. Both of these files are provided as part of TURBOC. Before any drawing can be carried out, it is required to switch over to the Graphics mode from the text mode. Switching depends on the adapter and monitor may Be available with us. These modes have been given numbers. Out of all the modes Available, we would like to switch over to the one which offers the best possible Resolution. The number of dots or picture elements or pixels available to us on the screen in The graphics is known as the resolution. The greater the number of dots, the higher will be the resolution. It means more the dots available clearer would be our picture. To switch over to the graphics mode that offers the best resolution we need to call The function initgraph(). It figures out the best resolution and puts the number Corresponding to that mode in the variable “gm”. The „gm‟ number tell us which monitor We are using, and its resolution, the number of video pages it supports and the colors that are available.
  • 4. A color monitor driven by VGA adapter, the maximum resolution of which is 640 x 480 (i.e. 640 pixels from left to right and 480 pixels from top to bottom). To understand „gd‟ we need to understand the concept of device drivers. Device Drivers are small programs, which talk directly to the hardware. Since we can‟t be machine dependent at any time, we need program to communicate with in a standardized way. These programs in turn communicate with the machine. The intermediary programs are known as device drivers. Graphics drivers are a subset of device drivers and are applicable only in the graphics mode. They work in the above fashion to execute whatever task we have assigned them. TURBOC offers certain graphics drivers. These are the files with a BGI extension. Depending on what adapter is used, one of these drivers gets selected. The sample programs have been developed on the VGA adapter. Thus EGAVGA.BGI files are required as graphics drivers. In the above program „gd‟ has been assigned the value DETECT. There by asking Initgraph() to figure out which BGI file is needed. This file is then loaded into Memory. If we do not initiate with DETECT macro then it is our responsibility to set up „gd‟ and „gm‟ with appropriate value. The moment we change over to the graphics mode two things happens. Firstly, The cursor disappears, since the graphics mode does not support the conventional cursor. Secondly, a coordinate system is established whereby thetop left corner to the screen is
  • 5. treated as origin (0, 0). As usual, the x – axis goes horizontally across, and the y-axis goes vertically downward. The basic tools we will need for drawing shapes are functions like putpixel(), Line(), ellipse(), arc(), drawpoly() etc. All these functions have been used in the above Sample program. Their general form is as follows: Table 1.0 Details of the Function SN Function Meaning 01 getmaxx() Fetches max value of x coordinate 02 getmaxy() Fetches max value of y coordinate 03 setcolor Sets the color for objects 04 rectangle() Draws rectangle using top left and right bottom Screen coordinates 05 circle() Draws circle using x,y coordinate of center and Radius 06 ellipse() Draw ellipse using x,y coordinate of the Intersection of major minor axis, start angle, end Angle, x radius and y radius 07 arc() Draws are using x,y coordinate of the center, start Angle, end angle and radius of arc 08 Line() Draws line using end point of the line 09 drawpoly() Draws polygon using no of vedrtices and their Coordinates
  • 6. 10 putpixel() Put a pixel at given location using the given color 11 outtextxy() Writes a string at the given location Note: Two functions getmaxx() and getmaxy() have ben used in the above sample Program, readers may change it and make user interactive before switching to the Graphic mode imposing the limitation of the maximum resolution of given graphics Adapter. INPUT OUTPUT GRAPH THEORETICAL QUESTIONS 1) 2) 3) 4) 5) Write the syntax of function initgraph(). What is the significance of function initgraph()? What is a pixel ? What is maximum resolution of a VGA adapter ? What is the syntax of function closegraph() and why is it used ? OBJECTIVE QUESTIONS 1) DETECT is a a)functions b) macro c) subroutine d) procedure 2) getmaxx() fetches maximum a) x-coordinate b) y-coordinate c) z-coordinate d) r-O
  • 7. coordinate 3) No of arguments passed to the function putpixel () is a)1 B)2 c)3 d) 4 4) The value of the third parameter passed to the function circle() related to a) x-coordinate of center b) radius of circle c) y-coordinate of circle d) diameter of circle 5) To draw a rectangle which function can be used instead of rectangle () function a) circle b) ellipse c) line d) drawpoly
  • 8. PROGRAM NO. 02 OBJECT Date…………….... WAP TO IMPLEMENT THE DDA LINE DRAWING ALGORITHM ALGORITHM An algorithm is a well-defined sequential set of mathematical and logical operations which, when implemented (or performed), produces the solution of a given mathematical problem. In feeding numerical data and in processing – which involves implementation of algorithms and the final output of the result – two types of errors are generally introduced. They are truncation errors and rounding off errors. Besides these, errors in the implementation of the algorithm must be taken into account. (nm/6) 1. Read the line end point (x1,y1) and x2,y2) such that they are not equal. (if Equal then plot that point and exit) 2. dx = |x2 –x1| and dy = |y2-y1| 3. if (dx>=dy) then length = dx else length = dy endif 4. dx = (x2-x 1)/length dy = (y2-y1)/length (This makes either dx or dy equal to 1 because length is either |x2-x1| or |y2-y|. Therefore, the incremental value for either x or y is one) 5. x = x1 + 0.5* sign(dx) y= y1 + 0.5* sign(dy) (here,sign function make s the algorithm work in all quadrant. It returns -1,0,1 depending on whether its argument is <-,=0,>0 respectively. The Factor 0.5 makes it possible to round the values in the integer function rather than truncating them).
  • 9. 6. i=1 (Begins the loop, in this loop points are plotted) While (i<=length) { plot (integer(x), integer (y)) x=x+dx y=y+dy i=i+1 } 7. Stop SAMPLE PROGRAM #include<stdio.h> #include<graphics.h> #include<math.h> main() { float x,y,x1,y1,x2,y2,dx,dy,length; int i,gd,gm; int xref=0,yref=400; clrscr(); /*Read two end points one line ------------------------------------*/ printf(“Enter the value of x1 :t”); scanf(“%of”.x1); printf(“Enter the value of y1 :t”; scanf(“%of,&y1) printf(“Enter the value of x2 :t”); scanf(“%of,&x2);
  • 10. printf(“Enter the value of y2 :t”); scanf(“%of,&y2); /* Initialise graphics mode ------------------------------ */ detectgraph(&gd &gm); initgraph(&gd,&gm””); dx=abs(x2-xx1); dy=abs(y2-y1); if (dx >=dy) { length = dx; } Else { length =dy; } dx = (x2-x1)/length; dy = (y2-y1)/length; x = x1 + 0.5; /* Factor 0.5 is added to round the values */ y = y1 + 0.5;/* Factor 0.5 is added to round the values */ i =1; /* Initialise loop counter */ while (i<=length)
  • 11. { putpixel(x-xref,yref-y,15); x = x+ dx; y = y+dy; i= i + 1: delay(100);/* Delay is purposely inserted to see Observe the line drawing process*/ } getch(); closegraph(); } INPUT OUTPUT GRAPH THEORETICAL QUESTIONS 1. 2. 3. 4. 5. What are the merits of DDA algorithm ? What are the limitations of DDA algorithm ? Name any other line drawing algorithm What is aliasing ? Can the equation y = mx + C be used effectively to calculate the pixel position ? Explain OBJECTIVE QUESTIONS 1. DDA is a technique for a) Scan conversion b) Image conversion c) Graphics conversion d) All of these……………… of a line 2. Which parameter decides the selection of equation for the calculation of coordinates in DDA algorithm. a)m b)|m| c) +m d)-m 3. The name of algorithm used for line drawing is
  • 12. a) Bresenham b) Cohen sutherland c) Z-buffer d) Liang Barsky 4. DDA algorithm is faster than a) Conventional method (y = mx + C) b) Bresenham‟s Line drawing algo c) Bresenham‟s circle d) Mid point circle algo 5. Pixel position of various coordinate are calculated using a) Absolute referencing b) Relative referencing c) Logarithmic referencing d) Exponential referencing
  • 13. PROGRAM NO. 03 OBJECT Date……………….. WAP TO IMPLEMENT BRESENHAM‟S LINE DRAWING ALGORITHM ALGORITHM 1. Read the line end points (x1,y1) and (x2,y2) such that they are not equal. (If equal then Plot that point and exit) 2. dx =|x2-x1| and dy = |y2-y1| 3. Initializing starting point X = x1 Y = y1 4. E = 2 * dy – dx (Initialize value of decision variable or error to compensate for non zero intercepts) 5. I= 1 (initialize couter) 6. Plot (x,y) 7. While (e>=0) { y+1 e = e-2 *dx } x= x+1 e=e+2* dy 8. 1=1+1 9. If (1<=dx then to step 6 10. Stop SAMPLE PROGRAM #include<stdio.h> #include <graphics.h> #include<math.h> #include<dos.h> main() { float x,y,x1,x2,y2,dx,dy,e;
  • 14. int I,gd,gm; int xref=0,yref = 400; clrscr(); /* Read two end points of line ………………………………….. */ printf (“Enteer the value of x1;t); scanf(“%of,&x1); printf(“Enter the value of y1 :t”): scanf(„%of,&y1; printf(„Enter the value of x2 :t‟) scanf(„%of &x2); printf(„Enter the value of y2 :t”); scanf(“%of &y2); /* Initialise graphics mode …………………………………*/ detectgraph(&gd,&gm); initgraph(&gd,&gm,””); dx=abs(x2-x1); dy=abs(y2-y1); /*Initialise starting point …………………………….. */ x=x1; y=y1; /* Initialise decision variable …………………………………. */
  • 15. e=2*dy-dx; i=1;/*Initialise loop counter */ do { putpixel(x-xref,yref,15); While (e>=0) { y=y+1; e=e-2 *dx; } x=x+1 e=e+2*dy: i=i+1; delay(100) }while (i<=dx); getch(); closegraph(); } INPUT OUTPUT GRAPH THEORETICAL QUESTIONS 1. What are the merits of Bresenham‟s algorithm over the DDA algorithm? 2. Write the equation of decision parameter used in Bresenham‟s line drawing algorithm. 3. What are the limitations of Bresenham‟s line drawing algorithm/ 4. Name three line drawing algorithm 5. What type of calculations are used in the Bresenham‟s line drawing algorithm/
  • 16. OBJECTIVE QUESTIONS 1. The proposed algorithm is applicable for the range of values of m a) -1 to 1 b) 0 to 1 c) 1 to 0 d) 0 to -1 2. The line algorithm which can be generalized easily for ellipse and conic a)Bresenham b)DDA c)Midpoint d) Franklin 3. Bresenham line drawing algorithm is faster than a) DDA b) Conventional method 9y = mx + C) c) Polar method d) All of these 4. The use of Bresenham algorithm avoids a) Round Function b) Floating point addition c) Both a & b d) Either of a and b 5. Which is not a line drawing algorithm a) Bresenham b) DDA c) Mid point d) End point
  • 17. PROGRAM NO. 4 OBJECT Date………………... WAP TO IMPLEMENT BRESENHAM‟S CIRCLE DRAWING ALGORITHM ALGORITHM 1. Read the radius ® of the circle. 2. d =3-2r(Initialize starting point) 3. x=0 y=r (Initialize starting point) 4. Do { Plot (x,y) If (d<0) then { D = d+4x+6 } Else { d=d+4(x-y)+10 Y=y-1 } X=x+1 While (x<y) 5. Stop SAMPLE PROGRAM #include<stdio.h> #include<graphics.h> #include<math.h> void main() { float d;
  • 18. int gd,gm,x,y; int r,tim; clrscr(); /*Read the radius of the circle ………………………………. */ printf(“Enter the radius of a circle :”); scanf(“%d”,&r); printf(“Enter the Time delay (milli second):”); scanf(“%d”,&tim); /*Initialise graphics mode -----------------------------*/ detectgraph(&gd,&gm); initgraph(&gd,&gm,” ”); /*Initialise starting points -----------------------------*/ x=0; y=r; /*initialise the decision variable -----------------------------*/ d = 3 – 2 *r; do { putpixel(200+x,200+y,15); putpixel(200+x,200+y,15); putpixel(200+y,200+x,15); putpixel(200+y,200-x,15);
  • 19. putpixel(200+x,200-y,15); putpixel(200-x,200-y,15); putpixel(200-y,200-x,15); putpixel(200-y,200+x,15); putpixel(200-x,200+y,15); if(d<=0) { d=d+4*x+6; } Else { d =d+4*x+6; } d=d+4(x-y)+10; y= y-1; } x = x+1; delay(tim); /*Delay is purposely inserted to see observe the line drawing process */ } while(x<y); getch(); closegraph(); return; }
  • 20. Note:- The algorithm plots 1/8 of the circle. INPUT OUTPUT GRAPH THEORETICAL QUESTIONS 1. What is the generalized equation of a circle with center at origin and radius „r‟ ? 2. Write trigonometric equation to draw a circle. 3. What is the difference between Bresenham‟s circle drawing algorithm and other Conventional equations? 4. Name any other algorithm for circle drawing. 5. Write the equation of decision parameter for circle drawing using Bresenham‟s Circle drawing algorithm? OBJECTIVE QUESTIONS 1. In the above algorithm pixel positions are calculated for a) Semi-quarter circle b) Quarter circle b) Half circle d) Full circle 2. Which not a circle drawing algorithm a)Bresenham b) DDA c) Mid point d) Franklin 3. To draw complete circle using Bresenham‟s circle drawing algorithm a) 8 – way symmetry b) 4 – way symmetry c) 2 – way symmetry d) 1-way symmetry 4. The above method generates the pixel position for a circle having it center at a) Origin b) x-axis c) y-axis d) At the center of reference frame 5. Which of the following transformation may be required to calculate the pixel Position of the circumference of a circle whose center is not at origin a) Flip b) Move c) Rotate d) Scale
  • 21. PROGRAM NO. 05 OBJECT Date……………………… WAP TO IMPLEMENT MID – POINT CIRCLE DRAWING ALGORITHM ALGORITHM u 1. Read the radius ® of the circle 2. Initialize starting position as x=0 y=0 3. Calculate initial value of decision parameter as P = 1.25 – r 4. do { Plot(x,y) If (d <0) { x=x+1 y=y d = d + 2x + 1 else { x = x+1 y=y–1 d = d + 2x + 2y + 1 } while (x <y) 5. Determine symmetry points 6. Stop SAMPLE PROGRAM #include<stdio.h> #include<graphics.h> #include<math.h> main() {
  • 22. float p; int i,gd,gm,x,y; int r; /* initialize graphics ……………………….. */ detectgraph(&gd,&gm); initgraph(&gd,gm,””); /* Read the radius ……………………. */ printf(“Enter the radius of the circle ;”); scanf(“%d”,&r); x=0; y=r; p=1.25 – r; do { putpixel(200+x,200+y,15); putpixel(200+y,200+x,15); putpixel(200+x,200-y,15); putpixel(200+y, 200-y,15); putpixel(200-x,200-y,15); putpixel(200-x,200+y,15); putpixel(200-y,200+x,15); putpixel(200-y,200-x,15); if (p < 0)
  • 23. { x+ x+1; y=y p=p+2*x + 2; } else { x =x+1 y=y-1 p=p+2*(x-y)+1; } delay(10000); } while(x <y); getch(); closegraph(); } INPUT OUTPUT GRAPH THEORETICAL QUESTION 1. 2. 3. 4. 5. What is Staircase effect? Write the equation of decision parameter used in Mid-Point circle drawing algorithm What is the difference between this and Bresenham‟s circle drawing algorithm? Name the method is used to draw a full circle in mid-point circle drawing algorithm? Name any two circle drawing algorithm.
  • 24. OBJECTIVE QUESTIONS 1. The pixel positions calculated using this and Bresenham‟s circle algorithm are a) Exactly same b) Different c) Partially different d) Depends on origin selection 2. Which of the following algorithm can be easily extended to ellipse and conic sections a) Mid-Point b) Bresenham c)DDA d) All of these 3. The ill effects of the scan conversion is removed by a) Anti-aliasing b) aliasing c) Staircase d) Jaggies 4. The functional value at the mid point between two pixels is evaluated to determine which Pixel out of the two should be plotted in a) Bresenham b) DDA c) Mid-point d)Hodgman algorithm 5. Which is not a method of Anti-aliasing a) Increrasing resolution b) Weighted are sampling c) pixel phasing d) Decreasing resolution.
  • 25. PROGRAM NO.06 Date ……………….. OBJECT WAP TO DRAW BEZIER CURVE ALGORITHM 1. Read no control points 2. Read the coordinate of control points 3. Generate Parametric equation to calculate 4. A) x – coordinate of the curve 5. B)y – coordinate of the curve 6. Using the Generalized equation for the Bezier curve 7. Select suitable increment in the parameter „u‟. 8. Iterate to get the various points of curve using equation 3a) and 3b). 9. Store the points in array 10. Plot the points. 11. Stop The Generalized Parametric Equation of the Bezier Curve is Where 1. 2. 3. 4. 5. 0< = u <=1 N = Degree of Polynomial n =No of control points N=n-1 Pk = The x/y coordinate of control SAMPLE PROGRAM #include<stdio.h> #include<dos.h> #include<graphics.h> #include<conio.h> #include<process.h> #include<iostream.h> Point.
  • 26. #include<math.h> void Init Graph(); void Draw Point (int x, int y, int clr); double fact (double x); void main() { int i,k,counter; float u,incr,factor; /* float Px[5]={60,80,150,180,0}; float Py[5]={20,100,90,50,0}; */ /* //Parabola floatPx[5]={9,0,9,180,0} float Py[5]={-6,0,6,50,0}; */ //Circle float Px[11]={10,8,6,7,0,-7.07,-10,-7.07, 0,7.07,8.6,10}; float Py[11]={0,5,7.07,10,7.07, 0,-7.07,-10,-7.07,-5,0} //Give Due care to Control Points int ctrl-pt; float tPx,tPy;
  • 27. int Xo,Yo; float Sx,Sy; FILE *fp; Clrscr(); //Variable initialization Incr = 0.01; ctrl –pt=11; Sx=15; Sy=15; tPx=Px[0]; tPy=Py[0]; counter=1; xo=100; Yo=250; fp=fopen(“bzr.txt”,”w”) // Note we are initializing the tPx and tPy with the starting value of the //control point because pow(0,0)give domain error and also it is useless //to do calculation for the first point //End of variable initialization Ctrl pt--; //Because counting starts from zero; Init-Graph(); for u=incr; u<=1; u+=incr) { fprintf(fp,”%4d X=%8.2f| Y=%8.2fn”,counter++,tPx,tPy); Draw Point (Xo+Sx*tPx,Yo-Sy*tPy,9); tPx=0; tPy=0 //Resetting the tPx,tPy for the next calculation for9K=0; k<=ctrl-pt; k++) { Factor=fact(ctrl-pt)/(fact(k) * fact(ctrl-pt-k));
  • 28. tPx+=factor*pow(u,k) *Px[k]* pow(1-u),(ctrl-pt-k)); tPy+=factor*pow(u,k)*Py[k]* pow(1-u),(ctrl-pt-k)); }//End of inner for loop }//End of outer for loop fclose(fp); getch(); return; }//End of the main double fact(double x) { If (x<1) Return 1; double factorial; factorial = x while (x > 1) factorial = factorial*(--x); return factorial; }//End of the function void Init-Graph() { int xmax,ymax, int gdriver = DETECT, gmode, errorcode; /*initialize graphics and local variables */
  • 29. initgraph(&gdriver,&gmode,”c.turboc”); /*read result of initialization */ errorcode = graphresult(); /*an error occurred */ If (errorcode !=grOk) { printf(“Graphics error: %sn”, grapherrormsg(errorcode)); printf(“Press any key to halt:”); getch(); exit(1); } setbkcolor(0); return; } void Draw Point (int x, int y, int clr) { putpixel(x,y,clr); putpixel(x+1,y,clr); putpixel(x-1,y,clr); putpixel(x,y-1clr); putpixel(x,y+1,clr); } INPUT OUTPUT
  • 30. GRAPH THEORETICAL QUESTIONS 1. 2. 3. 4. 5. What are the properties of Bezier curve? What is the difference between the Bezier curve and Splines? Write the parametric equation for ellipse, parabola and hyperbola. Write the parametric equation of Bezier curve using four control points Write the Generalized parametric equation for Bezier curve. OBJECTIVE QUESTIONS 1. Bezier curve always passes through a) First and last control point b)First and second control point c)Only mid control point d) Any control point except mid 2. The relation between degree of polynomial (DOP) and the no of control points (noc) is a) DOP=noc+1 b) DOP = noc-1 c)DOP=In(noc) d) DOP =noc 3. The no.of control points in a cubic Bezier curve will be a)1 b)2 c)3 d)4 4. The two basic type of parametric curves are a) Interpolation and approximation b) Extrapolation and approximation c) Interpolation and extrapolation d)Approximation & substraction 5. Bezier curve is an example of a) Interpolation d)Substraction b)Approximation …………type of parametric curve. c)Extrapolation
  • 31. PROGRAM NO.07 Date………………… OBJECT WAP TO IMPLEMENT COHEN SUTHERLAND LINE CLIPPING ALGORITHM ALGORITHM 1. Read two end points of the line say P1(x1,y1) and P2(x2,y2). 2. Read two corners (left-top and right bottom) of the window, say (Wx1,Wy1 and Wx2,Wy2). 3. Assign the region code for two end points P1 and P2 using following steps ; Initialize code with bits 0000 Set Bit 1 – if (x < Wx1) Set Bit 2 – if (x > Wx2) Set Bit 3 – if (y < Wy2) Set Bit 4 – if (y > Wy1) 4. Check for visibility of line P1 P2 a) If region codes for both tow endpoints P1 and P2 are zero then the line is completely visible. Hence draw the line and go to step 9. b) If region codes for endpoints are not zero and the logical ANDing of them is also nonzero then the line is completely Invisible, so reject the line and go to step 9. c) If region codes for two endpoints do not satisfy the conditions in 4a) and 4b) the line is partially visible. 5. Determine the intersecting edge of the clipping window by inspecting the region codes of two endpoints. a) If region codes for both the end points are non zero, find Intersection points P1‟ and P2‟ with boundary edges of clipping window with respect to point P1 and Point2 respectively. b) If region code for any one end point is non zero then find Intersection point P1 or P2‟ with the boundary edge of the Clipping window with respect to it. 6. Divide the line segment considering intersection points
  • 32. 7. Reject the line segment if any one end point of it appears outside the clipping window. 8. Draw the remaining line segment. 9. Stop. SAMPLE PROGRAM #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<dos.h> #include<math.h> #include<graphics.h> /* Defining structure for end point of line */ typedef struct coordinate { int x,y; char code [4]; } PT; void draw window () void draw line (PT p1, PT p2, int cl); PT setcode(PT p); int visibility (PT p1,PT p2); PT resetendpt(PT p1,PT p2); main() { int gd=DETECT,GM,V; PT p1,p2,ptemp;
  • 33. intigraph(&gd,gm,””) cleardevice(); printf(“nnttENTER END POINT 1 (x,y):”); scanf(“%d,%d,&p1,x,&p1.y); printf(“nntt ENTER END POINT 2 (x,y):”); scanf(“%d”&p2.x,&p2.y); cleardevice(); drawwindow(); getch(); drawline(p1,p2,15); getch(); p1 = setcode(p1); p2=setcode(p2); v=visibility(p1,p2); switch(v) { case 0: cleardevice();/* Line completely visible */ drawwindow(); drawline(p1,p2,15); break; case 1: cleardevice();/* Line completely invisible */ drawwindow(); break; case 2: cleardevice(); /* line partly visible */ p1 = resetendpt(p1,p2);
  • 34. p2=resetendpt(p2,p1); drawwindow(); drawline(p1,p2,15); break; getch(); closegraph(); return(0); } /*Function to draw window */ void drawwindow() { /*Function to draw line between two points ……………………………………………………….*/ void drawline (PT p1,PT p2, int cl) { setcolor (RED); line(150,100,450,100); line(450,100,450,350); line(450,350,150,350); line(150,350,150,100); } /*Function to draw line between two points ----------------------------------------------------*/ void drawline(PT p1,PT p2,int cl) setcolor(cl);
  • 35. line(p1.x,p1.y,p2.x,p2.y); } /*Function to set code of the coordinates …………………………………………………………..*/ PT setcode(PT p) { PT ptemp; If (p.y<100) ptemp.code[0]=‟1‟;/*TOP*/ else ptemp.code[0]=‟0‟; if (p.y<350) ptemp.code[1]=‟1‟;/*BOTTOM*/ else ptemp.code[1]=‟0‟; if(p.x>450) ptemp.code[2]=‟1‟/* RIGHT */ else ptemp.code[2]=‟0‟ if (p.x<150)/* LEFT */ ptemp.code [3]=‟1‟ else ptemp.code[3]=‟0‟ ptemp.x=p.x; ptemp.y=p.y;
  • 36. return(ptemp); } /* Function to determine visibility of line ……………………………………………. */ int visibility (PT p1, PT p2) { int i, flag=0; for(i=0;i<4;i++) { if(pl.code[i]!=‟0‟)||(p2.code[i]!=‟0‟)) flag=1; } if(flag= =0) return (0); for(i=0;i<4;i++) { if(p1.code[i]=p2.code[i]) &&(p1.code[i]=‟1‟)) flag=0; if (flag =0) return(1); return(2); } /* Function to find new end points …………………………………………….*/ PT resetendpt (T p1,PT p2)
  • 37. { PT temp; int x,y,I; float m,k; if (pl.code[3]=‟1‟/*Cutting LEFT Edge */ x=150; If(pl.code[2]=‟1‟)/*Cutting RIGHT Edge */ x=450 If(pl.code[3]=‟1‟)||(pl.code[2]=‟1‟)) { m=(float)(p2.y-pl.y)/(p2.x-pl.x); k=(pl.y+(m*(x-pl.x))); temp.y=k; temp.x=x; for(i=0;i<4;i++) temp.code[i]=pl.code[i]; if(temp.y<350&&temp.y>=100) return(temp); } If (p1.code[0]=‟1‟)/*Cutting TOP Edge */ y=100; if(pl.code[1[=‟1‟)/* Cutting BOTTOM Edge */ y=350;
  • 39. OBJECTIVE QUESTIONS 1. The process of selecting and viewing the picture with different views is called a) Windowing b) Clipping c) Normalizing d) Viewing 2. A process which divides each element of the picture into its visible and invisible portion, allowing the invisible portion to be discarded is called a) Windowing b) Normalizing c) Clipping d) Viewing 3. Cohen-Sutherland‟s 2D line clipping approach is a a)Parametric approach b) Non-Parametric approach c)Geometric approach d)Logarithmic approach 4. The no of bit used to generate Outcode for a given coordinates are a) 2 b)4 c)6 d)8 5. Cohen Sutherland line clipping algorithm computes the Outcode of a) End Points b) Mid point c) Any two consecutive point d)Both a and b …..of a line
  • 40. PROGRAM NO.08 Date……………… OBJECT WAP TO IMPLEMENT MID POINT SUB-DIVISION LINE CLIPPING ALGORITHM ALGORITHM 1. Read two end points of the line say P1(x1,y1) and P2(x2,y2) 2. Read two corners (left – top and right bottom) of the window, say (Wx1, Wy1 and Wx2,Wy2). 3. Assign region codes for two end points using following steps: Initialize code with bits 0000 Set Bit 1 - if (x<Wx1) Set Bit 2 - if (x> Wx2) Set Bit 3 - if (y< Wy1) Set Bit 4 - if (y> Wy2) 4. Check for visibility of line a) If region codes for both endpoints are zero then the line is completely visible. Hence Draw the line and go to step 6. b) If region codes for endpoints are not zero and the logical ANDING of them is also Non-zero then the line is completely invisible, so reject and the line and go to step 6. c) If region code for two endpoints do not satisfy the conditions in 4a) and 4b) the line is Partially visible. 5. Divide the partially visible line segment in equal parts and repeat steps 3 through 5 for both Subdivided line segments until you get completely visible and completely invisible line segments. 6. Stop.
  • 41. SAMPLE PROGRAM #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<dos.h> #include<math.h> #include<graphics.h> /* Defining structure for end point of line */ Typed of struct coordinate { int x,y; char code[4]; } PT; void drawwindow(); void drawline (PT p1, PT p2, int cl); PT setcode(PT p); int visibility (PT p1, PTp2); PT resetendpt( main() { Int gd=DETECT,gm,v. PT p1,p2,ptemp;
  • 42. intigraph(&gd,gm,‟‟); cleardevice(); printf(„nnttENTER END POINT 1(x, y”); scanf(“%d,%d”.&p1,x,&pl.y); printf(“nntENTER END POINT 2 (x, y):”) scanf(“%d,%%d,”,&p2,x,&p2.y); cleardevice() drawwindow(); getch(); drawwindow() midsub(p1,p2); getch(); closegraph(); return(0); } midsub(PT p1,PT p2) { PT mid; int v; p1=setcode(p1) p2=setcode(p2); v=visibility(p1,p2); switch(v)
  • 43. { case 0;/*Line completely visible *// drawline(p1,p2,15); break; case 1: /* Line completely invisible */ break; case 2: /* line partly visible */ mid.x=p1.x + (p2.x-p1.x)/2; mid.y=p1.y + (p2.y-p1.y)/2; midsub(p1,mid); mid.x=mid.x+1: mid.y=mid,y+1; midsub(mid,p2); break; } } /*Function to draw window */ void drawwindow() { setcolor(RED); line(150,100,450,100); line(450,100,450,400);
  • 44. line(450,400,150,400); line(150,400,150,100); /* Function to draw line between two points -------------------------------------------------*/ void drawline (PT p1,PT p2,int cl) { setcolor(cl); line(p1.x,p1.y,p2.x,p2.y); } /* Function to set code of the coordinates ---------------------------------------------*/ PT setcode(PT p) { PT ptemp; if(p.y<=100) ptemp.code[0]=,1,;/*TOP*/ else ptemp.code[0]=‟0‟ if(p.y>=400) ptemp[1]=‟1‟;/*BOTTOM*/ else ptemp.code[1]=‟0‟ if(p.x>=450)
  • 45. ptemp.code[2]=‟1‟;/* RIGHT *else ptemp.code[2]=‟0 ‟ if(p.x<150) /* LEFT * / ptemp.code[3]=‟1‟; else ptemp.code[3]=‟0‟; ptemp.x=p.x; ptemp.y=p.y; return(ptemp); } /* Function to determine visibility of the line -------------------------------------------------- */ int visibility (PT p1,PT p2) { int i, flag=0; for(i=0;i<4;i++) { If(p1.code[i]!!=‟0‟||(p2.code[i]!=‟0‟)) flag=1; } if(flag==0)
  • 46. return(0); for(i=0;i<4;i++) { if(p1.code[i]==p2.code[i]&&(p1.code[i]==‟1‟)) flag=0; } if(flag==0) return(1); return(2); } INPUT OUTPUT GRAPH THEORETICAL QUESTIONS 1. 2. 3. 4. 5. What is Mid Point line clipping algorithm ? What are the various type of coordinates ? Which method is used to clip circle and ellipse by taking their extents. Which line clipping algorithm is applicable only for the convex window region. What is window and viewport ? OBJECTIVE QUESTIONS 1. The Mid Point Subdivision algorithm is a special case of a) Liang Berksy b) Brute – Force b) Cohen Sutherland d) Sutherland & Hodgman 2. Clipping is done a) Before scan conversion b)After scan conversion c)In mid way d) Any of these 3. The combination of Clipping Scan conversion is known as
  • 47. a) Scissoring B) Viewing c) Windowing d) Normalizing 4. Which is not line clipping algorithm a)Cohen – Sutherland b) Mid point Subdivision c) Z-Buffer d) Liang – Barskey 5. Which is more efficient than Cohen Sutherland line clipping algorithm a) Mid-Point Subdivision b) Liang – Barksey c) Brute – Force d) Sutherland – Hodgman
  • 48. PROGRAM NO – 09 Date ……………………. OBJECT WAP TO MULTIPLY TWO GIVEN MATRICES ALGORITHM 1. 2. 3. 4. 5. 6. 7. 8. 9. Initialize First Matrix let it be A(m)(n). Read the order of First Matrix, let m=3,n=3 Input Data to the elements of the First Matrix Initialize Second Matrix let it be (q)(r) Read the order of Second Matrix, let q=3,r=3 Input Data elements of the Second Matrix Check the Possibility of Multiplication between two matrices If possibility exists apply the following formula C(i)(j)=c(i)(j) + a(i)(k) * b(k)(j) And Store the values into a New matrix, let it be C(m)(r) 10. Otherwise terminate the program messaging that multiplication is not possible. 11. Print the Result on Console. 12. Stop. SAMPLE PROGRAM # include<stdio.h> #include<conio.h> void main() { Int i,j.k; int a[3][3],b[3][3],c[3][3]; clrsr(); printf(“Enter values for the First Array ROW WISE n”);
  • 49. for(i=0;i<3;i++) { printf(“Enter value for a [%d][%d]=”,i+1,j+1); scanf(“%d”,&a[i][j]); }//End of inner for loop } printf(“enter values for the Second Array ROW WISE n”); for(i=0;i<3;i++) { for (j=0;j<3;j++) { printif(“Enter value for a {%d}[%d]=”.i+1.j+1; scanf(%d”,&b[i][j]; } //End of inner for loop } printf(“nn”); //Multiplication of Above Two Array and Storing the values into another Array C printf(Multiplication of the above Two Matrices is nn”); printf(“************************************************************************ ****** nnn”); for(i=0;i<3;i++) { c[i][j]=0
  • 50. for(int k=0;k<3;k++) { C[i][j]=c[i][j] + a[i][k] * b[k][j]; } } } //printing of the Multiplied array for(i=0;i<3,i++) { //printing of Array A[i][j] printf (“|”); for(j=0;j<3;j++) { printf(“%5d”,a[i][j]; } printf(“|”); If(i==0) printf(“*”); else printf(“”); //Printing of Array B[i][j] printf(“|”) for(j=0;j<3;J++)
  • 51. { printf (“%5d”,b[i][j][j]; } printf(“|”); //Printing of Array C[i][j] If (i==0) printf(“ =”); Else printf(“ “); printf(“ | “); for(j=0;j<3;j++) { printf(“%5d”,c[i][j]); } printf(“|n”); }//End of Outer for loop printf(“nnn”****************************************************************** **********nnn”); gotoxy(1,48); printf(“Press Any Key to Continue….”); getch(); return; }//End of the Main()
  • 52. INPUT OUTPUT THEORETICAL QUESTIONS 1. 2. 3. 4. 5. What is Subscripted Variable ? What is One dimensional array variable ? What is Two Dimensional array variable ? What is the necessary condition for the two Matrix to be Multiplied ? What is the use of Matrix ? OBJECTIVE QUESTIONS 1. The declaration of an array variable like A[10] is an example of a) 1 b)2 c)3 d)4 ….dimensional array. 2. The declaration of an array variable like B[10][10] is an example of a)1 b)2 c)3 d)4 …. Dimensional array. 3. The declaration of an array variable like C[10][10] is an example of a)1 b)2 c)3 d)4 ……dimensional array. 4. The no.of elements in the variable declaration like intA[5] will be a)2 b)5 c)4 d)10 5. The no.of elements in the variable declaration like int A[5][5] will be a)10 b)25 c)20 d)50
  • 53. PROGRAM NO-10 Date……………………… OBJECT WAP TO DRAW CUBIC SPLINE ALGORITHM 1. 2. 3. 4. Initialize the values of coefficients Initialize the value of parameter u, Set a proper increment Calculate the coordinate of various points using the parametric equation of CUBIC SPLINE i.e X=a0 + a1 * u + a2 * u2 +a3 * u3 and Y= b0 + b1 * u + b2 * u2 + b3 * u3 5. Plot the different values on the graphics mode 6. Stop SAMPLE PROGRAM # include < stdio.h> #include<conio.h> #include<dos.h> #include<process.h> #include<graphics.h> #include<math.h> Void initialize – Graphics(); Void Draw _ Axis(int dx,int dy); Int datum_y=450; Int datum _x=10;
  • 54. //Start of the main() void main() { float a[4]; float b[4]; float x,y; printf(“Enter the value of Coefficients for x Co-ordinaten”); for(int i=0;i<4;i++) { printf(“Enter the value of a(%d) = “.a[i]; scanf (“% of”,&a[i]); } printf (“Enter the value of Coefficients for y Co-ordinate n”); /* initialize graphics mode */ initgraph (&gdriver,&gmode,”d;tcc”); /*read result of initialization */ Errorcode = graphresult(); if (errorcode ! = grOk) /* an error occurred * / { printf (“Graphics error: %sn”, grapherrorms(errorcode)); printf(“Press any key to halt:”);
  • 55. getch(); exit(1); /* return with error code */ } /*draw a line */ outtextxy(250,40,”CUBIC SPLINE”); /* clean up */ } void Draw_Axis(int dx, int dy) { for(int i=0;i<620,i++) putpixel(dx+i,dy,WHITE); //Draw Horizontal Line for(i=0;i<400;i++) putpixel(dx,dy-i,WHITE); //Draw Vertical Line return; } INPUT OUTPUT GRAPH THEORETICAL QUESTIONS 1. 2. 3. 4. 5. What is a Cubic Spline ? What are the applications of the Cubic Spline ? What is the range of value of parameter „u‟ in case of Cubic Spline? How it is different from Bezier Curve? How multisegment Cubic Splines are made ?
  • 56. OBJECTIVE QUESTIONS 1. The value of parameter „u‟ in case of cubic spline will be A1 b)2 c)3 d)4 2. No.of Control points in a Cubic Spline is a)1 b)2 c)0 d)4 3. The equation y = a0 + a1 * X2 +a3 *X3 is a)Cartesian b) Polar c)Parametric d)Complex … form of equation. 4.The equation y=y= a0 +a1 * X +a2 * X2 + a3 *X3, where X is a parameter ………………………………is a a) Cartesian b) Polar c) Paramertic …………………….. form of equation. 5. Y=a1 + a2 X + a3 X2 is the equation of a) Slope b) Normal of a Cubic Spline. c) Asymptote None of these d)Complex