We have already discussed the rotation of a point P about the origin in the Set 1 and Set 2. The rotation of point P about origin with an angle θ in the anti-clockwise direction is given as under:

Rotation of P about origin: P * polar(1.0, θ)

**Rotation of P about point Q**

Now, we have to rotate the point P not about origin but about a general point Q. This can be easily understood by the method of translation which is quite a common technique adopted in geometric analysis.

**What is Translation?**

In Euclidean geometry, translation is a geometric transformation that moves every point of a figure or a space by the same amount in a given direction.

**How to Perform Translation?**

Translation can also be interpreted as the addition of a constant vector to every point, or as shifting the origin of the coordinate system.

After the translation, required computations are made and the translation is nullified by subtracting the constant vector to every point or shifting the origin back.

So, for rotating P about Q, we shift the origin at Q i.e. we subtract the vector equivalent of Q from every point of the coordinate plane. Now the new point P – Q has to be rotated about the origin and then translation has to be nullified.

These steps can be described as under:

**Translation (Shifting origin at Q):**Subtract Q from all points. Thus, P becomes P – Q**Rotation of (P – Q) about origin:**(P – Q) * polar(1.0, θ)**Restoring back the Origin:**Add Q to all the points.

Thus,

Rotation of P about Q : (P – Q) * polar(1.0, θ) + Q

`// CPP example to illustrate the rotation ` `// of a point about another point ` `#include <iostream> ` `#include <complex> ` ` ` `using` `namespace` `std; ` ` ` `typedef` `complex<` `double` `> point; ` `#define x real() ` `#define y imag() ` ` ` `// Constant PI for providing angles in radians ` `#define PI 3.1415926535897932384626 ` ` ` `// Function used to display X and Y coordinates of a point ` `void` `displayPoint(point P) ` `{ ` ` ` `cout << ` `"("` `<< P.x << ` `", "` `<< P.y << ` `")"` `<< endl; ` `} ` ` ` `//Function for Rotation of P about Q by angle theta ` `point rotate(point P, point Q, ` `double` `theta) ` `{ ` ` ` `return` `(P-Q) * polar(1.0, theta) + Q; ` `} ` ` ` `int` `main() ` `{ ` ` ` `// Rotate P about Q ` ` ` `point P(4.0, 3.0); ` ` ` `point Q(2.0, 2.0); ` ` ` ` ` `// Angle of rotation = 90 degrees ` ` ` `double` `theta = PI/2; ` ` ` ` ` `point P_rotated = rotate(P, Q, theta); ` ` ` `cout << ` `"The point P on rotating 90 degrees anti-clockwise about Q becomes:"` `; ` ` ` `cout << ` `"P_rotated"` `; displayPoint(P_rotated); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

Output:

The point P on rotating 90 degrees anti-clockwise about Q becomes: P_rotated(1, 4)

This article is contributed by **Aanya Jindal**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.

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.

## Recommended Posts:

- Reflection of a point at 180 degree rotation of another point
- Find determinant of matrix generated by array rotation
- Minimum number of flips with rotation to make binary string alternating
- Longest subsequence of a number having same left and right rotation
- Check if a number is a power of another number
- lseek() in C/C++ to read the alternate nth byte and write it in another file
- Sorting an array according to another array using pair in STL
- Check if a number is divisible by all prime divisors of another number
- Number of visible boxes after putting one inside another
- C++ program to append content of one text file to another
- Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)
- Check if a string can be formed from another string using given constraints
- GCD of a number raised to some power and another number
- How to convert a class to another class type in C++?
- Sum of elements in an array whose difference with the mean of another array is less than k
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Find the minimum number of rectangles left after inserting one into another
- Check if a circle lies inside another circle or not
- Angle subtended by the chord when the angle subtended by another chord of same length is given
- Distance of chord from center when distance between center and another equal length chord is given