0% found this document useful (0 votes)
88 views

2D Reflection - Own My Code - AngularJS, JS, JQuery, C, C++,C Graphics, Mini Project, Computer Programming

This C program allows the user to input coordinates for a 2D polygon and perform X or Y reflections on it. The user first enters the number of sides and coordinates for the polygon. They can then choose to reflect the polygon across the X or Y axis, or exit. The reflections are performed by applying the appropriate trigonometric functions to the coordinates. The original and reflected polygons are drawn on the screen after each operation.

Uploaded by

SakthiKotti
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)
88 views

2D Reflection - Own My Code - AngularJS, JS, JQuery, C, C++,C Graphics, Mini Project, Computer Programming

This C program allows the user to input coordinates for a 2D polygon and perform X or Y reflections on it. The user first enters the number of sides and coordinates for the polygon. They can then choose to reflect the polygon across the X or Y axis, or exit. The reflections are performed by applying the appropriate trigonometric functions to the coordinates. The original and reflected polygons are drawn on the screen after each operation.

Uploaded by

SakthiKotti
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/ 2

7/10/2015

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

2D Reflection | Own My Code - AngularJS, JS, JQuery, C,C++,C Graphics,Mini Project,Computer Programming

#include <stdio.h>
#include <stdlib.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void draw2d(int,int [],int [],int,int);
void main()
{
int gd=DETECT,gm;
int x[20],y[20],x1[20],y1[20],tx=0,ty=0,i,fs;
initgraph(&gd,&gm,"");
printf("No of sides : ");
scanf("%d",&fs);
printf("Co-ordinates : ");
for(i=0;i<fs;i++)
{
printf("(x%d,y%d)",i,i);
scanf("%d%d",&x[i],&y[i]);
}
draw2d(fs,x,y,tx,ty);
printf("translation (x,y) : ");
scanf("%d%d",&tx,&ty);
while(1)
{
clrscr();
cleardevice();
printf("1. X Reflection\n\n2. Y Reflection\n\n3. Exit");
draw2d(fs,x,y,0,0);
switch(getche())
{
case '1':
for(i=0;i<fs;i++)
{
x1[i]=(tx+((x[i]-tx)*cos(M_PI))-((y[i]-ty)*sin(M_PI)));
y1[i]=y[i];
}
break;
case '2':
for(i=0;i<fs;i++)
{
x1[i]=x[i];
y1[i]=(tx+((y[i]-ty)*cos(M_PI))+((x[i]-tx)*sin(M_PI)));
}
break;
case '3':
closegraph();
exit(0);
}
draw2d(fs,x1,y1,tx,ty);
getch();
}
}

http://ownmycode.blogspot.in/2012/09/2d-reflection.html

1/2

7/10/2015

53
54
55
56
57
58
59
60
61
62
63

2D Reflection | Own My Code - AngularJS, JS, JQuery, C,C++,C Graphics,Mini Project,Computer Programming

void draw2d(int fs,int x[20],int y[20],int tx,int ty)


{
int i;
for(i=0;i<fs;i++)
{
if(i!=(fs-1))
line(x[i]+tx,y[i]+ty,x[i+1]+tx,y[i+1]+ty);
else
line(x[i]+tx,y[i]+ty,x[0]+tx,y[0]+ty);
}
}

http://ownmycode.blogspot.in/2012/09/2d-reflection.html

2/2

You might also like