geometry
2D transformation
rotation
Cartesian coordinates
mathematics

Rotating a point about another point 2D

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Rotating one point around another point in 2D is a standard coordinate-transformation problem. The solution is always the same: translate the point so the pivot sits at the origin, apply the rotation, and translate back. Once you understand those three steps, the formula becomes easy to remember and implement.

The Three-Step Geometry

Suppose you want to rotate point (x, y) around pivot (cx, cy) by an angle measured in radians.

The process is:

  1. subtract the pivot so the pivot becomes the temporary origin
  2. apply the 2D rotation formula
  3. add the pivot back

If the translated coordinates are:

  • 'tx = x - cx'
  • 'ty = y - cy'

then the rotated translated coordinates are:

  • 'rx = tx * cos(angle) - ty * sin(angle)'
  • 'ry = tx * sin(angle) + ty * cos(angle)'

and the final answer is:

  • 'final_x = rx + cx'
  • 'final_y = ry + cy'

That is the whole transformation.

A Python Implementation

python
1import math
2
3
4def rotate_point(x, y, cx, cy, angle_radians):
5    tx = x - cx
6    ty = y - cy
7
8    rx = tx * math.cos(angle_radians) - ty * math.sin(angle_radians)
9    ry = tx * math.sin(angle_radians) + ty * math.cos(angle_radians)
10
11    return rx + cx, ry + cy
12
13
14x, y = rotate_point(1.0, 0.0, 0.0, 0.0, math.pi / 2)
15print(round(x, 6), round(y, 6))

Output:

text
0.0 1.0

This rotates (1, 0) around the origin by 90 degrees counterclockwise.

A C# Implementation

csharp
1using System;
2
3public static class Geometry
4{
5    public static (double X, double Y) RotatePoint(
6        double x,
7        double y,
8        double centerX,
9        double centerY,
10        double angleRadians)
11    {
12        double tx = x - centerX;
13        double ty = y - centerY;
14
15        double rx = tx * Math.Cos(angleRadians) - ty * Math.Sin(angleRadians);
16        double ry = tx * Math.Sin(angleRadians) + ty * Math.Cos(angleRadians);
17
18        return (rx + centerX, ry + centerY);
19    }
20
21    public static void Main()
22    {
23        var result = RotatePoint(3.0, 2.0, 1.0, 1.0, Math.PI / 2);
24        Console.WriteLine($"{result.X:F3}, {result.Y:F3}");
25    }
26}

This follows the same math directly and is easy to reuse in graphics, UI, or game code.

Degrees Versus Radians

Most programming language math libraries expect the angle in radians, not degrees. If your input is in degrees, convert it first.

python
angle_radians = math.radians(90)

Forgetting this is one of the fastest ways to get a result that “looks almost random” even when the formula is correct.

Clockwise Versus Counterclockwise

The standard formula above rotates counterclockwise for positive angles in the usual Cartesian coordinate system. If your screen coordinates have the y-axis growing downward, the visual result may appear flipped compared with textbook geometry.

That does not mean the formula is wrong. It means your coordinate system is different from the mathematical one. In screen-space systems, you often need to negate the angle or adjust the interpretation.

Common Pitfalls

  • Rotating around the origin when the real pivot is somewhere else.
  • Forgetting to translate the point to and from the pivot.
  • Passing degrees into sin and cos when the math library expects radians.
  • Expecting screen coordinates to behave exactly like Cartesian coordinates.
  • Rounding too early and accumulating visible error over many repeated transformations.

Summary

  • Rotate around another point by translating to the pivot, rotating, and translating back.
  • The core formula uses cos and sin on the translated coordinates.
  • Most code libraries expect the angle in radians.
  • Positive angles are usually counterclockwise in Cartesian coordinates.
  • If the result looks mirrored on screen, check whether your y-axis direction differs from standard math coordinates.

Course illustration
Course illustration

All Rights Reserved.