Given a point P in 2-D plane and equation of mirror, the task is to find the image of that point Q formed due to the mirror.
Equation of mirror is in form ax + by + c =
Input : P = (1, 0), a = -1, b = 1, c = 0 Output : Q = (0, 1) Input : P = (3, 3), a = 0, b = 1, c = -2 Output : Q = (3, 1)
Let coordinate of P(given point) be (x1, y1) Let coordinate of Q(image point) be (x2, y2) Let coordinate of R(point on mirror) be (x3, y3)
Since object and image are equidistant from mirror, R must be middle point of P and Q
Since equation of mirror is given to be: ax + by + c = 0. Equation of line passing through P and Q is perpendicular to mirror. Therefore equation of line passing through P and Q becomes ay – bx + d = 0, Also P passes through line passing through P and Q, so we put coordinate of P in above equation,
a*y1 – b*x1 + d = 0
d = b*x1 – a*y1
Also R is intersection of mirror and line passing through P and Q. So we find solution of
ax + by + c = 0
ay -bx + d = 0
Since a, b, c, d all are known we can find x and y here. Since coordinates of R is known now ie.. x3, y3 are known now.
Since R is middle point of PQ,
(x3, y3) = ((x1+x2)/2, (y1+y2)/2)
Since x1, y1, x3, y3 are known, we get below equation where (x, y) are coordinates of Q(image point)
We use above formula to find mirror image of point P(x1, y1) with respect to mirror of equation ax + by + c
Image of point (1, 0) by mirror (-1)x + (1)y + (0) = 0, is :(0, 1)
This article is contributed by Pratik Chhajer. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Check whether a given point lies inside a triangle or not
- How to check if a given point lies inside or outside a polygon?
- Given n line segments, find if any two segments intersect
- Find if two rectangles overlap
- Find Simple Closed Path for a given set of points
- Triangle with no point inside
- Optimum location of point to minimize total distance
- Find all sides of a right angled triangle from given hypotenuse and area | Set 1
- Find perimeter of shapes formed with 1s in binary matrix
- Count of parallelograms in a plane
- Check whether a point exists in circle sector or not.
- Find an Integer point on a line segment with given two ends
- Program to find area of a triangle
- Program to find area of a circle
- Find all angles of a given triangle