- Related Questions & Answers
- Point-to-Point Protocol (PPP)
- Difference between Point-to-Point and Multi-point Communication
- How to detect point on canvas after canvas rotation in HTML5
- C++ Floating Point Manipulation
- Fixed Point and Floating Point Number Representations
- Floating point comparison in C++
- Best Meeting Point in C++
- Decimal fixed point and floating point arithmetic in Python
- Generate Random Point in a Circle in C++
- Find intersection point of lines inside a section in C++
- Fixed Point in Python
- What are C++ Floating-Point Constants?
- What is the precision of floating point in C++?
- Program for Point of Intersection of Two Lines in C++
- Find an equal point in a string of brackets using C++.

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Rotation of a point X about origin is by an angle θ in anti-clockwise direction is done by −

** X by θ about origin anti-clRotateockwise: X*polar( 1.0,θ ).**

Here, the function polar for complex numbers is defined under <complex> header file and is used to find a complex number using phase angle and magnitude. polar(mag,angle) returns a complex number.

**Rotation of point X about a point Y**

To rotate a point about another point, we will use translation in which movement of all coordinates occur in a particular direction.

Translate X to Y, so Y becomes the new origin. This can be done by subtracting Y from all points. X now becomes X-Y.

Rotate (X-Y) about new origin using above formula: (X-Y)*polar( 1.0,θ )

Back-translation by adding Y to all points.

**Rotation of X about Y is : (X-Y)*polar( 1.0,θ ) + Y**

Below is the code to demonstrate rotation of point about another point

#include <iostream> #include <complex> using namespace std; typedef complex<double> point; #define x real() #define y imag() int main(){ // Rotate P about Q point X(5.0, 3.0); point Y(2.0, 4.0); // Angle of rotation is 90 degrees double theta = 3.14/2; point Xnew=(X-Y) * polar(1.0, theta) + Y; cout << "rotating X 90 degrees anti-clockwise about Y becomes:"; cout << "(" << Xnew.x << ", " << Xnew.y << ")" << endl; return 0; }

rotating X 90 degrees anti-clockwise about Y becomes:(3.00239, 6.9992)

Advertisements