Last active
September 10, 2020 18:07
-
-
Save AakashCode12/3577735fdad67acf5948c28ebcf78141 to your computer and use it in GitHub Desktop.
Done Finally by Matrix style
This file contains hidden or 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 <stdio.h> | |
#include <iostream.h> | |
#include <conio.h> | |
#include <math.h> | |
#include <stdlib.h> | |
#include <dos.h> | |
#include <graphics.h> | |
//!global Variables | |
int arr[2][2], scale[2][2], rotationAngle, shearx[2][2], shearY[2][2]; | |
int arrref[2][2], radiusref; | |
//!The Function prototyping | |
//!Axis Plotting | |
void axis() | |
{ | |
//!box Plot | |
line(0, 0, 400, 0); | |
line(0, 0, 0, 400); | |
line(0, 400, 400, 400); | |
line(400, 0, 400, 400); | |
//?Axis plot | |
line(200, 0, 200, 400); | |
line(0, 200, 400, 200); | |
} | |
//!done by matrix | |
void transform() | |
{ | |
cout << "\n2D Translation"; | |
cout << "\nEnter the Translation parameters (tx ,ty) : "; | |
cin >> arr[1][0]; | |
cin >> arr[1][1]; | |
//todo Transformations | |
//!Translation | |
arr[1][0] = arr[1][0] + arr[0][0]; | |
arr[1][1] = arr[1][1] + arr[1][0]; | |
putpixel(arr[0][0], arr[1][0], 15); | |
line(arr[0][0], arr[1][0], arr[1][0], arr[1][1]); | |
getch(); | |
cleardevice(); | |
} | |
//!done by matrix | |
void Scaling() | |
{ | |
cout << "\n2D Scaling Transformations"; | |
cout << "\nA Ellipse will be plotted with center as (X,Y)\n"; | |
cout << "\nEnter the Rx and Ry : "; | |
cin >> arr[0][1]; | |
cin >> arr[1][1]; | |
int start_angle = 0; | |
int end_angle = 360; | |
scale[0][0] = 1; // sx = 1 initially | |
scale[1][1] = 1; //sy = 1; | |
ellipse(arr[0][0], arr[1][0], start_angle, end_angle, scale[0][0] * arr[0][1], scale[1][1] * arr[1][1]); | |
getch(); | |
cout << "\nEnter the Scaling parameters (Sx ,Sy) : "; | |
cin >> scale[0][0]; | |
cin >> scale[1][1]; | |
ellipse(arr[0][0], arr[1][0], start_angle, end_angle, scale[0][0] * arr[0][1], scale[1][1] * arr[1][1]); | |
getch(); | |
cleardevice(); | |
} | |
//!done by matrix | |
void Rotation() | |
{ | |
cout << "\n2D Rotation Transformations"; | |
getch(); | |
cout << "\nThis is the line from (0,0) to (X,Y) : "; | |
line(0, 0, arr[0][0], arr[1][0]); | |
getch(); | |
cout << "\nEnter the Roation Angle (Degrees Clockwise Rotation): "; | |
cin >> rotationAngle; | |
double radiansRotationAngle = (3.142 * rotationAngle) / 180; | |
arr[0][1] = arr[0][0] * cos(radiansRotationAngle) - arr[1][0] * sin(radiansRotationAngle); | |
arr[1][1] = arr[0][0] * sin(radiansRotationAngle) + arr[1][0] * cos(radiansRotationAngle); | |
cout << "\nThis is the rotated line : "; | |
line(0, 0, arr[0][1], arr[1][1]); | |
getch(); | |
cleardevice(); | |
} | |
//!done matrix | |
void Shear() | |
{ | |
cout << "\n2D Shear Transformations"; | |
getch(); | |
cout << "\nEnter the Shear Parameters (Shear x , Shear y): "; | |
cin >> shearX[0][1]; | |
cin >> shearY[1][0]; | |
cleardevice(); | |
cout << "\nX Shear"; | |
//!Old Square | |
line(0, 0, arr[0][0], 0); | |
line(0, 0, 0, arr[0][1]); | |
line(arr[0][0], 0, arr[0][0], arr[0][1]); | |
line(0, arr[0][1], arr[0][0], arr[0][1]); | |
getch(); | |
cleardevice(); | |
//!X Shear Sqaure | |
line(0, 0, arr[0][0], 0); | |
line(arr[0][0], 0, arr[0][0] + shearX[0][1], arr[0][1]); | |
line(shearX[0][1], arr[0][1], arr[0][0] + shearX[0][1], arr[0][1]); | |
line(0, 0, shearX[0][1], arr[0][1]); | |
getch(); | |
cleardevice(); | |
cout << "\nY Shear"; | |
//!Old Square | |
line(0, 0, arr[0][0], 0); | |
line(0, 0, 0, arr[0][1]); | |
line(arr[0][0], 0, arr[0][0], arr[0][1]); | |
line(0, arr[0][1], arr[0][0], arr[0][1]); | |
getch(); | |
cleardevice(); | |
//!Y Shear Sqaure | |
line(0, 0, 0, arr[0][1]); | |
line(0, arr[0][1]), arr[0][0], arr[0][1] + shearY[1][0]); | |
line(0, 0, arr[0][0], shearY[1][0]); | |
line(arr[0][0], shearY[1][0], arr[0][0], arr[0][1] + shearY[1][0]); | |
getch(); | |
} | |
void Reflection() | |
{ | |
cleardevice(); | |
cout << "\nEnter the X AND Y Coordinates : "; | |
cin >> arrref[0][0]; | |
cin >> arrref[0][1]; | |
cout << "Enter the Radius : "; | |
cin >> radiusref; | |
cleardevice(); | |
//!Axis | |
axis(); | |
//!Initial Circle | |
circle(200 + arrref[0][0], 200 - arrref[0][1], radiusref); | |
getch(); | |
//!2nd Quadrant Circle | |
circle(200 - arrref[0][0], 200 - arrref[0][1], radiusref); | |
getch(); | |
//!3rd Quadrant Circle | |
circle(200 - arrref[0][0], 200 + arrref[0][1], radiusref); | |
getch(); | |
//!4th Quadrant Circle | |
circle(200 + arrref[0][0], 200 + arrref[0][1], radiusref); | |
getch(); | |
} | |
void main() | |
{ | |
clrscr(); | |
int gd = DETECT, gm; | |
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); | |
cleardevice(); | |
cout << "Enter the Initial Coordiantes ( X , Y ) :"; | |
cin >> arr[0][0]; | |
cin >> arr[1][0]; | |
cout << " \n*(IMP:: We will Use this X and Y throughout this program ) "; | |
getch(); | |
cleardevice(); | |
//!2D Transformations (Done) | |
transform(); | |
//!2D Scaling Trans formations (Done) | |
Scaling(); | |
//!2D Rotation Transforamtion (Done) | |
Rotation(); | |
//!2D Shear Transformations (Done) | |
Shear(); | |
//!2D Reflection | |
Reflection(); | |
closegraph(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
K reflection me Teen hi karne the so done dana done done