1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| import numpy as np import matplotlib.pyplot as plt
fig = plt.figure() ax = fig.gca(projection='3d')
stPos = [117.9844565, 24.1658956, 1.597] edPos = [118.1167438, 24.5656241, 5211.73]
stepNumber = 30
resX = [] resY = [] resZ = []
def computeLnadDefendAirParabolaWithSteps( st, ed, resX, resY, resZ, stepNum ): resX.append(st[0]) resY.append(st[1]) resZ.append(st[2])
p = (ed[2] - st[2])**2 / (ed[0] - st[0]) step = (ed[0] - st[0]) / stepNum for stepCnt in range(stepNum)[1:]: curX = st[0] + stepCnt * step curZ = (p * (curX - st[0])) ** 0.5 + st[2] resZ.append(curZ) if st[1] != ed[1]: k = (st[0] - ed[0]) / (st[1] - ed[1]) b = st[0] - k * st[1] curY = (curX - b) / k resY.append(curY) resX.append(curX) else: resY.append(curY) resX.append(curX) resX.append(ed[0]) resY.append(ed[1]) resZ.append(ed[2])
for idx in range(stepNum + 1): print("%10.6f, %10.6f, %10.3f"%(resX[idx], resY[idx], resZ[idx]))
computeLnadDefendAirParabolaWithSteps(stPos, edPos, resX, resY, resZ, stepNumber)
ax.plot(resX, resY, resZ, label='fitted curve')
ax.legend()
plt.show()
|