Steps:
Using some linear algebra:
import numpy as np
x = np.tile([1,2,3,4],8)
y = np.repeat([1,2,3,4,5,6,7,8],4)
A = np.vstack((x,y)) # just a quick example
# Rotation matrix as in e.g. https://en.wikipedia.org/wiki/Rotation_matrix
theta = -np.pi / 4
rotate = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
# Translation vector is the mean of all xs and ys.
translate = A.mean(axis=1, keepdims=True)
Apply transformations:
out = A - translate # Step 1
out = rotate @ out # Step 2
out = out + translate # Step 3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.