Given three coordinates of a triangle (x1, y1), (x2, y2), (x3, y3). The task is to find out if the triangle can be transformed to a right-angled triangle by moving only one point exactly by the distance 1.
If it is possible to make the triangle right-angled, then print “POSSIBLE”, else print “NOT POSSIBLE”.
If the triangle is already right-angled, it should also be reported.
x1 = -1, y1 = 0
x2 = 2, y2 = 0
x3 = 0, y3 = 1
First co-ordinate (-1, 0) can be changed to (0, 0) and make it right-angled.
x1 = 36, y1 = 1
x2 = -17, y2 = -54
x3 = -19, y3 = 55
As it is known that for a triangle of sides a, b and c, the triangle will be right-angled if the following equation holds true : a2 + b2 = c2
So for every co-ordinates of the triangle, find out all the sides and for the 3 possible permutations of them check if it is already right-angle triangle and report it.
If the above condition doesn’t hold true, then the following operations need to be done-
We need to change all the co-ordinates by 1 one by one and check that is it a valid combination for a right-angled triangle.
Look that there can be 4 possible combinations to change every co-ordinates by 1. They are (-1, 0), (0, 1), (1, 0), (0, -1). So run a loop and apply those changes one by one for every co-ordinates and check that the formula a2 + b2 = c2 is true or not.
If it’s true then it is possible to transform the triangle to a right-angled triangle, otherwise not.
Below is the implementation of the above code:
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 the given 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
- Check if it is possible to return to the starting position after moving in the given directions
- Check if any square (with one colored cell) can be divided into two equal parts
- Largest even number that can be formed by any number of swaps
- Program to find simple moving average
- Maximum possible intersection by moving centers of line segments
- Time until distance gets equal to X between two objects moving in opposite direction
- 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
- 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
- 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
- Find coordinates of a prime number in a Prime Spiral
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.