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.
- Find all possible coordinates of parallelogram
- Program to find the Area of a Parallelogram
- Find area of parallelogram if vectors of two adjacent sides are given
- Find the missing value from the given equation a + b = c
- Find n-variables from n sum equations with one missing
- Find the repeating and the missing number using two equations
- Find the missing number in Arithmetic Progression
- Find the smallest positive number missing from an unsorted array | Set 3
- Find the other end point of a line with given one end and mid
- Program to find the mid-point of a line
- Find normal at a given point on the curve
- Program to find the Break Even Point
- Find Tangent at a given point on the curve
- Find if a point lies inside a Circle
- Find a point such that sum of the Manhattan distances is minimized