Find the all the possible coordinate from the given three coordinates to make a parallelogram of a non-zero area.
Let’s call A,B,C are the three given points. We can have only the three possible situations:
(1) AB and AC are sides, and BC a diagonal (2) AB and BC are sides, and AC a diagonal (3) BC and AC are sides, and AB a diagonal
Hence, we can say that only 3 coordinates are possible from which we can generate a parallelogram if three coordinates are given.
To prove that all the three points are different let’s suppose it’s wrong. Without losing of generality suppose that the points got in cases AD and BC are equal.
Consider the system of two equations for the equality of these points:
Bx + Cx - Ax = Ax + Cx - Bx By + Cy - Ay = Ay + Cy - By It can be simplified as- Ax = Bx Ay = By
And we got a contradiction, as all the points A, B, C are distinct.
Input : A = (0 0) B = (1 0) C = (0 1) Output : 1 -1 -1 1 1 1 Input : A = (-1 -1) B = (0 1) C = (1 1) Output : -2 -1 0 -1 2 3
Since the opposite sides are equal, AD = BC and AB = CD, we can calculate the co-ordinates of the missing point (D) as:
AD = BC (Dx - Ax, Dy - Ay) = (Cx - Bx, Cy - By) Dx = Ax + Cx - Bx Dy = Ay + Cy - By
The cases where the diagonals are AD and BC, CD and AB are processed in the same way.
Below is the implementation of above approach:
4, -4 6, 4 -2, 1
Time Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program to find the Area of a Parallelogram
- Find the Missing Point of Parallelogram
- Find area of parallelogram if vectors of two adjacent sides are given
- Find the coordinates of a triangle whose Area = (S / 2)
- Find the other-end coordinates of diameter in a circle
- Find whether only two parallel lines contain all coordinates points or not
- Program to find the Type of Triangle from the given Coordinates
- Find minimum area of rectangle with given set of coordinates
- Find the original coordinates whose Manhattan distances are given
- Find coordinates of the triangle given midpoint of each side
- Find coordinates of a prime number in a Prime Spiral
- Program for Circumference of a Parallelogram
- Area of a triangle inside a parallelogram
- Check whether four points make a parallelogram
- Perimeter and Area of Varignon's Parallelogram
- Coordinates of rectangle with given points lie inside
- Minimum length of square to contain at least half of the given Coordinates
- Check if a right-angled triangle can be formed by the given coordinates
- Count of integral coordinates that lies inside a Square
- Check if a right-angled triangle can be formed by moving any one of the coordinates
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : vt_m