资源简介
DDA直线插补matalb实现,带左移规格化处理,插补效果更好,更加便于速度规划。

代码片段和文件信息
%DDA数字积分法插补:
%(xsys)起点坐标
%(xeye)起点坐标
%buffBitWidth 寄存器位宽
%base 基准:1全加载 2半加载 其他 普通
function DDA_Line2()%(xsys xeye buffBitWidth base)
%clc
close all
clear all
global x y speed;
%global x y m speed steplengh base zuo;
%初始化参数------------------------------
speed=0.01; %speed of running插补速度.
xs =0; % x start point x起始点
ys =0; % y start point y起始点
xe =1005; % x end point x终点
ye =1003; % y end point y终点
buffBitWidth=16;%寄存器位数
zuo=1;%左移偏置开关 1 开 0 关
base=1;%是否全加载1全加载 2半加载 其他 普通
steplengh=1;%步长设置
%理论曲线绘制-----------------------------
grid on;
plot([xsxe][ysye]‘r-‘);hold on;
title(‘DDA直线插补图像‘);
xlabel(‘x‘);
ylabel(‘y‘);
% main part--------------------------------------------
if (xe-xs)>0
xdir = 1;
else
xdir = -1;
end
if (ye-ys)>0
ydir = 1;
else
ydir = -1;
end
jx0 = abs(xe-xs);
jy0 = abs(ye-ys);
if(zuo)%进行左移规格化操作
while(jx0&&jy0<=(0.5*2^buffBitWidth))
jx0=2*jx0;
jy0=2*jy0;
end
end
switch base
case 1
jx=2^buffBitWidth;
jy=2^buffBitWidth;
case 2
jx=0.5*2^buffBitWidth;
jy=0.5*2^buffBitWidth;
otherwise
jx=0;
jy=0;
end
x=xs;
y=ys;
xplus = abs(xe-xs);
yplus = abs(ye-ys);
output(xsys); % move to start point.
while(xplus>0 || yplus>0)
jx=jx0+jx;
jy=jy0+jy;
if jx > 2^buffBitWidth&&jy>2^buffBitWidth
xstep = redo(xplus steplengh);
ystep = redo(yplus steplengh);
output(xdir*xstep ydir*ystep);
x = x+xdir*xstep;
y = y+ydir*ystep;
xplus=xplus-xstep;
yplus=yplus-ystep;
jx=jx-2^buffBitWidth;
jy=jy-2^buffBitWidth;
end
if jx>2^buffBitWidth&&jy<2^buffBitWidth
xstep = redo(xplus steplengh);
output(xdir*xstep 0);
x = x+xdir*xstep;
xplus=xplus-xstep;
jx=jx-2^buffBitWidth;
end
if jx<2^buffBitWidth&&jy>2^buffBitWidth
ystep = redo(yplus steplengh);
output(0 ydir*ystep);
y = y+ydir*ystep;
yplus=yplus-ystep;
jy=jy-2^buffBitWidth;
end
end
end
function output(dxdy)
global x y speed;
xi=x;
yi=y;
xj=x+dx;
yj=y+dy;
%if(dx)
% dx=dx
% disp(‘output‘)
%end
plot([xixj][yiyj]‘b-‘);hold on;
pause(speed);
end
function step = redo(data n)
if(data>0)
step=n;
else
step=0;
end
end
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2925 2018-11-06 20:45 DDA_Line2.m
----------- --------- ---------- ----- ----
2925 1
- 上一篇:实现对占空比的随时可调代码
- 下一篇:RSA非对称加密
相关资源
- 编程实现二维DCT变换
- 图像二值化
- 用FFT对信号进行频谱分析
- Tone-Reservation
- QGA 量子遗传算法
- 差分形式的阻滞增长模型
- 遗传算法的M文件
- 图形学集成程序dda、中点算法、多边
- 简单二阶互联系统的非线性动力学分
- 手写数字识别-模板匹配法
- Stock_Watson_动态因子分析模型
- 果蝇优化算法优化支持向量回归程序
- 自己做的一个简单GUI扑克纸牌识别-
- multi output SVR
- AR过程的线性建模过程与各种功率谱估
- PCNN TOOLBOX
- plstoolbox.zip
- 中国国家基础地理信息系统GIS数据
- 粒子群微电网优化调度
- 矩阵分析-经典教材-中文版-Roger.A.Ho
- 压缩感知TwIST
- 基于最小错误率的贝叶斯手写数字分
- 最全系统辨识源代码,包括多种最小
- 导弹制导实验
- 画跟踪精确度图的程序.zip
- 重力场大地水准面及重力异常阶次误
- prtools5.2.3工具包
- 脉冲耦合神经网络工具箱PCNN-toolbox
- SVM算法-回归拟合程序.zip
- DDA插补源码
评论
共有 条评论