C Program – Implement Bezier curves for a given set of control points.

by Nideesh C on April 17, 2011 · 0 comments

in C Programming




#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include <math.h>
 
void bezier (int x[4], int y[4])
{
    int gd = DETECT, gm;
    int i;
    double t;
 
    initgraph (&gd, &gm, "..\\bgi");
 
    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;
}
 
void main()
{
    int x[4], y[4];
    int i;
 
    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);
}



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C Program – Fill any given polygon using scan-line area filling algorithm
  2. C program to accept a set of numbers and compute mean, variance and standard deviation
  3. C Program – Implement 3-D rotation with respect to x-axis, y-axis and z-axis
  4. C++ Program – implement Linear Search algorithm
  5. C++ program to implement Shell sort using class

Leave a Comment

Previous post:

Next post: