File indexing completed on 2026-04-09 07:48:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 """
0022
0023 http://www.hannahfry.co.uk/blog/2011/11/16/bezier-curves
0024
0025 """
0026
0027 import scipy as sp
0028 import pylab as plt
0029
0030
0031 plt.ion()
0032 plt.close()
0033
0034
0035
0036
0037
0038 origins = [
0039 [1,0],
0040 [-0.5, sp.sqrt(3)/2],
0041 [-0.5,-sp.sqrt(3)/2]
0042 ]
0043
0044 destinations = [[0,0],[0,0],[0,0]]
0045
0046
0047 blue_angle = sp.pi/6
0048 red_angle = sp.pi/4
0049
0050
0051 blue_len = 1./5
0052 red_len = 1./3
0053
0054
0055
0056
0057 fig = plt.figure()
0058 ax = fig.add_subplot(111)
0059 ax.hold(True)
0060
0061
0062 t = sp.linspace(0,1,100)
0063
0064
0065 for i in xrange(len(origins)):
0066 POx,POy = origins[i][0], origins[i][1]
0067 P3x,P3y = destinations[i][0], destinations[i][1]
0068
0069
0070 ax.plot(POx,POy, 'ob')
0071 ax.plot(P3x,P3y, 'or')
0072 ax.plot((POx,P3x),(POy,P3y), 'g')
0073
0074
0075 r = ((POx-P3x)**2 + (POy-P3y)**2)**0.5
0076 theta = sp.arctan2((POy-P3y),(POx-P3x))
0077
0078
0079 aO =theta + blue_angle+ sp.pi
0080 aD = theta - red_angle
0081
0082
0083 P1x, P1y = POx+ blue_len*r*sp.cos(aO), POy + blue_len*r*sp.sin(aO)
0084 P2x, P2y = P3x+ red_len*r*sp.cos(aD), P3y + red_len*r*sp.sin(aD)
0085
0086
0087 ax.plot((P3x,P2x),(P3y,P2y), 'r')
0088 ax.plot((POx,P1x),(POy,P1y), 'b')
0089 ax.plot(P1x, P1y, 'ob')
0090 ax.plot(P2x, P2y, 'or')
0091
0092
0093 Bx = (1-t)**3*POx + 3*(1-t)**2*t*P1x + 3*(1-t)*t**2*P2x + t**3*P3x
0094 By = (1-t)**3*POy + 3*(1-t)**2*t*P1y + 3*(1-t)*t**2*P2y + t**3*P3y
0095
0096
0097 ax.plot(Bx, By, 'k')
0098 pass
0099
0100
0101
0102 plt.show()
0103