Given two integers X and Y. The task is to find two vertices of an isosceles triangle ABC(right-angled at B) which has one vertex at a point B(0, 0). And there is a rectangle with opposite sides (0, 0) and (X, Y). All the points of this rectangle are located inside or on the border of the triangle. Print 4 integers x1, y1, x2, y2, where A(x1, y1) and B(x2, y2).
Input : X = 3, Y = 3
Output : 6 0 0 6
Input : X = -3, y = -2
Output : -5 0 0 -5
Let Val = |x| + |y|. Then the first point is (Val * sign(x), 0) and the second point is (0, Val * sign(y)).
Let’s see how it works for x > 0 and y > 0. Other cases can be proved in a similar way.
We need to show, that (x, y) belongs to our triangle(including its borders). In fact (x, y) belongs to segment, connecting (x + y, 0) with (0, x + y). The line through (x + y, 0) and (0, x + y) is Y = – X + x + y. Using coordinates (x, y) in this equation proves our answer.
Below is the implementation of the above approach:
6 0 0 6
Time Complexity : O(1)
- Find the area of quadrilateral when diagonal and the perpendiculars to it from opposite vertices are given
- Divide an isosceles triangle in two parts with ratio of areas as n:m
- Find the altitude and area of an isosceles triangle
- Find the remaining vertices of a square from two given vertices
- Maximum number of 2x2 squares that can be fit inside a right isosceles triangle
- Maximum number of squares that can fit in a right angle isosceles triangle
- Program To Check whether a Triangle is Equilateral, Isosceles or Scalene
- Find the cordinates of the fourth vertex of a rectangle with given 3 vertices
- Find if there exists multiple ways to draw line through (x, y) to cut rectangle in equal halfs
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Ratio of area of a rectangle with the rectangle inscribed in it
- Largest subset of rectangles such that no rectangle fit in any other rectangle
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Number of Isosceles triangles in a binary tree
- Area of circle inscribed in a Isosceles Trapezoid
- Minimum adjacent swaps to move maximum and minimum to corners
- Time until distance gets equal to X between two objects moving in opposite direction
- Find the number of distinct pairs of vertices which have a distance of exactly k in a tree
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.