C++

Rotating a point about another point 2D

27 September 2026 · 5 min read

Rotating a point about another point 2D

In the expansive realm of mathematics and computer graphics, understanding how to manipulate geometric shapes is fundamental. One such crucial operation is rotating a point about another point (2D). While rotating a point around the origin (0,0) is straightforward, situations often arise where the rotation needs to occur around an arbitrary pivot point. This concept is vital in everything from game development and animation to robotics and engineering design. Mastering this transformation allows for precise control over object orientation and movement within a two-dimensional space, opening up a world of possibilities for complex simulations and visual effects. This guide will demystify the process, breaking down the mathematical principles and providing clear, actionable steps.

Understanding the Fundamentals of 2D Rotation

At its core, 2D rotation involves moving a point or an object around a fixed central point, known as the pivot or center of rotation, by a specified angle. When this pivot point is the origin (0,0), the mathematical formulas are relatively simple. However, real-world applications rarely afford such convenience. Imagine rotating a door around its hinge, or a character’s arm around their elbow in a game; these are instances where the pivot is not the origin of the coordinate system.

To accurately perform a rotation about an arbitrary pivot, we employ a clever trick involving translation. This method leverages our existing knowledge of rotation around the origin. The basic idea is to temporarily shift the entire coordinate system so that the desired pivot point becomes the new “origin.” After the rotation is performed around this temporary origin, we then shift the coordinate system back to its original position. This three-step process—translate, rotate, translate back—is a cornerstone of geometric transformations in 2D coordinate geometry, ensuring precision and flexibility in handling complex movements.

This technique is not just a mathematical curiosity; it’s a fundamental principle of Euclidean geometry widely applied in various computational fields. It allows developers and engineers to define complex movements relative to specific object parts or spatial anchors, rather than being confined to the global coordinate system’s origin. Understanding this foundational step is paramount before delving into the specific formulas that govern the rotation itself.

The Mathematical Framework: Translation and Rotation

To rotate a point P(x, y) about an arbitrary pivot point C(cx, cy) by an angle θ (theta), the process involves a sequence of transformations. This method effectively transforms the problem into one of rotating about the origin, which has well-defined mathematical formulas. The angle θ is typically measured in radians, and positive values usually indicate a counter-clockwise rotation, while negative values indicate clockwise rotation.

The core of this transformation relies on the standard 2D rotation matrix applied after a translation. First, the point P is translated such that the pivot C moves to the origin. This means subtracting the pivot’s coordinates from the point’s coordinates: P'(x - cx, y - cy). Once translated, the standard rotation formulas for rotation about the origin are applied to P' to get P''. Finally, P'' is translated back by adding the pivot’s coordinates: P_rotated(x'' + cx, y'' + cy). This sequence ensures the rotation is precisely centered around the specified pivot.

To rotate a point (x, y) about a pivot point (cx, cy) by an angle θ, apply the following formulas: First, translate the point: x_translated = x - cx and y_translated = y - cy. Next, rotate these translated coordinates: x_rotated = x_translated cos(θ) - y_translated sin(θ) and y_rotated = x_translated sin(θ) + y_translated cos(θ). Finally, translate back: x_final = x_rotated + cx and y_final = y_rotated + cy. These calculations provide the new coordinates of the point after rotation.

Key components in this transformation include:

  • Translation Vector: The vector (-cx, -cy) used to move the pivot to the origin.
  • Rotation Matrix Components: The cosine and sine of the rotation angle θ. Make sure your programming environment uses radians for trigonometric functions.
  • Inverse Translation Vector: The vector (cx, cy) used to move the rotated point back to the original coordinate system.

Step-by-Step Guide to Rotating a Point

Let’s walk through the process of rotating a point Question & Answer : </b><br><p>I'm trying to make a card game where the cards fan out. Right now to display it Im using the Allegro API which has a function:</p> <pre>al_draw_rotated_bitmap(OBJECT_TO_ROTATE,CENTER_X,CENTER_Y,X ,Y,DEGREES_TO_ROTATE_IN_RADIANS); </pre> <p>so with this I can make my fan effect easily. The problem is then knowing which card is under the mouse. To do this I thought of doing a polygon collision test. I'm just not sure how to rotate the 4 points on the card to make up the polygon. I basically need to do the same operation as Allegro.</p> <p>for example, the 4 points of the card are:</p> <pre>card.x card.y card.x + card.width card.y + card.height </pre> <p>I would need a function like:</p> <pre>POINT rotate_point(float cx,float cy,float angle,POINT p) { } </pre> <p>Thanks</p><br><p>First subtract the pivot point (cx,cy), then rotate it (counter clock-wise), then add the point again.</p> <pre>POINT rotate_point(float cx, float cy, float angleInRads, POINT p) { float s = sin(angleInRads); float c = cos(angleInRads); // translate point back to origin: p.x -= cx; p.y -= cy; // rotate point float xnew = p.x * c - p.y * s; float ynew = p.x * s + p.y * c; // translate point back: p.x = xnew + cx; p.y = ynew + cy; return p; } </pre>">