Xs = input('input the start of X\nXs = ');
Ys = input('input the start of Y\nYs = ');
%结束点的坐标
Xe = input('input the end of X\nXe = ');
Ye = input('input the end of Y\nYe = ');
%%步长
h = input('input step\nh = ');
%%判断是顺时针还是逆时针,1代表逆时针
bIsCW = input('input bIsCW\nbIsCW = ');
%%Mount是总共需要走的步数
Mount = (abs(Xe-Xs)+abs(Ye-Ys))/h;
%记录插补的次数
Count = 0;
%lDevVal的值是用来判断是在圆内还是在圆外,等于0是在圆上
lDevVal=0;
%%xCurVal,yCurVal是用来控制插补过程中的点
xCurVal=Xs;
yCurVal=Ys;
%%标示所在的象限
nDir = 1;
%%%%设定起始点所在的象限%%%%
if(Xs>=0&Ys>0) nDir = 1;
end
if(Xs<0&Ys>=0) nDir = 2;
end
if(Xs<=0&Ys<0) nDir = 3;
end
if(Xs>0&Ys<=0) nDir = 4;
end
x = 0;
y = 0;
%%%% 插补过程%%%%
while (Count
if(xCurVal>=0&yCurVal>0) nDir = 1;%第一象限
end
if(xCurVal<0&yCurVal>=0) nDir = 2;%第二象限
end
if(xCurVal<=0&yCurVal<0) nDir = 3;%第三象限
end
if(xCurVal>0&yCurVal<=0) nDir = 4;%第四象限
end
%lDevVal的值是用来判断是在圆内还是在圆外,在圆内的就是小于0,在圆外的话就是大于0
%%等于0就是在圆上
lDevVal=xCurVal*xCurVal+yCurVal*yCurVal-Xs*Xs-Ys*Ys;
if(bIsCW==1)%逆时针方向
if(nDir==1) %在第一象限的处理措施
if (lDevVal>=0) %现在的点在圆外
xCurVal = xCurVal-h; %x轴左移h
else %点在圆内
yCurVal = yCurVal+h; %y轴上移h
end
x = [x xCurVal];%记录坐标
y = [y yCurVal];
Count = Count+1;%点的个数加1
hold on
end
if(nDir==2)%在第二象限
if (lDevVal>=0) %现在的点在圆外
xCurVal = xCurVal+h; %x轴右移h
else
yCurVal = yCurVal+h; %y轴上移h
end
x = [x xCurVal];
y = [y yCurVal];
Count = Count+1;
hold on
end
if(nDir==3)
if (lDevVal>=0)
xCurVal = xCurVal+h; %x轴右移h
else
yCurVal = yCurVal-h; %y轴下移h
end
x = [x xCurVal];
y = [y yCurVal];
Count = Count+1;
hold on
end
if(nDir==4)
if (lDevVal>=0)
xCurVal = xCurVal-h; %x轴左移h
else
yCurVal = yCurVal-h; %y轴下移h
end
x = [x xCurVal];
y = [y yCurVal];
Count = Count+1;
hold on
end
else%%顺时针方向,读懂了上面的,下面的就是小Ks了吧,呵呵
if(nDir==1)
if (lDevVal>=0)
xCurVal = xCurVal-h;
else
yCurVal = yCurVal+h;
end
x = [x xCurVal];
y = [y yCurVal];
Count = Count+1;
hold on
end
if(nDir==2)
if (lDevVal>=0)
xCurVal = xCurVal-h;
else
yCurVal = yCurVal-h;
end
x = [x xCurVal];
y = [y yCurVal];
Count = Count+1;
hold on
end
if(nDir==3)
if (lDevVal>=0)
xCurVal = xCurVal+h;
else
yCurVal = yCurVal-h;
end
x = [x xCurVal];
y = [y yCurVal];
Count = Count+1;
hold on
end
if(nDir==4)
if (lDevVal>=0)
xCurVal = xCurVal+h;
else
yCurVal = yCurVal+h;
end
x = [x xCurVal];
y = [y yCurVal];
Count = Count+1;
hold on
end
end
end
plot(x,y)%%画出插补的过程