Finding reflection of a point relative to another point in JavaScript

Point reflection, also known as point symmetry, is a geometric transformation where a point P is reflected across a midpoint Q to create a new point P' that is equidistant from Q but in the opposite direction.

P(6, -4) Q(11, 5) P'(16, 14) distance d distance d Point Reflection: P reflected across Q gives P'

The Formula

To find the reflection of point P across point Q, we use the formula:

  • P'x = 2 × Qx - Px
  • P'y = 2 × Qy - Py

Implementation

Here's how to implement point reflection in JavaScript:

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));
{ x: 16, y: 14 }

Alternative Approach Using Direct Formula

We can simplify the function using the direct formula:

const findReflectionDirect = (p, q) => {
    return {
        x: 2 * q.x - p.x,
        y: 2 * q.y - p.y
    };
};

// Test with same points
const point = { x: 6, y: -4 };
const center = { x: 11, y: 5 };

console.log(findReflectionDirect(point, center));
{ x: 16, y: 14 }

How It Works

The reflection works by:

  1. Finding the distance vector from Q to P
  2. Extending the same distance from Q in the opposite direction
  3. The formula P' = 2Q - P achieves this mathematically

Multiple Points Example

const reflectPoints = (points, center) => {
    return points.map(point => ({
        x: 2 * center.x - point.x,
        y: 2 * center.y - point.y
    }));
};

const points = [
    { x: 1, y: 2 },
    { x: 5, y: 7 },
    { x: -2, y: 3 }
];
const center = { x: 0, y: 0 };

console.log(reflectPoints(points, center));
[
  { x: -1, y: -2 },
  { x: -5, y: -7 },
  { x: 2, y: -3 }
]

Conclusion

Point reflection uses the formula P' = 2Q - P to find the symmetric point across a center. This geometric transformation is useful in graphics programming and mathematical applications.

Updated on: 2026-03-15T23:19:00+05:30

425 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements