point-by-point relative method
用逐点比较插补法插补第一象限的直线OA,O点为原点,A点坐标为 (8,6),请完成以下任务:
(1)列出插补计算过程;
(2)画出插补轨迹图。
import numpy as np
from matplotlib import pyplot as plt
#确定第一象限直线
line = [[0, 8], [0, 6]]
plt.title("point-by-point relative method")
plt.xlabel("X")
plt.ylabel("Y")
plt.plot(line[0],line[1])
plt.scatter(line[0], line[1], color='Red')
plt.show()
#计算出总共节拍
Nxy =abs((line[0][1]-line[0][0]))+abs((line[1][1]-line[1][0]))
print(Nxy)
Output:14
#F作为判别函数,S和E代表偏差与坐标值计算时候的xy轴
F = 0
S = [0,0]
E = [0,0]
print(end= "Step\tDiscriminant function\t")
print(end= "Feed function\tDeviation and coordinate value calculation\t")
print(end= "End point\n")
for i in range(0, Nxy):
print(end = "{}\t".format(i+1))
#判段判别函数,分别得出进给方向,偏差与坐标值计算
if F >= 0:
print(end = "F >= 0\t\t\t+X\t\t")
F = F - line[1][1]
print(end = "F = {}\t\t\t\t\t\t".format(F))
S[1] = S[1] + 1
plt.plot(S,E)
plt.scatter(S,E, color='b')
S[0] = S[1]
print(end = "{}\n".format(Nxy - i))
continue
if F < 0:
print(end = "F < 0\t\t\t+Y\t\t")
F = F + line[0][1]
print(end = "F = {}\t\t\t\t\t\t".format(F))
E[1] = E[1] + 1
plt.plot(S,E)
plt.scatter(S,E, color='b')
E[0] = E[1]
print(end = "{}\n".format(Nxy - i))
continue
#进行图像打印
plt.plot(line[0],line[1])
plt.scatter(line[0], line[1], color='Red')
plt.grid(color = 'gray')
plt.show()
Output:
Step Discriminant function Feed function Deviation and coordinate value calculation End point 1 F >= 0 +X F = -6 14 2 F < 0 +Y F = 2 13 3 F >= 0 +X F = -4 12 4 F < 0 +Y F = 4 11 5 F >= 0 +X F = -2 10 6 F < 0 +Y F = 6 9 7 F >= 0 +X F = 0 8 8 F >= 0 +X F = -6 7 9 F < 0 +Y F = 2 6 10 F >= 0 +X F = -4 5 11 F < 0 +Y F = 4 4 12 F >= 0 +X F = -2 3 13 F < 0 +Y F = 6 2 14 F >= 0 +X F = 0 1 |