我在unutbu的different post中找到了我的大部分答案(第二个答案)。在
这是我对他的基本功能的修改,还有一些额外的功能来解决我上面的问题。我将不得不为直线段编写一个类似的函数,但这显然要容易得多,它们之间可以拼凑出曲线和直线段的任何组合,以实现上述目标。在def pascal_row(n):
# This is over my designer's brain, but unutbu says:
# "This returns the nth row of Pascal's Triangle"
result = [1]
x, numerator = 1, n
for denominator in range(1, n//2+1):
# print(numerator,denominator,x)
x *= numerator
x /= denominator
result.append(x)
numerator -= 1
if n&1 == 0:
# n is even
result.extend(reversed(result[:-1]))
else:
result.extend(reversed(result))
return result
def bezier_interpolation(origin, destination, control_o, control_d=None):
points = [origin, control_o, control_d, destination] if control_d else [origin, control_o, de