Source code for pymead.utils.transformations
import numpy as np
[docs]
def translate_matrix(mat: np.ndarray, dx, dy):
if not mat.shape[1] == 2:
raise ValueError("Input matrix must be N x 2")
mat[:, 0] += dx
mat[:, 1] += dy
return mat
[docs]
def scale_matrix(mat: np.ndarray, scale_factor):
if not mat.shape[1] == 2:
raise ValueError("Input matrix must be N x 2")
mat *= scale_factor
return mat
[docs]
def rotate_matrix(mat: np.ndarray, theta):
if not mat.shape[1] == 2:
raise ValueError("Input matrix must be N x 2")
xy = mat.T
rotation_mat = np.array([[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]])
mat = (rotation_mat @ xy).T
return mat