def _Bez3step(b, r, alpha):
    """Cubic bezier step r for interpolating at parameter alpha.

    Steps 1, 2, 3 are applied in succession to the 4 points
    representing a bezier segment, making a triangular arrangement
    of interpolating the previous step's output, so that after
    step 3 we have the point that is at parameter alpha of the segment.
    The left-half control points will be on the left side of the triangle
    and the right-half control points will be on the right side of the
    triangle.

    Args:
      b: list of tuples (coordinates), of length 5-r
      r: int - step number (0=orig points and cps)
      alpha: float - value in range 0..1 where want to divide at
    Returns:
      list of length 4-r, of vertex coordinates, giving linear interpolations
          at parameter alpha between successive pairs of points in b
    """

    ans = []
    n = len(b[0])  # dimension of coordinates
    beta = 1 - alpha
    for i in range(0, 4 - r):
        # find c, alpha of the way from b[i] to b[i+1]
        t = [0.0] * n
        for d in range(n):
            t[d] = b[i][d] * beta + b[i + 1][d] * alpha
        ans.append(tuple(t))
    return ans