Given three Cartesian coordinates, the task is to check if a right-angled triangle can be formed by the given coordinates. If it is possible to create a right-angled triangle, print Yes. Otherwise, print No.
Input: X1=0, Y1=5, X2=19, Y2=5, X3=0, Y3=0
Length of side connecting points (X1, Y1) and (X2, Y2) is 12.
Length of side connecting points (X2, Y2) and (X3, Y3) is 15.
Length of side connecting points (X1, Y1) and (X3, Y3) is 9.
122 + 92 = 152.
Therefore, a right-angled triangle can be made.
Input: X1=5, Y1=14, X2=6, Y2=13, X3=8, Y3=7
The idea is to use the Pythagoras Theorem to check if a right-angled triangle is possible or not. Calculate the length of the three sides of the triangle by joining the given coordinates. Let the sides be A, B, and C. The given triangle is right-angled if and only if A2 + B2 = C2. Print Yes if the condition holds true. Otherwise, print No.
Below is the implementation of the above approach:
Time Complexity: O(logN)
Auxiliary Space: O(1)
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.
- Check if a right-angled triangle can be formed by moving any one of the coordinates
- Program to find the Type of Triangle from the given Coordinates
- Find coordinates of the triangle given midpoint of each side
- Find the coordinates of a triangle whose Area = (S / 2)
- Maximum count of Equilateral Triangles that can be formed within given Equilateral Triangle
- Area of triangle formed by the axes of co-ordinates and a given straight line
- Count of Right-Angled Triangle formed from given N points whose base or perpendicular are parallel to X or Y axis
- Coordinates of rectangle with given points lie inside
- Find minimum area of rectangle with given set of coordinates
- Minimum length of square to contain at least half of the given Coordinates
- Find the original coordinates whose Manhattan distances are given
- Check if B can be formed by permuting the binary digits of A
- Check if N rectangles of equal area can be formed from (4 * N) integers
- Check whether a straight line can be formed using N co-ordinate points
- Sum of upper triangle and lower triangle
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle
- Program to print a Hollow Triangle inside a Triangle
- Find coordinates of a prime number in a Prime Spiral
- Find all possible coordinates of parallelogram
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.