« 上一篇: 断开的坐标轴 下一篇: 螺旋片helix »
萝卜 @ 2008-04-24 07:47

使用说明:以往数据点多的时候,一般是按x-轴每隔一点数目的点取出一点。这样会因
曲线在竖直方向陡变而显得不均匀。本函数实现这个按曲线长度均匀取点,这样看着更
美观些,具体使用见说明和示例。

function [xn,yn]=samplep(x,y,N,sD,sA);
% sample point with an equal step length of curve
% N is total number of sample point.
% sD is a scale from the quantity levels of x-Data and y-Data
% sA is a scale from the length of x-axis and y-axes at the axes
% For user, sD can easier be calsulated by the data.
% sA needs that try it again and again. sA is from the
% defference of the scale at x-axis and y-axis.
% Author's email: zjliu2001@163.com
% Example:
% x=linspace(0,6,200);
% y=exp(-x.^2)/1000;
% [xn,yn]=samplep(x,y,20,1e-3,0.1);
% subplot(121);
% plot(x(1:10:end),y(1:10:end),'k-o');
% xlabel('sample at x-axis');
% subplot(122);
% plot(xn,yn,'ko');hold on;
% plot(x,y,'k');
% xlabel('sample at curve');

y=y/sD/sA;
L=0;
D=[x(1:end-1)-x(2:end)].^2+[y(1:end-1)-y(2:end)].^2;
L=sum(sqrt(D));
dL=L/[N-1];
kt=1;
Lf=0;
for k=1:length(D);
    Lf(k+1)=Lf(k)+sqrt(D(k));
end
xn(1)=x(1);
yn(1)=y(1);
Nx=1;
for k=2:length(x);
    if Lf(k)>=Nx*dL;
        if Lf(k)==Nx*dL;
            xn=[xn,x(k)];
            yn=[yn,y(k)];
            Nx=Nx+1;           
        else
            Dd1=Lf(k)-Nx*dL;
            Dd2=sqrt(D(k-1))-Dd1;
            s=Dd1/Dd2;
            xn=[xn,(x(k)+s*x(k-1))/(1+s)];
            yn=[yn,(y(k)+s*y(k-1))/(1+s)];
            Nx=Nx+1;
        end
    end
end
yn=yn*sD*sA;


示例输出结果



曾经的这一天...

相关文章:

最新评论


当当

2008-07-22 13:11 匿名 219.225.*.*

这个需要取点足够多,即取得的线长近似程度要高


评论 / 个人网页 / 扔小纸条
* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 


 

分类小组论坛
杂谈 , 娱乐、八卦 , 文学、艺术 , 体育 , 旅游、同城 , 象牙塔 , 情感 , 时尚、生活 , 星座 , 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定