数控技术插补算法
function myfun = pbpLinearintepol(x0, y0, x1, y1)
%x0,y0,x1,y1分别为起始点的横、纵坐标和终止点的横、纵坐标
%以下程序是将图形限制在area区域内,并且将网格间距调整为1个单位长度 area = max(max(x0,y0),max(x1,y1));
plot([0 0],[area area]);
grid on
set(gca,'XTick',[0:1:area])
set(gca,'YTick',[0:1:area])
%以下部分程序是画出需要加工的工件轮廓
line([x0 x1],[y0 y1]);
hold on;
grid on
%以下部分程序是模拟走刀路径
num = abs(x0-x1) + abs(y0-y1);
px = x0;
py = y0;
k0 = (y1-y0)/(x1-x0);
k = k0;
for i=1:num
lastX = px;
lastY = py; %lastX、lastY为走刀之前的位置坐标
if (k>k0)
py = py + 1; else px = px + 1; end line([lastX px],[lastY py],'Marker','.','Color','r','Linestyle','-','LineWidth',2); k = (y1-py)/(x1-px); pause(.5); %每走一步暂停0.5秒
endsSS