在 3d 中旋转平面 array/list

Rotate plane in 3d array/list

我有一个 (x,y,z) 坐标的二维列表。现在我想围绕穿过中点的垂直线将所有内容旋转 a 度。所有点都应保留相同的 y 坐标。两个平原都是垂直的。有this post, but I cant understand a word and I have looked into the wikipedia article。这是一张照片:

对于任何对未来感兴趣的人,我使用这个函数来获取边缘垂直线上每个点的新点坐标,并用画线算法将它们连接起来。

def thirdPoint(p1, p2, a):
    x1, y, z1 = p1
    x2, _, z2 = p2
    
    aP1P2 = math.atan2(z2-z1, x2-x1)  # In radians, not degrees
    aP1P3 = aP1P2 - math.radians(a)

    x3 = x1 + rDis * math.cos(aP1P3)
    z3 = z1 + rDis * math.sin(aP1P3)
    
    return (x3, y1, z3)

绕y轴的旋转可以表示为the following matrix:

    ┌                     ┐
    │ cos(α)   0   sin(α) │
R = │    0     1     0    │
    │ -sin(α)  0   cos(α) │
    └                     ┘

其中α表示旋转角度。

因此,我们可以围绕中点旋转,方法是先平移取反的中点向量,应用 R,然后平移回来:

def rotate_points(points, alpha):
    # compute the mid point
    midpoint = np.mean(points, 0)

    # let's ignore the y coordinate
    midpoint[1] = 0.0

    # translate all points so that midpoint is at [0, y, 0]
    translated = points - midpoint

    # for use in the following step
    cos = np.cos(alpha)
    sin = np.sin(alpha)

    # apply the rotation matrix
    rotated = [np.array([v[0] * cos + v[2] * sin, v[1], -v[0] * sin + v[2] * cos])
               for v in translated]

    # translate back
    untranslated = rotated + midpoint

    # ...and done
    return untranslated