import matplotlib.pyplot as plt import matplotlib.animation as animation import math import numpy as np def binom(n,k): return math.factorial(n) / (math.factorial(k) * math.factorial(n - k)) def bernstein(n,t): return [binom(n,i) * t**i * (1-t)**(n-i) for i in range(n + 1)] def d(x1,x2,y1,y2): return ( (x2 - x1)**2 + (y2 - y1)**2 )**0.5 data_raw = [ [235.00,575.00], [233.17,556.00], [233.17,556.00], [233.17,556.00], [231.00,527.00], [231.00,527.00], [231.00,527.00], [230.00,511.00], [230.00,511.00], [229.94,475.20], [229.45,449.75], [236.60,414.00], [239.09,401.53], [242.12,389.00], [246.34,377.00], [248.41,371.15], [251.27,365.69], [258.00,364.52], [261.15,363.97], [268.57,365.36], [272.00,365.92], [272.00,365.92], [301.00,371.63], [301.00,371.63], [337.38,380.56], [372.25,392.25], [404.00,412.69], [416.22,420.56], [427.67,428.72], [438.00,439.00], [440.89,441.88], [448.02,450.26], [452.00,450.27], [454.77,450.27], [458.80,446.99], [461.00,445.37], [461.00,445.37], [477.00,434.33], [477.00,434.33], [477.00,434.33], [516.00,411.14], [516.00,411.14], [521.98,407.82], [534.70,400.58], [541.00,399.47], [550.35,397.82], [561.69,407.46], [570.00,411.74], [572.89,413.23], [576.70,415.53], [580.00,415.18], [582.08,414.97], [588.67,412.13], [591.00,411.20], [591.00,411.20], [611.00,403.42], [611.00,403.42], [625.33,398.06], [645.91,392.72], [661.00,389.80], [661.00,389.80], [703.00,384.00], [703.00,384.00], [703.00,384.00], [712.00,384.00], [712.00,384.00], [712.00,384.00], [724.00,383.00], [724.00,383.00], [751.41,382.96], [772.23,382.21], [799.00,374.57], [813.18,370.53], [828.67,363.19], [841.00,355.14], [848.30,350.37], [855.56,343.39], [863.00,340.00], [864.22,346.33], [860.96,350.07], [859.21,356.00], [857.26,362.60], [857.54,370.69], [860.35,377.00], [868.65,395.69], [891.13,403.38], [909.00,409.33], [933.40,417.47], [952.26,425.77], [975.00,437.78], [987.65,444.46], [1000.18,452.30], [1012.00,460.34], [1015.70,462.86], [1021.34,468.39], [1025.99,466.08], [1028.91,464.62], [1038.31,452.38], [1041.28,449.00], [1048.84,440.41], [1057.91,432.59], [1067.00,425.65], [1096.71,402.96], [1138.78,385.68], [1175.00,376.63], [1175.00,376.63], [1208.00,368.40], [1208.00,368.40], [1212.37,367.54], [1219.67,365.79], [1223.81,368.40], [1227.93,370.55], [1230.21,378.63], [1231.67,383.00], [1235.53,394.58], [1240.24,412.98], [1242.25,425.00], [1248.69,463.61], [1250.00,501.06], [1245.84,540.00], [1245.84,540.00], [1239.79,578.00], [1239.79,578.00], [1238.16,585.67], [1235.64,593.15], [1235.00,601.00], [1241.19,599.47], [1245.20,595.25], [1250.00,591.25], [1250.00,591.25], [1271.00,573.17], [1271.00,573.17], [1301.63,545.60], [1327.90,515.83], [1351.41,482.00], [1351.41,482.00], [1373.72,447.00], [1373.72,447.00], [1375.36,444.16], [1379.24,436.87], [1383.56,439.28], [1388.01,441.76], [1381.78,454.41], [1380.42,458.00], [1380.42,458.00], [1357.72,515.00], [1357.72,515.00], [1330.50,578.08], [1300.28,629.25], [1260.29,685.00], [1260.29,685.00], [1227.58,726.00], [1227.58,726.00], [1221.64,732.97], [1214.42,739.11], [1215.10,749.00], [1215.53,755.32], [1221.42,767.85], [1224.14,774.00], [1235.06,798.70], [1251.02,819.02], [1270.00,838.00], [1270.00,838.00], [1293.99,859.20], [1293.99,859.20], [1297.51,862.12], [1302.08,865.88], [1301.51,871.00], [1301.04,875.17], [1296.56,880.76], [1294.00,884.00], [1294.00,884.00], [1276.00,906.00], [1276.00,906.00], [1248.58,937.78], [1225.95,961.62], [1194.00,989.13], [1094.90,1074.47], [971.72,1130.24], [842.00,1147.72], [820.90,1150.56], [799.27,1152.97], [778.00,1153.00], [778.00,1153.00], [761.00,1154.00], [761.00,1154.00], [761.00,1154.00], [720.00,1153.00], [720.00,1153.00], [720.00,1153.00], [710.00,1152.09], [710.00,1152.09], [710.00,1152.09], [679.00,1149.72], [679.00,1149.72], [672.74,1148.96], [657.43,1146.64], [652.00,1147.17], [638.98,1148.45], [637.72,1151.92], [628.00,1155.91], [620.06,1159.17], [610.56,1160.65], [602.00,1159.83], [569.31,1156.71], [523.63,1143.05], [493.00,1130.80], [418.51,1101.00], [346.38,1052.53], [287.00,998.83], [253.81,968.81], [224.81,936.35], [197.42,901.00], [197.42,901.00], [179.34,876.00], [179.34,876.00], [176.97,872.48], [173.45,867.50], [174.35,863.00], [175.36,857.98], [182.19,853.60], [186.00,850.55], [192.40,845.43], [204.46,834.84], [209.91,829.00], [222.15,815.87], [232.76,802.18], [242.32,787.00], [242.32,787.00], [251.80,771.00], [251.80,771.00], [252.93,769.08], [254.85,765.20], [256.49,763.93], [258.42,762.45], [267.16,760.82], [270.00,760.21], [270.00,760.21], [299.00,754.00], [299.00,754.00], [247.20,699.70], [203.92,634.86], [168.31,569.00], [168.31,569.00], [146.26,524.00], [146.26,524.00], [146.26,524.00], [119.81,460.00], [119.81,460.00], [118.69,457.06], [115.36,447.70], [115.01,445.00], [114.71,442.72], [115.05,439.63], [118.07,439.63], [121.71,439.63], [124.95,446.26], [126.68,449.00], [126.68,449.00], [146.02,479.00], [146.02,479.00], [163.90,504.93], [184.76,528.76], [207.00,551.00], [213.14,557.14], [227.44,572.42], [235.00,575.00], ] for p in data_raw: p[0] = (p[0] - 750.0) / 1000.0 p[1] = (750.0 - p[1]) / 1000.0 x = [] y = [] for i in range(int((len(data_raw) - 1) / 3)): idx = i * 3 # dis = d(data_raw[idx+1][0], data_raw[idx+4][0], data_raw[idx+1][1], data_raw[idx+4][1]) b1 = [data_raw[idx+i][0] for i in range(1,5)] b2 = [data_raw[idx+i][1] for i in range(1,5)] for t in np.linspace(0,1,200): b = bernstein(len(b1) - 1, t) x.append(sum([b[i] * b1[i] for i in range(len(b1))])) y.append(sum([b[i] * b2[i] for i in range(len(b2))])) proc_x = [] proc_y = [] for (re, im) in zip(x,y): if len(proc_x) == 0 or d(re, proc_x[-1], im, proc_y[-1]) > 0.01: proc_x.append(re) proc_y.append(im) print(proc_x) print(proc_y) print(len(proc_x)) plt.scatter(proc_x,proc_y) # fig, ax = plt.subplots() # ani = animation.FuncAnimation(fig=fig, func=update, frames=1000, interval=1) plt.show()