Find if it’s possible to rotate the page by an angle or not.

You are given three points a, b, c on a page. Find if it’s possible to rotate the page around the point by an angle, such that the new position of ‘a’ is same as the old position of ‘b’, and the new position of ‘b’ is same as the old position of ‘c’. If such angle exists print “Yes”, else “No”.


Input : a1 = 0, a2 = 1, b1 = 1, b2 =  1,
        c1 = 1, c2 = 0
Output : Yes
Explanation : Rotate the page by 90 degree.

Input : a1 = 1, a2 = 1, b1 = 0, b2 = 0,
        c1 = 1000, c2 = 1000
Output : No

Rotation of page by some angle is only possible if the distance between points ‘a’ and ‘b’ is equal to distance between points ‘b’ and ‘c’. But if the points are on same line, there is no rotation at point ‘b’. The problem has no solution when ‘a’, ‘b’, ‘c’ are in the same line or dis(a, b) != dis(b, c)

// C++ program to find if its possible 
// to rotate page or not
using namespace std;

// function to find if it's possible
// to rotate page or not
void possibleOrNot(long long a1, long long a2,
                   long long b1, long long b2, 
                   long long c1, long long c2){
    // Calulating distance b/w points
    long long dis1 = pow(b1 - a1, 2) + 
                      pow(b2 - a2, 2);
    long long dis2 = pow(c1 - b1, 2) + 
                      pow(c2 - b2, 2);

    // If distance is not equal
    if(dis1 != dis2)
        cout << "No";
    // If the points are in same line
    else if (b1 == ((a1 + c1) / 2.0) && b2 == 
                          ((a2 + c2) / 2.0))
        cout << "No";
        cout << "Yes";

// Driver Code
int main()
    // Points a, b, and c
    long long a1 = 1, a2 = 0, b1 = 2,
             b2 = 0, c1 = 3, c2 = 0;
    possibleOrNot(a1, a2, b1, b2, c1, c2);
    return 0;



This article is contributed by Sachin Bisht. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to 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.

GATE CS Corner    Company Wise Coding Practice

Please write to us at to report any issue with the above content.

Recommended Posts:

0 Average Difficulty : 0/5.0
No votes yet.