# Codewars Points of Reflection Solution Javascript / C / C++ (8 kyu)

This is the solution for the Codewars Points of Reflection question in Javascript or C or C++ with a simple & easy to understand code and explanation. The logic will be the same in all the languages.

Given two points P and Q, output the symmetric point of point P about Q. Each argument is a two-element array of integers representing the point’s X and Y coordinates. The output should be in the same format, giving the X and Y coordinates of point P1. You do not have to validate the input.

Here’s the link to the kata – Points of Reflection

## Solution to Points of Reflection Question:

The way to solve the Points of Reflection question is with the help of the midpoint formula, as we know (first coordinate + second coordinate) / 2 gives us the midpoint, then Midx = (Rx + Px) / 2 => Rx = 2Midx – Px and same for the y-axis: Midy = (Ry + Py) / 2 => Ry = 2Midy – Py. Here’s the detailed explanation:

We know that the points P and Q are symmetrical, so we should find the reflected point from point P and passes through Q.

The midpoint formula says Mid = (P + R)/2, by using mathematics to solve the equation we get Reflection, R = 2Q – P (Q = Midpoint). We apply this formula to find the x & y coordinates of R.

``````//solution style 1 - input: p & q are arrays

function symmetricPoint(p, q) {
return [ 2*q-p, 2*q-p ];
}``````
``````//solution style 2 - point p & q is in p[x,y] ,q[x,y] axis format

function symmetricPoint([a, b], [c, d]) {
return  [c * 2 - a, d * 2 - b];
}``````