Reflection of a Point at 180-Degree Rotation of Another Point


What do you understand by the heading `Reflection of a point at 180−degree rotation of another point`? Let’s decode it in this article.

Let's assume we have two points (x1, y1) and (x2, y2) in a 2−D plane.

Where (x2, y2) is the point of rotation and (x1, y1) is the point to be reflected.

Now, suppose x1,y1 is rotated 180 degrees across x2,y2 , and we get x1`,y1`.

Now, we can observe that, if we are given 2 points in a 2−d plane with one of the points rotating across the second point it results in 3 collinear points, and also the point across which the other point is rotated comes in the middle of the straight line joining the three points.

Based on these observations, we can use the following steps to find the coordinates of the reflected point.

  • Calculate the difference between the point to be reflected and the point of rotation. That is, calculate (x1−x2) and (y1−y2).

  • To reflect the point, we need to add the difference to the point of rotation. That is, the reflected point will be (x2+(x2−x1), y2+(y2−y1)).

  • Simplifying the equation, we get the reflected point as (2x2−x1, 2y2−y1).

Therefore, to reflect a point (x1, y1) at a 180−degree rotation of another point (x2, y2), we need to calculate the reflected point using the equation (2x2−x1, 2y2−y1).

For example, let's assume we have a point (4, 6) that needs to be reflected at a 180−degree rotation of another point (2, 2). The reflected point can be calculated as (2*2−4, 2*2−6), which is (0, −2) or (0, 2) after simplification.

Approach

Now, we have a clear idea of the logic which should go into solving this question. Let’s jot down the step−by−step approach to convert the discussed logic into a program.

  • Take the coordinates of the two points as user input.

  • Calculate the coordinates of the reflection point using the formula (x2+(x2−x1), y2+(y2−y1)).

  • Print the reflection point to the console.

C++ code implementation

All theory and no code make jack a dull boy. Let's do some code now.

Here is the c++ implementation to find the coordinates of the Reflection of a point at a 180−degree rotation of another point.

Example

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    double x1 = 0;
double y1 = 0;
double x2 = 1;
double y2 = 1;
   
        
    // Calculate the coordinates of the reflected point
    double xr = x2 + (x2 - x1);
    double yr = y2 + (y2 - y1);
    
    cout << "The reflection of point (" << x1 << ", " << y1 << ") at 180-degree rotation of point (" << x2 << ", " << y2 << ") is (" << xr << ", " << yr << ").";
    
    return 0;
}

Output

The reflection of point (0, 0) at 180-degree rotation of point (1, 1) is (2, 2).

Space Complexity : O(1)

Time Complexity : O(1)

Conclusion

In this article, we have covered the logic involved in calculating the coordinates of the reflection point, for the Reflection of a point at 180−degree rotation of another point, when 2 points are given. Hope you had a clear idea of the concept involved and the code executed.

Updated on: 23-Aug-2023

78 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements