二维平移矩阵是一种将二维空间中的点进行平移的矩阵,其计算公式为:

其中,分别是平移的x和y方向的距离。 然后将二维点与平移矩阵相乘,得到平移后的点。

标准代码如下

def translate_object(points, tx, ty):
    translation_matrix = np.array([
        [1, 0, tx],
        [0, 1, ty],
        [0, 0, 1]
    ])
    
    homogeneous_points = np.hstack([np.array(points), np.ones((len(points), 1))])
    
    translated_points = np.dot(homogeneous_points, translation_matrix.T)
    
    return translated_points[:, :2].tolist()