Given three coordinates (x, y), which are the midpoint of the sides of the triangle. The task is to find the coordinates of the triangle.
Input : midx1 = 5, midy1 = 3 midx2 = 4, midy2 = 4 midx3 = 5, midy3 = 5 Output : x1 = 4 y1 = 2 x2 = 4 y2 = 6 x3 = 6 y3 = 4 Solution can be verified by the figure.
Let’s separately solve for X-coordinates and Y-coordinates. For X coordinate of vertices, let them be x1, x2, x3. Then, X-coordinate of middel points will be (x1 + x2)/2, (x2 + x3)/2, (x3 + x1)/2. Observe, sum of these 3 expressions is equal to sum of X-coordinates. Now, we have sum of 3 varibles and 3 expressions for sum of every pair of them, find out the values of coordinates by solving equations.
Similarly, we solve for Y-coordinates.
Below is the implemenetation of this approach:
6 4 4 2 4 6
Time Complexity : O(1)
This article is contributed by Anuj Chauhan. 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 the coordinates of a triangle whose Area = (S / 2)
- Program to find the Type of Triangle from the given Coordinates
- Program to find third side of triangle using law of cosines
- Check if a right-angled triangle can be formed by moving any one of the coordinates
- Minimum and maximum possible length of the third side of a triangle
- Find all possible coordinates of parallelogram
- Find the other-end coordinates of diameter in a circle
- Find minimum area of rectangle with given set of coordinates
- Find whether only two parallel lines contain all coordinates points or not
- Find the original coordinates whose Manhattan distances are given
- Midpoint ellipse drawing algorithm
- Program to find the side of the Octagon inscribed within the square
- Find the side of the squares which are inclined diagonally and lined in a row
- Find coordinates of a prime number in a Prime Spiral
- Find the side of the squares which are lined in a row, and distance between the centers of first and last square is given