When I use a rotation matrix to rotate points from a meshgrid, the points are no longer orthogonal. Using NumPy, how do I keep the gridlines perpendicular when rotating?
Here's the Python code that I'm using:
import numpy as np
import matplotlib.pyplot as plt
# Input
rot_degrees = 10
x = np.linspace(200, 600, 4)
y = np.linspace(200, 700, 5)
xv, yv = np.meshgrid(x, y)
pts = np.column_stack( (xv.flatten(), yv.flatten()) )
# Rotate points
radians = np.radians(rot_degrees)
rot_mat = np.array([[np.cos(radians),-np.sin(radians)],
[np.sin(radians), np.cos(radians)]])
einsum = np.einsum('ji, mni -> jmn', rot_mat, [pts])
pts_rotated = np.squeeze(einsum).T
# Output
plt.scatter(pts[:,0], pts[:,1], c='r')
plt.scatter(pts_rotated[:,0], pts_rotated[:,1], c='b')
plt.show()

