Find the Missing Point of a Parallelogram

Last Updated : 17 Sep, 2026

Given the coordinates of three points a, b, and c, find the coordinates of the fourth point d such that abcd forms a parallelogram. 

Since three different parallelograms can be formed using the given three points, return the lexicographically smallest possible coordinates of d.

frame_3770

A point P(x1, y1) is lexicographically smaller than Q(x2, y2) if:

  • x1 < x2, or
  • x1 == x2 and y1 < y2.

Return the coordinates of the required point with a precision of 6 decimal places.

Note: The given three points are guaranteed to be non-collinear.

Examples:

Input: a = (3, 2), b = (3, 4), c = (2, 2)
Output: [2.000000, 0.000000]
Explanation: There are two options for point d : (2, 4) and (2, 0) such that abcd forms a parallelogram. Since (2, 0) is lexicographically smaller than (2, 4). Hence, (2, 0) is the answer.

Input: a = (1, 1), b = (2, 3), c = (4, 2)
Output: [3.000000, 0.000000]
Explanation: There are three possible coordinates for point d: (5, 4) (3, 0) (-1, 4) Among these, (3, 0) is the lexicographically smallest valid point. Hence, the answer is (3.000000, 0.000000).

Try It Yourself
redirect icon

Using the Diagonal Midpoint Property - O(1) Time and O(1) Space

The diagonals of a parallelogram bisect each other, so their midpoints are always the same. By treating each of the three given points as the vertex opposite the missing point, we can calculate three possible fourth vertices. We then choose the lexicographically smallest one.

frame_3771

Suppose, AC and BD are diagonals of a parallelogram, and diagonals of a parallelogram bisect each other. So their midpoints must be equal:

\frac{A+C}{2} = \frac{B+D}{2}

Multiply both sides by 2, we get -> A + C = B + D

Rearranging, we get -> D = A + C - B

That's where the formula comes from.

  • Use the property that the diagonals of a parallelogram bisect each other.
  • Find the first possible point by considering A and D as opposite vertices: D1​ = B + C − A
  • Find the second possible point by considering B and D as opposite vertices: D2​ = A + C − B
  • Find the third possible point by considering C and D as opposite vertices: D3​ = A + B − C
  • Compare them lexicographically: first compare x, then y if x is equal.
  • Return the lexicographically smallest candidate.
C++
#include 
using namespace std;

vector<double> findPoint(vector<int> &a, vector<int> &b, vector<int> &c)
{
    // If A and D are opposite vertices,
    // diagonals AD and BC have the same midpoint.
    // Therefore:
    // A + D = B + C
    // D = B + C - A
    pair<double, double> d1 = {b[0] + c[0] - a[0], b[1] + c[1] - a[1]};

    // If B and D are opposite vertices:
    // B + D = A + C
    // D = A + C - B
    pair<double, double> d2 = {a[0] + c[0] - b[0], a[1] + c[1] - b[1]};

    // If C and D are opposite vertices:
    // C + D = A + B
    // D = A + B - C
    pair<double, double> d3 = {a[0] + b[0] - c[0], a[1] + b[1] - c[1]};

    // pair comparison in C++ is lexicographical.
    // Hence, min() directly gives the required point.
    pair<double, double> ans = min({d1, d2, d3});

    return {ans.first, ans.second};
}

int main()
{
    vector<int> a = {3, 2};
    vector<int> b = {3, 4};
    vector<int> c = {2, 2};

    vector<double> ans = findPoint(a, b, c);

    cout << fixed << setprecision(6);
    cout << ans[0] << " " << ans[1] << "\n";

    return 0;
}
Java
import java.util.*;

class GFG {
    public static List<Double> findPoint(int[] a, int[] b,
                                         int[] c)
    {
        // If A and D are opposite vertices:
        // A + D = B + C
        // D = B + C - A
        double[] d1
            = { b[0] + c[0] - a[0], b[1] + c[1] - a[1] };

        // If B and D are opposite vertices:
        // B + D = A + C
        // D = A + C - B
        double[] d2
            = { a[0] + c[0] - b[0], a[1] + c[1] - b[1] };

        // If C and D are opposite vertices:
        // C + D = A + B
        // D = A + B - C
        double[] d3
            = { a[0] + b[0] - c[0], a[1] + b[1] - c[1] };

        // Find the lexicographically smallest point.
        double[] ans = d1;

        if (d2[0] < ans[0]
            || (d2[0] == ans[0] && d2[1] < ans[1])) {
            ans = d2;
        }

        if (d3[0] < ans[0]
            || (d3[0] == ans[0] && d3[1] < ans[1])) {
            ans = d3;
        }

        // Return the answer as List.
        return Arrays.asList(ans[0], ans[1]);
    }

