#include #include #include #include #include void Curve(int x1, int y1, int x2, int y2,int x3, int y3,int x4, int y4, float); void curve(int x1, int y1, int x2, int y2,int x3, int y3,int x4, int y4, float); void main() { int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver, &gmode, "c:\\la\\tc\\bgi"); int x1=500 , y1=400; int x2=300 , y2=10; int x3=100, y3=300 ; int x4=100 , y4=100; curve(x1, y1, x2, y2, x3, y3, x4, y4, 10.0); Curve(x1, y1, x2, y2, x3, y3, x4, y4, 100.0); setcolor(4); circle(x1,y1,5); circle(x2,y2,5); circle(x3,y3,5); circle(x4,y4,5); getch(); closegraph(); } void Curve(int x1, int y1, int x2, int y2,int x3, int y3,int x4, int y4, float Step) { double x,y,t,Step_Size, ax, ay, bx, by, cx, cy, dx = (float) x1, dy = (float) y1; Step_Size = 1.0 /Step; ax = -x1 + (3 * x2) - (3 * x3) + x4; ay = -y1 + (3 * y2) - (3 * y3) + y4; bx = (3 * x1) - (6 * x2) + (3 * x3); by = (3 * y1) - (6 * y2) + (3 * y3); cx = (-3 * x1) + (3 * x2); cy = (-3 * y1) + (3 * y2); moveto(x1,y1); for (int i = 0 ; i <= Step; i++) { t = Step_Size * i; x = (ax *t*t*t) + (bx*t*t) + (cx*t) +dx; y = (ay *t*t*t) + (by*t*t) + (cy*t) +dy; lineto(x, y); } } void curve(int x1, int y1, int x2, int y2,int x3, int y3,int x4, int y4, float Step) { float x, y, u; float Step_Size = 1.0 /Step; for(int i = 0; i < Step; i++) { u = Step_Size * i; x = pow((1 - u), 3.0) * x1 + 3 * pow((1 - u), 2.0) * u * x2 + 3 * (1 - u) * u * u * x3 + u * u * u * x4; y = pow((1 - u), 3.0) * y1 + 3 * pow((1 - u), 2.0) * u * y2 + 3 * (1 - u) * u * u * y3 + u * u * u * y4; putpixel(x, y, 15); } }