Given three coordinate points A, B and C, find the missing point D such that ABCD can be a parallelogram.
Input : A = (1, 0) B = (1, 1) C = (0, 1) Output : 0, 0 Explanation: The three input points form a unit square with the point (0, 0) Input : A = (5, 0) B = (1, 1) C = (2, 5) Output : 6, 4
A quadrilateral is said to be a parallelogram if its opposite sides are parallel and equal in length.
As we’re given three points of the parallelogram, we can find the slope of the missing sides as well as their lengths.
The algorithm can be explained as follows
Let R be the missing point. Now from definition, we have
- Length of PR = Length of QS = L1 (Opposite sides are equal)
- Slope of PR = Slope of QS = M1 (Opposite sides are parallel)
- Length of PQ = Length of RS = L2 (Opposite sides are equal)
- Slope of PQ= Slope of RS = M2 (Opposite sides are parallel)
Thus we can find the points at a distance L1 from P having slope M1 as mentioned in below article :
Find points at a given distance on a line of given slope.
Now one of the points will satisfy the above conditions which can easily be checked (using either condition 3 or 4).
Below is the program for the same.
0, 0 6, 4
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
Below is the implementation of above approach:
This article is contributed by Ashutosh Kumar 😀 and Abhishek Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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.
- Find all possible coordinates of parallelogram
- Find area of parallelogram if vectors of two adjacent sides are given
- Program to find the Area of a Parallelogram
- Check whether four points make a parallelogram
- Program for Circumference of a Parallelogram
- Area of a triangle inside a parallelogram
- Perimeter and Area of Varignon's Parallelogram
- Length of a Diagonal of a Parallelogram using the length of Sides and the other Diagonal
- Length of diagonal of a parallelogram using adjacent sides and angle between them
- Program to calculate area of a parallelogram
- Rotation of a point about another point in C++
- Reflection of a point at 180 degree rotation of another point
- Find n-variables from n sum equations with one missing
- Find the missing digit x from the given expression
- Find the missing value from the given equation a + b = c
- Find the repeating and the missing number using two equations
- Find the smallest positive number missing from an unsorted array | Set 3
- Find the last two missing digits of the given phone number
- Find the missing number in unordered Arithmetic Progression
- Find temperature of missing days using given sum and average