<p>Trick is, to move the entire object so that the point about which you want to rotate is at the center. Then rotate and after that counter move it so that the point is were it was.</p>

<p>In fact this is not so much of a trick, as such, nearly all graphics engines work this way. It is just abstracted away in many cases. Most often you will see it done in matrix notation like this:</p>

<p>$$ T^{-1} R T $$</p>

<p>Where T is to transformation from world to pivot and R is the rotation matrix. Since it can be easily packaged this way you end up with a function called rotate about the pivot point. This is usually the reason why drawing API's allow for a transformation matrix.</p>

<p><a href="https://i.sstatic.net/kIH24.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kIH24.png" alt="Rotate about a pivot"></a></p>

<p><strong>Image 1</strong>: Rotate about a pivot point, <a href="http://pastebin.com/L2XpvfeG" rel="nofollow noreferrer">image source</a> available for investigation. Sub images in RTL reading order: Original, inverse transform, inverse and rotate, inverse rotate and move back.</p>

CC BY-SA 3.0
2016-02-16T21:18:00.447Z
2016-02-17T09:22:41.763Z
2016-02-17T09:22:41.763Z
joojaa
<p>I am a bit unsure if my calculations are correct, but on my scribbling paper it seemed to work out.</p>

<p>P1 and P2 lie on a circle around M.</p>

<p>This allows us to measure the distance of the two points by just taking the radius (which is half the line length) of the circle and constructing two rectangular triangles. The accepted answer <a href="https://math.stackexchange.com/questions/134606/distance-between-any-two-points-on-a-unit-circle">here</a> provides a sketch for this construction.
So given your rotation angle is $\gamma$ and the line is $l$ long it follows:</p>

<p>$x = 2* sin(\frac{\gamma}{2}) * \frac{l}{2}$</p>

<p>The lines M to P1 and M to P2 form a isosceles triangle with the third side being the line segment between P1 and P2.</p>

<p>The angle at point M is known to be the rotation angle $\gamma$ so the remaining two angles in this triangle are given by</p>

<p>$\alpha = \frac{180 - \gamma}{2}$ </p>

<p>And therefore the angle between the wrong line and the needed translation vector is just </p>

<p>$\beta = \alpha + \gamma$</p>

<p>So now you rotate a unit vector that starts along the wrong line.</p>

<p>You rotate it around P1 for $\beta$ and scale it to length x.</p>

<p>This yields the translation vector from P1 to P2. The rotation of the line should indeed be correct.</p>

CC BY-SA 3.0
2016-02-16T23:27:35.177Z
Though in general it is far easier to just use the construction joojaa explained in his answer.
Dragonseel
CC BY-SA 3.0
2016-02-16T23:26:31.237Z
2016-02-16T23:26:31.237Z
2017-04-13T12:19:38.027Z
Dragonseel
<p>I have to use a propriertary graphics-engine for drawing a line. I can rotate the whole drawing by its origin point (P1). What I want, is to rotate it around its center point(M). So basically that it looks like the green line (L_correct instead of L_wrong).</p>
<p>I think, it should be possible to correct it, by moving it from P1 to P2. But I cannot figure out what formula could be used, to determine the distance. It must probably involve the angle, with and height... Can anyone give me a hint?</p>
<p><img src="https://i.sstatic.net/75MpZ.jpg" alt="1" /></p>

<transformations><line-drawing><mathematics>
Rotate line around center
Tofferino
# Rotate line around center

(Asked by: username_0 on 2016-02-16)

I have to use a propriertary graphics-engine for drawing a line. I can rotate the whole drawing by its origin point (P1). What I want, is to rotate it around its center point(M). So basically that it looks like the green line (L\_correct instead of L\_wrong).

I think, it should be possible to correct it, by moving it from P1 to P2. But I cannot figure out what formula could be used, to determine the distance. It must probably involve the angle, with and height... Can anyone give me a hint?

![1](https://i.sstatic.net/75MpZ.jpg)

**Tags:** transformations, line-drawing, mathematics


---

## 2 answers

### Answer by username_1 on 2016-02-16. Score: 6

Trick is, to move the entire object so that the point about which you want to rotate is at the center. Then rotate and after that counter move it so that the point is were it was.

In fact this is not so much of a trick, as such, nearly all graphics engines work this way. It is just abstracted away in many cases. Most often you will see it done in matrix notation like this:

$$ T^{-1} R T $$

Where T is to transformation from world to pivot and R is the rotation matrix. Since it can be easily packaged this way you end up with a function called rotate about the pivot point. This is usually the reason why drawing API's allow for a transformation matrix.

[![Rotate about a pivot](https://i.sstatic.net/kIH24.png)](https://i.sstatic.net/kIH24.png)

**Image 1**: Rotate about a pivot point, [image source](http://pastebin.com/L2XpvfeG) available for investigation. Sub images in RTL reading order: Original, inverse transform, inverse and rotate, inverse rotate and move back.


---

### Answer by username_2 on 2016-02-16. Score: 1

I am a bit unsure if my calculations are correct, but on my scribbling paper it seemed to work out.

P1 and P2 lie on a circle around M.

This allows us to measure the distance of the two points by just taking the radius (which is half the line length) of the circle and constructing two rectangular triangles. The accepted answer [here](https://math.stackexchange.com/questions/134606/distance-between-any-two-points-on-a-unit-circle) provides a sketch for this construction.
So given your rotation angle is $\gamma$ and the line is $l$ long it follows:

$x = 2\* sin(\frac{\gamma}{2}) \* \frac{l}{2}$

The lines M to P1 and M to P2 form a isosceles triangle with the third side being the line segment between P1 and P2.

The angle at point M is known to be the rotation angle $\gamma$ so the remaining two angles in this triangle are given by

$\alpha = \frac{180 - \gamma}{2}$

And therefore the angle between the wrong line and the needed translation vector is just

$\beta = \alpha + \gamma$

So now you rotate a unit vector that starts along the wrong line.

You rotate it around P1 for $\beta$ and scale it to length x.

This yields the translation vector from P1 to P2. The rotation of the line should indeed be correct.

> **Comments:**
> **username_2**: Though in general it is far easier to just use the construction username_1 explained in his answer.  

---

