- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find mirror image of a point in 2-D plane in C++

In this problem, we are given a point P in a 2-D plane and the points a, b, c of the equation ax + by + c = 0. Our task is to find a mirror image of a point in 2-D plane.

**Let’s take an example to understand the problem,**

## Input

P = (2, 1), a = 1, b = -1, c = 0

## Output

(1, 2)

## Explanation

The plane looks like,

## Solution Approach

To solve the problem, we need to find the equation point P' with coordinates (x', y'). So, we have R, the midpoint where the line form P - P' intersects the mirror line.

The line P-R-P' is perpendicular to the mirror. Hence, the equation of line will be,

ay - by + d = 0

The points are P(x, y) ; P'(x', y') ; R(xm, ym).

The points P and R are known. So, using the equations we will find P’ as,

$$\left(\frac{??'-??}{??}\right)=\left(\frac{??'-??}{??}\right)=\left(\frac{????-????+??}{??^2+x^2}\right)$$

**Program to illustrate the working of our solution,**

## Example

#include <iostream> using namespace std; void findMirrorImage( double a, double b, double c, double x, double y){ double points = -2 * (a * x + b * y + c) / (a * a + b * b); double xm = points * a + x; double ym = points * b + y; cout<<"("<<xm<<","<<ym<<")"; } int main(){ double a = -1.0; double b = 1.0; double c = 0.0; double x = 1.0; double y = 0.0; cout<<"Image of point ("<<x<<", "<<y<<") using mirror ("<<a<<")x + ("<<b<<")y + ("<<c<< ") = 0, is :"; findMirrorImage(a, b, c, x, y); return 0; }

## Output

Image of point (1, 0) using mirror (-1)x + (1)y + (0) = 0, is :(0,1)

- Related Questions & Answers
- Validating a square in a 2-D plane in JavaScript
- Finding distance between two points in a 2-D plane using JavaScript
- Find foot of perpendicular from a point in 2D plane to a Line in C++
- C++ Program to find out the moves to read a point from another point in a 2D plane
- C++ Program to Check if a Point d lies inside or outside a circle defined by Points a, b, c in a Plane
- Print the Mirror Image of Sine-Wave Pattern in C
- Create a mirror image with CSS
- Emulating a 2-d array using 1-d array in C++
- C++ Program to check whether points in a 3-D plane are Coplanar
- Find mirror of a given node in Binary tree in C++
- Print a 2 D Array or Matrix in C#
- Find 2^(2^A) % B in C++
- Count of parallelograms in a plane in C++
- C++ Program for triangular pattern (mirror image around 0)
- Sum of the mirror image nodes of a complete binary tree in an inorder way in C++