You are on page 1of 14

Experiment Title:3.

Student Name: Naman Chahal UID: 19BCS1522


Branch: B.E. (CSE) Section/Group: 19BCS 3(B)
Semester: 5th Date of Performance: 16/11/2021
Subject Name: Computer Graphics Lab Subject Code: CSP-305

1. Aim/Overview of the practical:

AIM-To calculate and draw a Bezier curve passing through four control
points. AIM-To draw a B-Spline curve.

2. Steps for experiment/practical/Code:

To calculate and draw a Bezier curve passing through four control points.

for (u= 0.0; u<1.0; u=u+0.0005)

double xt = pow (1-u,3) * x[0] + 3 * u * pow (1-u,2) * x[1]

+ 3 * pow (u, 2) * (1-u) * x[2] + pow (u, 3) * x[3];

double yt = pow (1-u,3) * y[0] + 3 * u * pow (1-u, 2) * y[1]

+ 3 * pow (u, 2) * (1-u) * y[2] + pow (u,3) * y[3];

putpixel (xt, yt, YELLOW);

}
To draw a B-Spline curve.

val=((stpos-knot[i])*basis(i,k-1,knot,stpos))/(knot[i+k-1]-knot[i])+((knot[i+k]-stpos)*basis(i+1,k-
1,knot,stpos))/(knot[i+k]-knot[i+1]);

return(val);

void main()

int gm,gd=DETECT;

int xc[6]={10,80,250,400,500,550}; //control

points int yc[6]={180,130,10,700,50,70};

double knot[]={0,1,2,3,4,5,6,7}; //knot vector


 PROGRAM:-

TO CALCULATE AND DRAW A BEZIER CURVE PASSING THROUGH FOUR CONTROL POINTS.

#include<stdio.h>

#include<dos.h>

#include<stdlib.h>

#include<graphics

. h>

#include<math.h>

void bezier (int x[4], int y[4])

doubl

e t; int

i;

for (t = 0.0; t < 1.0; t += 0.0005)

double xt = pow (1-t, 3) * x[0] + 3 * t * pow (1-t, 2)

* x[1] + 3 * pow (t, 2) * (1-t) * x[2] + pow (t, 3) *

x[3]; double yt = pow (1-t, 3) * y[0] + 3 * t * pow (1-

t, 2) * y[1] + 3 * pow (t, 2) * (1-t) * y[2] + pow (t, 3) *


y[3];
putpixel (xt, yt, WHITE);

for (i=0; i<4; i++)

putpixel (x[i], y[i], YELLOW);

getch();

closegraph

); return;

int main()

int x[4],

y[4]; int i;

int gd = DETECT,

gm=0; initgraph(&gd,

&gm, (char*)"");

line(100,100,100,400);
printf ("Enter the x- and y-coordinates of the four control points.\n");

for (i=0; i<4; i++)

scanf ("%d%d",

&x[i],

&y[i]); bezier (x,

y); return 0;

TO DRAW A B-SPLINE CURVE:-

#include<stdio.h>

#include<dos.h>

#include<stdlib.h>

#include<graphics

. h>

#include<math.h>

double basis(int i, int k, double knot[],double stpos)

double val; //recursion


if(k==1)

if(knot[i]<=stpos&&stpos<knot[i+1])

return(1);

else

return(0

val=((stpos-knot[i])*basis(i,k-1,knot,stpos))/(knot[i+k-1]-
knot[i])+((knot[i+k]-
stpos)*basis(i+1,k-1,knot,stpos))/(knot[i+k]- knot[i+1]);

return(val);

int main()

int gm,gd=DETECT;
int xc[6]={10,80,250,400,500,550};

//control points int

yc[6]={180,130,10,700,50,70};

double knot[]={0,1,2,3,4,5,6,7};

//knot vector initgraph(&gd,&gm,

(char*)"");

int k=4,i;

double bas,stpos=knot[k-1],endpos=knot[8-

k],slice=(endpos- stpos)/100; double x,y,lx,ly;

lx=xc[0]; //first point

ly=yc[0];

for(;stpos<endpos;stpos+=slice)

x=y=0;
for(i=1;i<=6;i

+)

{
bas=basis(i-1,k,knot,stpos); x=x+

(xc[i-1]*bas); //x,y for

bspline curves y=y+(yc[i-1]*bas);

line(lx,ly,x,y);

lx=x; //last

point ly=y;

getch();

closegraph

); return 0;

}
 RESULT:-

To calculate and draw a Bezier curve passing through four control points.
NAAC
GRADE&"BY"
ACABEMICAFFAIRS
Disro•er. Lea rn. Empower.
ACCREDITED UNIVERSITY
 TO DRAW A B-SPLINE CURVE:-
4. Learning outcomes (What I have learnt):

1. Learned about designing shapes using graphics.

2. Learned about #include<graphics.h> library.

3. Learned about gdriver ,gmode,DETECT commands.

4. Learned about calculate and draw a Bezier curve and To draw a B-Spline curve.

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):
Sr. No. Parameters Marks Obtained Maximum Marks
1.
2.
3.

You might also like