0% found this document useful (0 votes)
366 views3 pages

Assignment - 10: Q1. Write A Graphics Program To Implement Bezier Curve Code

The document contains code to implement a Bezier curve and draw an ellipse using Bezier curves in C graphics programming. It takes input of control points from the user, initializes the graphics mode, and uses parametric equations to calculate pixel coordinates along the curve at small time increments from 0 to 1 to draw the curve in red pixels.

Uploaded by

ritesh sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
366 views3 pages

Assignment - 10: Q1. Write A Graphics Program To Implement Bezier Curve Code

The document contains code to implement a Bezier curve and draw an ellipse using Bezier curves in C graphics programming. It takes input of control points from the user, initializes the graphics mode, and uses parametric equations to calculate pixel coordinates along the curve at small time increments from 0 to 1 to draw the curve in red pixels.

Uploaded by

ritesh sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ASSIGNMENT -10

Q1. Write a graphics program to implement Bezier curve

CODE:
//Implementation of bezier curve
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
int gd=DETECT,gm;
int a[4],b[4],i;
float xt,yt,t;
printf("Enter the four control points:\n");
for(i=0;i<4;i++)
{
scanf("%d%d",&a[i],&b[i]);
}
initgraph(&gd,&gm,"");
line(a[0],b[0],a[1],b[1]);
line(a[1],b[1],a[2],b[2]);
line(a[2],b[2],a[3],b[3]);
line(a[3],b[3],a[0],b[0]);
for(t=0.0;t<=1.0;t=t+0.0001)
{
xt=pow(1-t,3)*a[0]+3*t*pow(1-t,2)*a[1]+3*pow(t,2)*(1-t)*a[2]+pow(t,3)*a[3];
yt=pow(1-t,3)*b[0]+3*t*pow(1-t,2)*b[1]+3*pow(t,2)*(1-t)*b[2]+pow(t,3)*b[3];
putpixel(xt,yt,RED);
}
getchar();
closegraph();
}
INTPUT:

OUTPUT:

Q2. Write a graphics program to draw ellipse using Bezier cure


CODE:
//ellipse by the help of Bezier curve
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
int gd=DETECT,gm;
int a[6],b[6],i;
float xt,yt,t;
printf("Enter the six control points:\n");
for(i=0;i<6;i++)
{
scanf("%d%d",&a[i],&b[i]);
}
initgraph(&gd,&gm,"");
for(t=0.0;t<=1.0;t=t+0.0001)
{
xt=pow(1-t,3)*a[0]+3*t*pow(1-t,2)*a[1]+3*pow(t,2)*(1-t)*a[2]+pow(t,3)*a[3];
yt=pow(1-t,3)*b[0]+3*t*pow(1-t,2)*b[1]+3*pow(t,2)*(1-t)*b[2]+pow(t,3)*b[3];
putpixel(xt,yt,RED);
}
for(t=0.0;t<=1.0;t=t+0.0001)
{
xt=pow(1-t,3)*a[0]+3*t*pow(1-t,2)*a[4]+3*pow(t,2)*(1-t)*a[5]+pow(t,3)*a[3];
yt=pow(1-t,3)*b[0]+3*t*pow(1-t,2)*b[4]+3*pow(t,2)*(1-t)*b[5]+pow(t,3)*b[3];
putpixel(xt,yt,RED);
}
getchar();
closegraph();
}

INTPUT:

OUTPUT:

You might also like