zhuangjie007 发表于 2005-7-23 14:12:59

bzzz 发表于 2005-7-24 23:21:07

Re:求教:如何利用离散点进行插值,生成闭合曲线?

通过极坐标来插值就不会重复
随便选的点,

plot(x,y,'r*');
hold on
x0=mean(x);y0=mean(y);         % the center point

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
r=sqrt((x-x0).^2+(y-y0).^2);    % the radius
theta=acos((x-x0)./r);            %the angle
index=(y-y0)<0;
theta(index)=2*pi-theta(index)   %计算各个点的角度
%using cart2pol is almost the same
%=cart2pol(x-x0,y-y0);
%theta(theta<0)=theta(theta<0)+2*pi;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

=sort(theta)
r1=r(i1)
theta=;
r1=;

theta1=min(theta):2*pi/100:max(theta);

%r2=spline(theta,,theta1);             %插值
r2=interp1(theta,,theta1,'pchip');   

%which one works better? it depends. for the case with fewer points, such as 10 points, i will choose spline, otherwise i will choose pchip

ttt=;
rrr=;
=sort(ttt);
rrr=rrr(i2);

xx=rrr.*cos(ttt)+x0;                  
yy=rrr.*sin(ttt)+y0;
plot(xx,yy)

[ 本帖最后由 bzzz 于 2006-8-9 23:59 编辑 ]

lyrock 发表于 2005-7-25 06:25:38

Re:求教:如何利用离散点进行插值,生成闭合曲线?

in my opinion, bzzz solved the problem well.

with the value provided, the codes work well.

the GUI was developed for this problem, the spline part used the method bzz presented. in some case, it dosen't work well. The figure I pasted is a good one. there should be some better solutions.

bzzz 发表于 2005-7-25 09:48:53

Re:求教:如何利用离散点进行插值,生成闭合曲线?

there are some bugs as I was so sleepy to give a full check~~~
anyhow the idea, I guess, is basically right
and I reconsidered the problem and rewrote some statements
it will work better now

i guess one problem i should point out is the interpolation method, the spline will lead to asmoother curve but does not work well if there are many points, while pchip(cubic) will work under most circumstances, but the curve is not very smooth sometimes.
So it just depends~~

and I am still not sure if it can be applied to the case with many points, such as 200 or even more~~~

if there are so many points, i do not think it will be easy to form a closed curve even for human mind^_^

the rewritten function is listed above.
I have tested the case with 50, it seems ok~~~

bzzz 发表于 2005-7-25 09:55:53

Re:求教:如何利用离散点进行插值,生成闭合曲线?

the above case is 50 points with pchip(x=rand(50,1),y=rand(50,1))

20 points with pchip:(x=rand(20,1),y=rand(20,1))

bzzz 发表于 2005-7-25 09:57:34

Re:求教:如何利用离散点进行插值,生成闭合曲线?

20 points with spline:(x=rand(20,1),y=rand(20,1))

bzzz 发表于 2005-7-25 09:59:04

Re:求教:如何利用离散点进行插值,生成闭合曲线?

10 points with pchip:(x=rand(10,1),y=rand(10,1))

bzzz 发表于 2005-7-25 10:03:12

Re:求教:如何利用离散点进行插值,生成闭合曲线?

10 points with spline:(x=rand(10,1),y=rand(10,1))

bainhome 发表于 2005-7-28 03:07:07

Re:求教:如何利用离散点进行插值,生成闭合曲线?

昨天翻了一下样条工具箱的命令,看了两个命令,我也凑个热闹,在bzzz和lyrock两位大高手面前献个丑^_^:
function points_contact(m)
%对点做顺次首尾相连.
if m<=1|m/round(m)~=1
    disp('we can not make a line by one point or none point!')
return
end
x=rand(1,m);y=rand(1,m);
points=;
x0=mean(x);y0=mean(y); % the center point
r=sqrt((x-x0).^2+(y-y0).^2); % the radius
theta=acos((x-x0)./r); %the angle

