Bezier Curve

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>

void bezier(int x[41],int y[4])
{
    int gd=DETECT,gm;
    int i;
    double t,xt,yt;
    initgraph(&gd,&gm,"c:\\tc\\bgi");
    for(t=0.0;t<1.0;t+=00.0005)
    {
        xt=pow(1-t,3)*x[0]+t*pow(1-t,2)*x[1]+3*pow(t,2)*(1-t)*x[2]+pow(t,3)*x[3];
        yt=pow(1-t,3)*y[0]+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;
}

void main()
{
    int x[4],y[4],i;
    printf("\nEnter the X and Y coordinates of the four control points:");
    for(i=0;i<4;i++)
        scanf("%d%d",&x[i],&y[i]);
    bezier(x,y);
}

Output
bezier.png

bezier op.png

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s