Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int MAX = 5;
- const double PI = 3.14;
- void GetCords(float mat1[][MAX], float mat2[][MAX], int n) {
- int i, j;
- for (i = 0; i < n; i++) {
- printf("\n Enter Coordinate no %d:- \n", i + 1);
- for (j = 0; j < 2; j++) {
- scanf("%f", &mat1[j][i]);
- }
- }
- for (i = 0; i < n; i++) {
- mat2[0][i] = mat1[0][i];
- mat1[0][i] = 320 + mat1[0][i];
- mat2[1][i] = mat1[1][i];
- mat1[1][i] = 240 - mat1[1][i];
- }
- setcolor(GREEN);
- line(0, 240, 640, 240);
- outtextxy(630, 245, "x");
- line(320, 0, 320, 480);
- outtextxy(310, 0, "y");
- outtextxy(280, 245, "(0,0)");
- setcolor(YELLOW);
- moveto(mat1[0][0], mat1[1][0]);
- for (i = 0; i < n; i++) {
- lineto(mat1[0][i], mat1[1][i]);
- moveto(mat1[0][i], mat1[1][i]);
- }
- lineto(mat1[0][0], mat1[1][0]);
- }
- void Scale(float mat2[][MAX], int n) {
- int sx, sy, i, j, k;
- float tmat[MAX][MAX], tot[MAX][MAX];
- printf("\n Enter the Scale value of x: ");
- scanf("%d", &sx);
- printf("\n Enter the Scale value of y: ");
- scanf("%d", &sy);
- tmat[0][0] = sx;
- tmat[0][1] = 0;
- tmat[1][0] = 0;
- tmat[1][1] = sy;
- for (i = 0; i < 2; i++) {
- for (j = 0; j < n; j++) {
- tot[i][j] = 0;
- for (k = 0; k < 2; k++) {
- tot[i][j] = tot[i][j] + (tmat[i][k] * mat2[k][j]);
- }
- }
- }
- for (i = 0; i < n; i++) {
- tot[0][i] = 320 + tot[0][i];
- tot[1][i] = 240 - tot[1][i];
- }
- setcolor(LIGHTRED);
- moveto(tot[0][0], tot[1][0]);
- for (i = 0; i < n; i++) {
- lineto(tot[0][i], tot[1][i]);
- moveto(tot[0][i], tot[1][i]);
- }
- lineto(tot[0][0], tot[1][0]);
- }
- void Rotate(float mat2[][MAX], int n) {
- int ang, i, j, k;
- float tmat[MAX][MAX], tot[MAX][MAX];
- float rad;
- printf("\n Enter the Angle (in Degrees):- \n");
- scanf("%d", &ang);
- rad = (ang * PI) / 180;
- tmat[0][0] = cos(rad);
- tmat[0][1] = -sin(rad);
- tmat[1][0] = sin(rad);
- tmat[1][1] = cos(rad);
- for (i = 0; i < 2; i++) {
- for (j = 0; j < n; j++) {
- tot[i][j] = 0;
- for (k = 0; k < 2; k++) {
- tot[i][j] = tot[i][j] + (tmat[i][k] * mat2[k][j]);
- }
- }
- }
- for (i = 0; i < n; i++) {
- tot[0][i] = 320 + tot[0][i];
- tot[1][i] = 240 - tot[1][i];
- }
- setcolor(LIGHTRED);
- moveto(tot[0][0], tot[1][0]);
- for (i = 0; i < n; i++) {
- lineto(tot[0][i], tot[1][i]);
- moveto(tot[0][i], tot[1][i]);
- }
- lineto(tot[0][0], tot[1][0]);
- }
- void pointRotate(float mat2[][MAX], int n) {
- int ang, i, j, k;
- float tmat[MAX][MAX], tot[MAX][MAX];
- float rad;
- int px, py;
- // Get a Point.
- px = mat2[0][0];
- py = mat2[1][0];
- printf("\n Enter the Angle (in Degrees):- \n");
- scanf("%d", &ang);
- // Inv Translation to Origin.
- for (i = 0; i < n; i++) {
- mat2[0][i] -= px;
- mat2[1][i] -= py;
- }
- // Rotation.
- rad = (ang * PI) / 180;
- tmat[0][0] = cos(rad);
- tmat[0][1] = -sin(rad);
- tmat[1][0] = sin(rad);
- tmat[1][1] = cos(rad);
- for (i = 0; i < 2; i++) {
- for (j = 0; j < n; j++) {
- tot[i][j] = 0;
- for (k = 0; k < 2; k++) {
- tot[i][j] = tot[i][j] + (tmat[i][k] * mat2[k][j]);
- }
- }
- }
- // Translate from the Origin.
- for (i = 0; i < n; i++) {
- tot[0][i] += px;
- tot[1][i] += py;
- }
- for (i = 0; i < n; i++) {
- tot[0][i] = 320 + tot[0][i];
- tot[1][i] = 240 - tot[1][i];
- }
- setcolor(LIGHTRED);
- moveto(tot[0][0], tot[1][0]);
- for (i = 0; i < n; i++) {
- lineto(tot[0][i], tot[1][i]);
- moveto(tot[0][i], tot[1][i]);
- }
- lineto(tot[0][0], tot[1][0]);
- }
- void Translate(int mat[][MAX], int n) {
- int dx, dy, i;
- printf("\n Enter Cordinates (dx, dy):- \n");
- scanf("%d %d", &dx, &dy);
- for (i = 0; i < n; i++) {
- mat[0][i] += dx;
- mat[1][i] -= dy;
- }
- setcolor(LIGHTRED);
- moveto(mat[0][0], mat[1][0]);
- for (i = 0; i < n; i++) {
- lineto(mat[0][i], mat[1][i]);
- moveto(mat[0][i], mat[1][i]);
- }
- lineto(mat[0][0], mat[1][0]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement