I've a set of (n) geometrical shapes that are defined by a fixed number (p) of 2D points. Those shapes are independent but for efficiency reason, I stored time in a single numpy array. Scaling or translating those shapes are easy, but I would like to rotate them and I'm not sure how to do that. I suspect np.tensordot
is my friend but I can't find the way to properly use it.
n = 100 # Number of shape
p = 4 # Points per shape
P = np.random.uniform(0, 1, (n, p, 2))
# Scaling
S = 0.5*np.ones(n)
P *= S
# Translating
T = np.random.uniform(0, 1, (n, 1, 2))
P += T
# Rotating
A = np.random.uniform(0, 2*np.pi, n)
cosA, sinA = np.cos(A), np.sin(A)
R = np.empty((n,2,2))
R[:,0,0] = cosA
R[:,1,0] = sinA
R[:,0,1] = -sinA
R[:,1,1] = cosA
np.tensordot(P, R, axes=???)