0% found this document useful (0 votes)
16 views3 pages

Practical No09

Uploaded by

Shubham Mulik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Practical No09

Uploaded by

Shubham Mulik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No.

09
/*Write a 'C' program for 2D Reflection and for (i = 0; i < n; i++) {
Shear.*/ for (j = 0; j < 3; j++) {
#include <stdio.h> for (k = 0; k < 3; k++) {
#include <conio.h> a[i][j] = a[i][j] + (c[i][k] * b[k][j]);
#include <graphics.h> }
#include <math.h> }
#include <process.h> }
}
void disp(int n, float c[][3]) {
float maxx, maxy; void reflection(int n, float c[][3]) {
int i; float b[10][3], a[10][3];
int i = 0, ch, j;
maxx = getmaxx();
maxy = getmaxy(); cleardevice();
maxx = maxx / 2; printf("\n\t** MENU **");
maxy = maxy / 2; printf("\n\t1) ABOUT X-AXIS");
printf("\n\t2) ABOUT Y-AXIS");
i = 0; printf("\n\t3) ABOUT ORIGIN");
printf("\n\t4) ABOUT X=Y");
while (i < n - 1) { printf("\n\t5) ABOUT -X=Y");
line(maxx + c[i][0], maxy - c[i][1], maxx + printf("\n\t6) EXIT");
c[i + 1][0], maxy - c[i + 1][1]); printf("\n\tENTER YOUR CHOICE: ");
i++; scanf("%d", &ch);
}
cleardevice();
i = n - 1; disp(n, c);
line(maxx + c[i][0], maxy - c[i][1], maxx +
c[0][0], maxy - c[0][1]); for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
setcolor(GREEN); b[i][j] = 0;
line(0, maxy, maxx * 2, maxy); if (i == j)
line(maxx, 0, maxx, maxy * 2); b[i][j] = 1;
setcolor(WHITE); }
} }

void mul(int n, float b[][3], float c[][3], float switch (ch) {


a[][3]) { case 1:
int i, j, k; b[1][1] = -1;
break;
for (i = 0; i < n; i++) { case 2:
for (j = 0; j < 3; j++) { b[0][0] = -1;
a[i][j] = 0; break;
} case 3:
b[0][0] = -1;
} b[1][1] = -1;
break; for (i = 0; i < 3; i++) {
case 4: for (j = 0; j < 3; j++) {
b[0][0] = 0; b[i][j] = 0;
b[1][1] = 0; }
b[0][1] = 1; }
b[1][0] = 1;
break; for (i = 0; i < 3; i++) {
case 5: b[i][i] = 1;
b[0][0] = 0; }
b[1][1] = 0;
b[0][1] = -1; switch (ch) {
b[1][0] = -1; case 1:
break; b[1][0] = sh;
case 6: break;
return; case 2:
default: b[0][1] = sh;
printf("\n\tINVALID CHOICE!"); break;
return; default:
} printf("\n\tINVALID CHOICE!");
return;
mul(n, b, c, a); }
setcolor(RED);
disp(n, a); mul(n, b, c, a);
} setcolor(RED);
disp(n, a);
void shearing(int n, float c[][3]) { }
float b[10][3], sh, a[10][3];
int i = 0, ch, j; void main() {
int i, n, cho, gd = DETECT, gm;
cleardevice(); float c[10][3];
printf("\n\t*** MENU ***");
printf("\n\t1) X SHEARING"); initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
printf("\n\t2) Y SHEARING");
printf("\n\t3) EXIT"); printf("\nEnter the number of vertices: ");
printf("\n\tENTER YOUR CHOICE: "); scanf("%d", &n);
scanf("%d", &ch);
for (i = 0; i < n; i++) {
if (ch == 3) printf("\nEnter the coordinates of vertex
return; %d: ", i + 1);

printf("\n\tENTER THE VALUE for


SHEARING: ");
scanf("%f", &sh);

cleardevice();
scanf("%f%f", &c[i][0], &c[i][1]);
c[i][2] = 1;
}

do {
clrscr();
cleardevice();

printf("\n\t\t*** MENU ***");


printf("\n\t1) REFLECTION");
printf("\n\t2) SHEARING");
printf("\n\t3) EXIT");
printf("\n\tENTER YOUR CHOICE: ");
scanf("%d", &cho);

switch (cho) {
case 1:
cleardevice();
setcolor(BLUE);
disp(n, c);
reflection(n, c);
getch();
break;
case 2:
cleardevice();
setcolor(BLUE);
disp(n, c);
shearing(n, c);
getch();
break;
case 3:
exit(0);
break;
default:
printf("\n\tInvalid choice!!");
break;
}
} while (cho != 3);

closegraph();
}

You might also like