In [ ]:
%matplotlib inline
In [ ]:
import math
import numpy as np
import matplotlib.pyplot as plt
In [ ]:
X = np.random.randint(10, size=[5,2])
X
In [ ]:
plt.plot(X[:,0], X[:,1]);
In [ ]:
angle = math.radians(180)
R = np.array([[math.cos(angle), -math.sin(angle)],
[math.sin(angle), math.cos(angle)]])
In [ ]:
Xr = np.dot(R, X.T).T
In [ ]:
Xr
In [ ]:
plt.plot(X[:,0], X[:,1])
plt.plot(Xr[:,0], Xr[:,1]);
https://github.com/cta-observatory/ctapipe/blob/master/ctapipe/image/geometry_converter.py#L44
The correction on the pixel position r can be described by a rotation R around one angle and a sheer S along a certain axis:
$$r' = S \cdot R \cdot r$$$$ \begin{pmatrix} x' \\ y' \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ -1/\tan & 1 \end{pmatrix} \cdot \begin{pmatrix} \cos & -\sin \\ \sin & \cos \end{pmatrix} \cdot \begin{pmatrix} x \\ y \end{pmatrix} $$$$ \begin{pmatrix} x' \\ y' \end{pmatrix} = \begin{pmatrix} \cos & -\sin \\ \sin-\cos/\tan & \sin/\tan+\cos \end{pmatrix} \cdot \begin{pmatrix} x \\ y \end{pmatrix} $$To revert the rotation, we need to find matrices $S'$ and $R'$ with $S' \cdot S = 1$ and $R' \cdot R = 1$ so that $r = R' \cdot S' \cdot S \cdot R \cdot r = R' \cdot S' \cdot r'$:
$$ \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} \cos & \sin \\ -\sin & \cos \end{pmatrix} \cdot \begin{pmatrix} 1 & 0 \\ 1/\tan & 1 \end{pmatrix} \cdot \begin{pmatrix} x' \\ y' \end{pmatrix} $$$$ \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} \cos+\sin/\tan & \sin \\ \cos/\tan-\sin & \cos \end{pmatrix} \cdot \begin{pmatrix} x' \\ y' \end{pmatrix} $$Source: