逐点比较直线插补法(python)

 

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

 

  • 5
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值