112k views
3 votes
Write a program to model the first letter of your first, middle or last name using cubic Bézier curves. Also:

- Plot the letter with the control points
- Plot the letter without displaying the control points
- Try to modify the shape of the letter by relocating and/or adding more control points. Show the results of at least one modification.

1 Answer

3 votes

Answer:

see explaination for program code

Step-by-step explanation:

Bezier curve is often used to model smooth curves. Below is the c program to implement bezier curve in c.

#include <stdio.h>

#include <stdlib.h>

#include <graphics.h>

#include <math.h>

void bezier (int x[4], int y[4])// procedure to implement bezier curve

{

int gd = DETECT, gm;

int i;

double t;

initgraph (&gd, &gm, "..\\bgi"); //initialization of graph

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];//calculating of points

putpixel (xt, yt, WHITE);//plotting

}

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.\\");

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

scanf ("%d%d", &x[i], &y[i]);

bezier (x, y);

}

User Sabbir
by
5.5k points