index=(y-y0)<0;
theta(index)=2*pi-theta(index); %计算各个点的角度
=sort(theta);
r1=r(i1);
xi=x0+r1.*cos(theta);
yi=y0+r1.*sin(theta);
points=[;];
curve=cscvn(points);
fnplt(curve);
hold on;
plot(points(1,:),points(2,:),'o')
hold off
=================================================================================
另外还有一个GUI命令,"getcurve",用于屏幕去点做样条连接,比较简单就不再多说了
根据bzzz的思路修改了一下,今天想了很久,始终没有想到比他这种排序更好的方法.^_^
==============================================================================
5 points:

bainhome 发表于 2005-7-28 03:09:17

Re:求教:如何利用离散点进行插值,生成闭合曲线?

10 points:

bainhome 发表于 2005-7-28 03:14:21

Re:求教:如何利用离散点进行插值,生成闭合曲线?

20 points:

bainhome 发表于 2005-7-28 03:18:13

Re:求教:如何利用离散点进行插值,生成闭合曲线?

50 points:

lyrock 发表于 2005-7-28 08:32:51

Re:求教:如何利用离散点进行插值,生成闭合曲线?

I would like to say bzzz's algorithm works very well, which can be shown in the attached GUI file.

lyrock 发表于 2005-7-28 08:52:45

Re:求教:如何利用离散点进行插值,生成闭合曲线?

have a look at the difference results between two methods (spline, interp1):

bzzz 发表于 2005-7-28 09:52:33

Re:求教:如何利用离散点进行插值,生成闭合曲线?

bainhome wrote:
10 points:

把点先按照对于中点的角度排一下序的话效果会好些

lyrock 发表于 2005-7-28 10:52:51

Re:求教:如何利用离散点进行插值,生成闭合曲线?

bainhome, "fnplt" & "cscvn" are functions in the spline toolbox? If so, it's a pity that my boss didn't buy this toolbox.

But it's really wonderful to learn from each other.

bainhome 发表于 2005-7-28 11:29:24

Re:求教:如何利用离散点进行插值,生成闭合曲线?

lyrock wrote:
bainhome, "fnplt" & "cscvn" are functions in the spline toolbox? If so, it's a pity that my boss didn't buy this toolbox.

But it's really wonderful to learn from each other.

Yes,"fnplt"&"cscvn" both belong to the spline toolbox,and yesterday I find command "cscvn" first too.In sp toobox,the other command such as csaps(Cubic smoothing spline),csape,ppmak...also make me feel really exciting!But another thing is:your programm is wonderful too,because that definitely will give me a pretty hard time----push me to spend lot of time to figure that out!that time supposed to be the "hanging with my friend and drinking beer" time^_^

damingsun 发表于 2005-7-28 11:30:23

Re:求教:如何利用离散点进行插值,生成闭合曲线?

请仔细讲讲下面几句,偶是菜鸟,看不懂,特别是第一句:
index=(y-y0)<0;
theta(index)=2*pi-theta(index) %计算各个点的角度
=sort(theta)
r1=r(i1)
theta=;
r1=;
==============================================================================
index=(y-y0)<0返回的是所有y与均值y0之差小于零的逻辑索引为真则是1,为假则是0,第二句是对所有满足y-y0小于零的列对应的theta做处理,处理的原因猜测是前面定义theta时正负号的标定使用的是"x-x0",而同时"y-y0"还有正负两种情况,用2pi-theta(index)将其放到其共轭的位置上,保证四个象限上向量方向的协调(感觉是这个意思...^_^).后面的应该就比较简单了,倒数第二行是样条拟合最后一步——对曲线进行封闭,即初始theta旋转2π角度重合回去.
==============================================================================
acos算出来的值域是第一第二象限,第三第四象限的点的角度也会落到第一第二象限,需要把这些点的角度给复原

[ 本帖最后由 bainhome 于 2006-10-15 11:26 编辑 ]

bainhome 发表于 2005-7-28 20:50:16

Re:求教:如何利用离散点进行插值,生成闭合曲线?

补充100个点的拟合:
ps:还是忍不住赞一个bzzz和lyrock,厉害!

[ 本帖最后由 bainhome 于 2008-12-29 22:16 编辑 ]

baijie 发表于 2005-9-14 10:06:26

Re:求教:如何利用离散点进行插值,生成闭合曲线?

小弟有个问题,以上的都是二维的,那如何实现三维的呢?
页: [1] 2 3
查看完整版本: 如何利用离散点进行插值,生成闭合曲线?(离散点/闭合曲线/拟合/插值)[有代码]