Program-4: Write A Program To Implement 2D Reflection of An Object
Program-4: Write A Program To Implement 2D Reflection of An Object
Types of Reflection:
1.Reflection about the x-axis
2.Reflection about the y-axis
3.Reflection about an axis perpendicular to xy plane and passing through the origin
4.Reflection about line y=x
Code:
#include "graphics.h"
#include<iostream>
#define PI 3.14159265
using namespace std;
int main()
{
double m, c;
int delta = 250;
cout << " Reflection of a 2D object [CIRCLE]" << endl;
cout << endl;
initwindow(500, 500, "Reflection of a 2D object");
cout << "Enter radius and centre (x,y) [space separated] ";
int r, x, y;
cin >> r >> x >> y;
circle(delta + x, delta - y, r);
cout << "Reflection about y=mx+c => Enter m & c [space-separated] ";cin >> m >>
c;
double rx, ry;
getxy(m, c, x, y, rx, ry);
line(delta - 150, delta - (c - 150 * m), delta + 150, delta - (c + 150 * m));
circle(int(rx + 0.5) + delta, delta - int(ry + 0.5), r);
while (!kbhit())
{
delay(200);
}
return 0;
}
Result:
Learning Outcome:
Through this code we learnt how to reflect points along a line by calcultaing the
corresponding points according to the line.