#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
int n;
void reset (int h[][2])
{
int i,j,val[50][2];
printf("\n enter no of sides");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&val[i][j]);
}
}
for (i=0; i<n; i++)
{
h[i][0] = val[i][0];
h[i][1] = val[i][1];
}
}
void draw (int h[][2])
{
int i;
setlinestyle (SOLID_LINE, 0, 1);
for (i=0; i<n-1; i++)
line (320+h[i][0], 240-h[i][1], 320+h[i+1][0], 240-h[i+1][1]);
line (320+h[0][0], 240-h[0][1], 320+h[n-1][0], 240-h[n-1][1]);
}
void rotate (int h[][2], float angle)
{
int i;
for (i=0; i<n; i++)
{
int xnew, ynew;
xnew = h[i][0] * cos (angle) - h[i][1] * sin (angle);
ynew = h[i][0] * sin (angle) + h[i][1] * cos (angle);
h[i][0] = xnew; h[i][1] = ynew;
}
}
void reflect (int h[][2], int m, int c)
{
int i;
float angle;
for (i=0; i<n; i++)
h[i][1] -= c;
angle = M_PI/2 - atan (m);
rotate (h, angle);
for (i=0; i<n; i++)
h[i][0] = -h[i][0];
angle = -angle;
rotate (h, angle);
for (i=0; i<n; i++)
h[i][1] += c;
}
void ini()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
}
void dini()
{
getch();
closegraph();
}
void main()
{
int h[50][2],c;
float m;
printf ("Enter the values of m and c: ");
scanf ("%f%d", &m, &c);
reset (h);
ini();
setlinestyle (DOTTED_LINE, 0, 1);
line (320, 0, 320, 480);
line (0, 240, 640, 240);
draw (h);
getch();
setcolor(RED);
reflect (h, m, c);
draw (h);
dini();
}
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
int n;
void reset (int h[][2])
{
int i,j,val[50][2];
printf("\n enter no of sides");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&val[i][j]);
}
}
for (i=0; i<n; i++)
{
h[i][0] = val[i][0];
h[i][1] = val[i][1];
}
}
void draw (int h[][2])
{
int i;
setlinestyle (SOLID_LINE, 0, 1);
for (i=0; i<n-1; i++)
line (320+h[i][0], 240-h[i][1], 320+h[i+1][0], 240-h[i+1][1]);
line (320+h[0][0], 240-h[0][1], 320+h[n-1][0], 240-h[n-1][1]);
}
void rotate (int h[][2], float angle)
{
int i;
for (i=0; i<n; i++)
{
int xnew, ynew;
xnew = h[i][0] * cos (angle) - h[i][1] * sin (angle);
ynew = h[i][0] * sin (angle) + h[i][1] * cos (angle);
h[i][0] = xnew; h[i][1] = ynew;
}
}
void reflect (int h[][2], int m, int c)
{
int i;
float angle;
for (i=0; i<n; i++)
h[i][1] -= c;
angle = M_PI/2 - atan (m);
rotate (h, angle);
for (i=0; i<n; i++)
h[i][0] = -h[i][0];
angle = -angle;
rotate (h, angle);
for (i=0; i<n; i++)
h[i][1] += c;
}
void ini()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
}
void dini()
{
getch();
closegraph();
}
void main()
{
int h[50][2],c;
float m;
printf ("Enter the values of m and c: ");
scanf ("%f%d", &m, &c);
reset (h);
ini();
setlinestyle (DOTTED_LINE, 0, 1);
line (320, 0, 320, 480);
line (0, 240, 640, 240);
draw (h);
getch();
setcolor(RED);
reflect (h, m, c);
draw (h);
dini();
}
No comments:
Post a Comment