
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Find if it's possible to rotate the page by an angle or not in C++
In this problem, we are given coordinates of three points that lie on a page. Our task is to find if it’s possible to rotate the page by an angle or not.
The rotation of the page is made in such a way that the new position of ‘x’ is the old position of ‘y’, the new position of ‘y’ is the old position of ‘z’. And print “Yes” or “No” based on the rotation.
Let’s take an example to understand the problem,
Input: x = (0, 1), y = (1, 0), z = (0, -1)
Output: Yes
Explanation:
We can rotate the page by 90o.
Solution Approach:
We can rotate the page by some angle if some conditions are possible.
This can be done if the distance between x and y is the same as the distance between y and z. Also, if all the points lie on the same line rotation cannot be possible.
Program to illustrate the working of our solution,
Example
#include<bits/stdc++.h> using namespace std; int possibleOrNot(int coordinates[3][2]){ long long dis1 = pow(coordinates[1][0] - coordinates[0][0], 2) + pow(coordinates[1][1] - coordinates[0][1], 2); long long dis2 = pow(coordinates[2][0] - coordinates[1][0], 2) + pow(coordinates[2][1] - coordinates[1][1], 2); if(dis1 != dis2) return 0; else if (coordinates[1][0] == ((coordinates[0][0] + coordinates[2][0]) / 2.0) && coordinates[1][1] == ((coordinates[0][1] + coordinates[2][1]) / 2.0)) return 0; else return 1; } int main() { int coordinates[3][2] = {{0 , 1}, {1 , 0}, {0, -1} } ; if ( possibleOrNot(coordinates)) cout<<"The rotation of page is possible"; else cout<<"The rotation of page is not possible"; return 0; }
Output
The rotation of page is possible
- Related Articles
- PyTorch – How to rotate an image by an angle?
- How to rotate an Image in ImageView by an angle on Android?
- How to Rotate image in image view by an angle in Android?
- If an angle is acute, how can we know if it is an interior angle or an exterior angle?
- How to rotate an image in imageview by an angle on Android using Kotlin?
- Why it is not possible to capture an image formed by convex mirror?
- What would happen if earth did not rotate or revolve?
- Is it possible to have an HTML canvas element in the background of my page?
- How to rotate an image in imageview by an angle on iOS App using Swift?
- If an angle differ from its complement by $10^o$, find the angle.
- Is it possible to make an insert or an update in the same MySQL query?
- Rotate the element based on an angle using CSS
- The Vertical Angle Of An Isosceles Triangle Is 100°. Find It's Base Angles.
- Check if it is possible to create a polygon with a given angle in Python
- If an expression has no variables, does that mean it's not an equation?

Advertisements