Created
October 29, 2020 08:19
-
-
Save AakashCode12/8072c2e3a216e44c915ae745eef1f968 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream.h> | |
#include <conio.h> | |
#include <math.h> | |
#include <stdlib.h> | |
#include <dos.h> | |
#include <graphics.h> | |
//Todo prototyping | |
void BezierThreePoints(); | |
void BezierFourPoints(); | |
// todo 3 Points Bezier | |
void BezierThreePoints() | |
{ | |
cout << "3 Points Bezier Curve"; | |
cout << "\n Enter the 3 points\n"; | |
int x1, y1, x2, y2, x3, y3; | |
cin >> x1 >> y1; | |
cin >> x2 >> y2; | |
cin >> x3 >> y3; | |
putpixel(x1, y1, WHITE); | |
putpixel(x2, y2, WHITE); | |
putpixel(x3, y3, WHITE); | |
//todo P = (1−t)2P1 + 2(1−t)tP2 + t2P3 | |
double x = 0.0, y = 0.0; | |
for (double t = 0.0; t <= 1; t = t + 0.001) | |
{ | |
x = (1 - t) * (1 - t) * x1 + 2 * (1 - t) * (t)*x2 + t * t * x3; | |
y = (1 - t) * (1 - t) * y1 + 2 * (1 - t) * (t)*y2 + t * t * y3; | |
putpixel(x, y, YELLOW); | |
} | |
} | |
//todo 4 Points Bezier | |
void BezierFourPoints() | |
{ | |
cout << "4 Points Bezier Curve"; | |
cout << "\n Enter the 4 points\n"; | |
int x1, y1, x2, y2, x3, y3, x4, y4; | |
cin >> x1 >> y1; | |
cin >> x2 >> y2; | |
cin >> x3 >> y3; | |
cin >> x4 >> y4; | |
putpixel(x1, y1, WHITE); | |
putpixel(x2, y2, WHITE); | |
putpixel(x3, y3, WHITE); | |
putpixel(x4, y4, WHITE); | |
//todo P = (1−t)^3*P1 + 3(1−t)^2*t*P2 +3(1−t)t^2P3 + t^3P4 | |
double x = 0.0, y = 0.0; | |
for (double t = 0.0; t <= 1; t = t + 0.001) | |
{ | |
x = (1 - t) * (1 - t) * (1 - t) * x1 + 3 * (1 - t) * (1 - t) * (t)*x2 + 3 * (1 - t) * (t) * (t)*x3 + t * t * t * x4; | |
y = (1 - t) * (1 - t) * (1 - t) * y1 + 3 * (1 - t) * (1 - t) * (t)*y2 + 3 * (1 - t) * (t) * (t)*y3 + t * t * t * y4; | |
putpixel(x, y, YELLOW); | |
} | |
} | |
void main() | |
{ | |
clrscr(); | |
int gd = DETECT, gm; | |
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); | |
cout << "BEZIER CURVE\n"; | |
cout << "\n1) 3 Point\n2) 4 Point \nEnter your options: \n"; | |
int option; | |
cin >> option; | |
switch (option) | |
{ | |
case 1: | |
BezierThreePoints(); | |
break; | |
case 2: | |
BezierFourPoints(); | |
break; | |
default: | |
cout << "\n Invalid option"; | |
break; | |
} | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment