# Finding reflection of a point relative to another point in JavaScript

JavascriptWeb DevelopmentFront End Technology

#### JavaScript for beginners

Best Seller

74 Lectures 10 hours

#### Modern Javascript for Beginners + Javascript Projects

Most Popular

112 Lectures 15 hours

#### The Complete Full-Stack JavaScript Course!

Best Seller

96 Lectures 24 hours

## Point Of Symmetry

"Point reflection" or "point symmetry" is a basic concept in geometry where a given point, P, at a given position relative to a midpoint, Q has a corresponding point, P1, which is the same distance from Q but in the opposite direction.

## Problem

We are required to write a JavaScript function that takes in two objects P and Q specifying two points in a 2-D plane.

Our function should output the symmetric point of point P about Q.

## Example

Following is the code −

Live Demo

const p = {
x: 6, y: -4
};
const q = {
x: 11, y: 5
};
const findReflection = (p = {}, q = {}) => {
const res = {};
const Xdistance = p['x'] - q['x'];
res['x'] = q['x'] - Xdistance;
let Ydistance = p['y'] - q['y'];
res['y'] = q['y'] - Ydistance;
return res;
};
console.log(findReflection(p, q));

## Output

Following is the console output −

{ x: 16, y: 14 }