    public static void main(String[] args)
    {
        int[] a = { 3, 2 };
        int[] b = { 3, 4 };
        int[] c = { 2, 2 };

        List<Double> ans = findPoint(a, b, c);

        System.out.printf("%.6f %.6f%n", ans.get(0),
                          ans.get(1));
    }
}
Python
def findPoint(a, b, c):

    # If A and D are opposite vertices:
    # A + D = B + C
    # D = B + C - A
    d1 = [
        b[0] + c[0] - a[0],
        b[1] + c[1] - a[1]
    ]

    # If B and D are opposite vertices:
    # B + D = A + C
    # D = A + C - B
    d2 = [
        a[0] + c[0] - b[0],
        a[1] + c[1] - b[1]
    ]

    # If C and D are opposite vertices:
    # C + D = A + B
    # D = A + B - C
    d3 = [
        a[0] + b[0] - c[0],
        a[1] + b[1] - c[1]
    ]

    # Python compares lists lexicographically,
    # so min() directly gives the required point.
    ans = min(d1, d2, d3)

    return [float(ans[0]), float(ans[1])]


# Driver Code
if __name__ == "__main__":
    a = [3, 2]
    b = [3, 4]
    c = [2, 2]

    ans = findPoint(a, b, c)

    print(f"{ans[0]:.6f} {ans[1]:.6f}")
C#
using System;
using System.Collections.Generic;

class GFG {
    static List<double> findPoint(int[] a, int[] b, int[] c)
    {
        // If A and D are opposite vertices:
        // A + D = B + C
        // D = B + C - A
        double[] d1
            = { b[0] + c[0] - a[0], b[1] + c[1] - a[1] };

        // If B and D are opposite vertices:
        // B + D = A + C
        // D = A + C - B
        double[] d2
            = { a[0] + c[0] - b[0], a[1] + c[1] - b[1] };

        // If C and D are opposite vertices:
        // C + D = A + B
        // D = A + B - C
        double[] d3
            = { a[0] + b[0] - c[0], a[1] + b[1] - c[1] };

        // Find the lexicographically smallest point.
        double[] ans = d1;

        if (d2[0] < ans[0]
            || (d2[0] == ans[0] && d2[1] < ans[1])) {
            ans = d2;
        }

        if (d3[0] < ans[0]
            || (d3[0] == ans[0] && d3[1] < ans[1])) {
            ans = d3;
        }

        // Return the answer as List.
        return new List<double>{ ans[0], ans[1] };
    }

    static void Main()
    {
        int[] a = { 3, 2 };
        int[] b = { 3, 4 };
        int[] c = { 2, 2 };

        List<double> ans = findPoint(a, b, c);

        Console.WriteLine($"{ans[0]:F6} {ans[1]:F6}");
    }
}
JavaScript
function findPoint(a, b, c)
{
    // If A and D are opposite vertices:
    // A + D = B + C
    // D = B + C - A
    const d1 = [ b[0] + c[0] - a[0], b[1] + c[1] - a[1] ];

    // If B and D are opposite vertices:
    // B + D = A + C
    // D = A + C - B
    const d2 = [ a[0] + c[0] - b[0], a[1] + c[1] - b[1] ];

    // If C and D are opposite vertices:
    // C + D = A + B
    // D = A + B - C
    const d3 = [ a[0] + b[0] - c[0], a[1] + b[1] - c[1] ];

    // Find the lexicographically smallest point.
    const points = [ d1, d2, d3 ];

    let ans = points[0];

    for (let i = 1; i < points.length; i++) {

        // Compare x-coordinates first.
        // If x is equal, compare y-coordinates.
        if (points[i][0] < ans[0]
            || (points[i][0] === ans[0]
                && points[i][1] < ans[1])) {
            ans = points[i];
        }
    }

    return ans;
}

// Driver Code
const a = [ 3, 2 ];
const b = [ 3, 4 ];
const c = [ 2, 2 ];

const ans = findPoint(a, b, c);

console.log(`${ans[0].toFixed(6)} ${ans[1].toFixed(6)}`);

Output
2.000000 0.000000
Comment