I have a two dimensional data set that I would like to rotate 45 degrees such that a 45 degree line from the points (0,0 and 10,10) becomes the x-axis. For example, the x,y points (1,1)
, (2,2)
, and (3,3)
would be transformed to the points (0,1
), (0,2)
, and (0,3)
, respectively, such that they now lie on the x-axis. The points (1,0
), (2,0)
, and (3,0)
would be rotated to the points (1,1)
, (2,2)
, and (3,3)
. How can I calculate how to rotate a series of x,y point 45 degrees?

- 483
-
1Where does (2,1) go? – Ross Millikan May 06 '13 at 15:59
4 Answers
The transformation you describe by examples is not a rotation, in fact it does not preserve norms, it is the projection on the real axis. If instead you want a $45°$-counterclockwise rotation, apply the rotation matrix $$\left( \begin{array}{cc} \cos\theta&-\sin\theta\\ \sin\theta&\cos\theta \end{array} \right)$$
with $\theta=\frac{\pi}{4}$

- 8,422
-
-
1@RossMillikan yes, but there is a canonical iso $X\cong X\times 0$ – Federica Maggioni May 06 '13 at 15:04
There are a few ways to work this out, but my favorite is with complex numbers.
If we represent the point $(x,y)$ by the complex number $x+iy$, then we can rotate it 45 degrees clockwise simply by multiplying by the complex number $(1-i)/\sqrt{2}$ and then reading off their $x$ and $y$ coordinates.
$$(x+iy)(1-i)/\sqrt{2} = ((x+y) +i(y-x))/\sqrt{2} = \tfrac{x+y}{\sqrt{2}} + i\tfrac{y-x}{\sqrt{2}}.$$
Therefore, the rotated coordinates of $(x,y)$ are $\big(\tfrac{x+y}{\sqrt{2}},\tfrac{y-x}{\sqrt{2}}\big)$.
If your data consists of rational numbers, scaling by $\sqrt{2}$ may be undesirable. In that case, you can leave the $\sqrt{2}$ out of the denominator, but then note that the points have been both rotated and scaled.
Finally, if $(u,v)$ is a point in your rotated coordinates and you want to get back to the original data, you just multiply $u+iv$ by $(1+i)/\sqrt{2}$, the inverse of $(1-i)/\sqrt{2}$.

- 2,055
Here is some good background about this topic in wikipedia:

- 143
-
1Sorry, I somehow couldn't post this as a comment for another answer somehow... – ArminB May 06 '13 at 14:56
I don't think you have defined things properly, at least not with the usual mathematical definition of the $x$ axis going positive left and the $y$ axis going positive up. If you rotate the $x$ axis as you say, $(1,1)$ should go to $(1,0)$, not to $(0,1)$. Also note that your vectors change in length, which may or may not be a problem.
You seem to be trying to rotate the plane of lattice points by $45^\circ$. The problem is that many lattice points are no longer lattice points after the rotation. Your definition is not linear: given $(1,1) \to (1,0), (0,1) \to (1,1)$ we should have $(1,0) \to (0,-1)$ which is clearly not what you want.

- 374,822