Given two points coordinates (x1, y1) and (x2, y2)on 2D plane. The task is to find the reflection of (x1, y1) at 180 degree rotation of (x2, y2).
Input : x1 = 0, y1 = 0, x2 = 1, y2 = 1 Output : (2, 2) Input : x1 = 1, y1 = 1, x2 = 2, y2 = 2 Output : (3, 3)
Let the reflection point of point (x1, y1) about (x2, y2) be (x’, y’).
For (x’, y’) be the 180 degree rotation of point (x1, y1) around point (x2, y2), they all must be collinear i.e all the three point must lie on a same straight line. Also, observe (x2, y2) will became mid point between (x1, y1) and (x’, y’).
x’ – x2 = x2 – x1
y’ – y2 = y2 – y1
x’ = 2 * x2 – x1
y’ = 2 * y2 – y1
Below is the implementation of this approach:
Time Complexity : O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Rotation of a point about another point in C++
- Reflection of a point about a line in C++
- Mirror of a point through a 3 D plane
- Triangle with no point inside
- Find the other end point of a line with given one end and mid
- First collision point of two series
- Distance between a point and a Plane in 3 D
- Satisfy the parabola when point (A, B) and the equation is given
- Check whether given floating point number is even or odd
- Shortest distance between a point and a circle
- Perpendicular distance between a point and a Line in 2 D
- Finding the best fit rectangle that covers a given point
- Program to find the mid-point of a line
- Bitonic point in the given linked list
- Check whether the point (x, y) lies on a given line
- Find normal at a given point on the curve
- Program for Point of Intersection of Two Lines
- Find the Missing Point of Parallelogram
- Check if a point is inside, outside or on the parabola
- Sum of two large Floating-point numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.