Given hypotenuse and area of a right angle triangle, get its base and height and if any triangle with given hypotenuse and area is not possible, print not possible.
Input : hypotenuse = 5, area = 6 Output : base = 3, height = 4 Input : hypotenuse = 5, area = 7 Output : No triangle possible with above specification.
We can use a property of right angle triangle for solving this problem, which can be stated as follows,
A right angle triangle with fixed hypotenuse attains maximum area, when it is isosceles i.e. both height and base becomes equal so if hypotenuse if H, then by pythagorean theorem, Base2 + Height2 = H2 For maximum area both base and height should be equal, b2 + b2 = H2 b = sqrt(H2/2) Above is the length of base at which triangle attains maximum area, given area must be less than this maximum area, otherwise no such triangle will possible.
Now if given area is less than this maximum area, we can do a binary search for length of base, as increasing base will increases area, it is a monotonically increasing function where binary search can be applied easily.
In below code, a method is written for getting area of right angle triangle, recall that for right angle triangle area is ½*base*height and height can be calculated from base and hypotenuse using pythagorean theorem.
Below is the implementation of above approach:
One more solution is discussed in below post.
Check if right angles possible from given area and hypotenuse
This article is contributed by Utkarsh Trivedi. 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 the hypotenuse of a right angled triangle with given two sides
- Number of possible pairs of Hypotenuse and Area to form right angled triangle
- Count right angled triangles in a matrix having two of its sides parallel to sides of the matrix
- Check if right triangle possible from given area and hypotenuse
- Check whether right angled triangle is valid or not for large sides
- Find the height of a right-angled triangle whose area is X times its base
- Area of Circumcircle of a Right Angled Triangle
- Area of Incircle of a Right Angled Triangle
- Find the dimensions of Right angled triangle
- Check if a right-angled triangle can be formed by the given coordinates
- Count of Right-Angled Triangle formed from given N points whose base or perpendicular are parallel to X or Y axis
- Check if a right-angled triangle can be formed by moving any one of the coordinates
- Find area of triangle if two vectors of two adjacent sides are given
- Find other two sides and angles of a right angle triangle
- Find other two sides of a right angle triangle
- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Dividing the rectangle into n right-angled triangles
- Find the type of triangle from the given sides