19
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ Where does (2,1) go? $\endgroup$ May 6, 2013 at 15:59

4 Answers 4

18
$\begingroup$

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}$

$\endgroup$
2
  • $\begingroup$ It is not a projection, as the output is still two dimensional. $\endgroup$ May 6, 2013 at 15:00
  • 1
    $\begingroup$ @RossMillikan yes, but there is a canonical iso $X\cong X\times 0$ $\endgroup$ May 6, 2013 at 15:04
10
$\begingroup$

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}$.

$\endgroup$
1
  • $\begingroup$ You are trying to preserve norms, which OP seems not to want. $\endgroup$ May 6, 2013 at 14:59
2
$\begingroup$

Here is some good background about this topic in wikipedia:

Rotation Matrix

$\endgroup$
1
  • 1
    $\begingroup$ Sorry, I somehow couldn't post this as a comment for another answer somehow... $\endgroup$
    – ArminB
    May 6, 2013 at 14:56
0
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .