5

What might be going wrong with my rotation of set of points as result look distorted? I have a set of points (X,Y). I calculate the mean (= "center of gravity") of them and subtract it from each point, then I rotate 10 degrees clockwise these and finally add back the mean. But the result seems somehow distorted if one looks attached pictures of original points as red squares and rotated points as blue x's. It is more obvious in the second picture where only rotated points are plotted with circles and center of rotation is marked by red. I try to highlight what I mean by distortion by marking it yellow color.

I don't see what goes wrong with my code. Is this normal? Can it be avoided?

# needed libraries
import numpy as np
import math 
import matplotlib.pyplot as plt

# generating the original points 
E_min = 379557
E_max = 379590
N_min = 6673711
N_max = 6673746
X = []
Y = []

for east in range(E_min, E_max,5):
  for north in range(N_min, N_max,5):
    X.append(east)
    Y.append(north)

# angle of rotation 10 degrees
alfa = -10*math.pi/180

# calculating "center of gravity" = rotation point 
X_mean = np.mean(X)
Y_mean = np.mean(Y)

# subtracting mean from original coordinates and saving result to X_new and Y_new 
X_new = []
Y_new = []
for i in range(len(X)):
  X_new.append(X[i] - X_mean)
  Y_new.append(Y[i] - Y_mean)

# rotating coordinates from which mean has been subtracted
X_apu = []   #temporary help variable
Y_apu = []   #temporary help variable
    
for i in range(len(X)):
  X_apu.append(math.cos(alfa)*X_new[i]-math.sin(alfa)*Y_new[i])
  Y_apu.append(math.sin(alfa)*X_new[i]+math.cos(alfa)*Y_new[i])
    
# adding mean back to rotated coordinates
X_new = X_apu + X_mean
Y_new = Y_apu + Y_mean

# plotting data
plt.scatter(X_new, Y_new, c='b', marker='x', label='1')
plt.scatter(X, Y, c='r', marker='s', label='-1')**

Original points with red squares and rotated with blue x's Rotated points with center of rotation marked by red

1 Answer 1

6

There is nothing wrong with the rotation. It is a side effect from visualization. If you look at the picture captured from QGIS, you will see that the dots do not only get bigger and smaller, but also dance (look distorted).

enter image description here

Also, dots in your first picture are not distorted.

enter image description here

2
  • Thanx for outstanding answer! Out of interest, how did you get in Python that red grid connecting blue points? It really nails that there is no distortion.
    – Estiivan
    Commented Oct 22, 2021 at 10:33
  • Drown manually. Commented Oct 22, 2021 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.