import copy


def transform_point(p, transform):
    """ The function to transform a 3D point using a transformation matrix

        Args:
            p (list): the point to transform; [X, Y, Z, ...]
            transform (numpy array): 4x4 transformation matrix 

        Returns:
            (list): the transformed point; [X, Y, Z, ...]

    """

    a = copy.deepcopy(p)
    b = transform

    p2 = copy.deepcopy(p)
    p2[0] = a[0] * b[0, 0] + a[1] * b[0, 1] + a[2] * b[0, 2] + b[0, 3]
    p2[1] = a[0] * b[1, 0] + a[1] * b[1, 1] + a[2] * b[1, 2] + b[1, 3]
    p2[2] = a[0] * b[2, 0] + a[1] * b[2, 1] + a[2] * b[2, 2] + b[2, 3]
    
    return p2