4 control points – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sun, 10 Mar 2024 17:04:43 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg 4 control points – Programmerbay https://programmerbay.com 32 32 C Program to draw Bezier Curve using 4 control points https://programmerbay.com/c-program-to-draw-bezier-curve-using-4-control-points/ https://programmerbay.com/c-program-to-draw-bezier-curve-using-4-control-points/#respond Sat, 24 Feb 2024 16:41:31 +0000 https://www.programmerbay.com/?p=2143 Bezier Curve is one of the Curve representation which uses control points to draw a curve. It is always determined on the number of control points that require to draw it. It follows Bernstein polynomial as the basis function.

Must Read [  What is Bezier Curve ?  ]

C Program to draw a Bezier curve

Program:

#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>
void main()
{
int x[4],y[4],i;
double put_x,put_y,t;
int gr=DETECT,gm;
initgraph(&gr,&gm,"C:\\TURBOC3\\BGI");
printf("\n****** Bezier Curve ***********");
printf("\n Please enter x and y coordinates ");
for(i=0;i<4;i++)                 
{
scanf("%d%d",&x[i],&y[i]);
putpixel(x[i],y[i],3);                // Control Points
}

for(t=0.0;t<=1.0;t=t+0.001)             // t always lies between 0 and 1
{
put_x = pow(1-t,3)*x[0] + 3*t*pow(1-t,2)*x[1] + 3*t*t*(1-t)*x[2] + pow(t,3)*x[3]; // Formula to draw curve
put_y =  pow(1-t,3)*y[0] + 3*t*pow(1-t,2)*y[1] + 3*t*t*(1-t)*y[2] + pow(t,3)*y[3];
putpixel(put_x,put_y, WHITE);            // putting pixel 
}
getch();
closegraph();
}

 

Output:

bezier curve

 

]]>
https://programmerbay.com/c-program-to-draw-bezier-curve-using-4-control-points/feed/ 0