Last active
July 1, 2018 03:34
-
-
Save TheEyesightDim/395bcd5b538f25e18baf852937adaaf4 to your computer and use it in GitHub Desktop.
Inversion of a point around another point
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//point inversion | |
#include <vector> | |
#include <iostream> | |
struct Point { int x, y; }; | |
struct Line { Point petal, center; }; | |
//reflects Point 'mover' across another Point 'focus'. | |
//'focus' is the midpoint of 'mover' and the return value. | |
Point invert_point(const Point mover, const Point focus){ | |
return Point{2 * focus.x - mover.x, 2 * focus.y - mover.y}; | |
} | |
int main() | |
{ | |
std::vector<Line> lines; | |
std::vector<Point> mirror; | |
int count; | |
std::cin >> count; | |
lines.reserve(count); | |
mirror.reserve(count); | |
Line tmpL; | |
Point tmpP; | |
while(std::cin >> tmpL.petal.x >> tmpL.petal.y >> tmpL.center.x >> tmpL.center.y) | |
lines.push_back(tmpL); | |
for(auto& l : lines) | |
mirror.push_back(invert_point(l.petal, l.center)); | |
for(const auto& p : mirror) | |
std::cout << p.x << ' ' << p.y << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment