|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
有人会改这个程序不~!<BR>>> function [xp,yp,t,d]=calculate_distance(b,X,Y)<BR>% Calculate distance between bezier curve and a point<BR>% [xp,yp,t,d]=calculate_distance(b,X,Y)<BR>if ~strcmpi(class(b),'bezier')<BR> error('Expecting a bezier object');<BR>end<BR>[x0,ax,bx,cx,y0,ay,by,cy]=deal(b.x0,b.ax,b.bx,b.cx,b.y0,b.ay,b.by,b.cy);<BR>jj=[ay^2+ax^2,2*(by*ay+bx*ax),2*cy*ay+by^2+2*cx*ax+bx^2,...<BR> 2*(-X+x0)*ax+2*cx*bx+2*(-Y+y0)*ay+2*cy*by,...<BR> 2*(-Y+y0)*by+cy^2+2*(-X+x0)*bx+cx^2,...<BR> 2*(-Y*cy+y0*cy-X*cx+x0*cx),(-Y+y0)^2+(-X+x0)^2];<BR>dj=polyder(jj);<BR>r=roots(dj);<BR>i=find(imag(r)==0 & r>=0 & r<=1);<BR>pt=[0,1];<BR>if ~isempty(i)<BR> pt=[pt,r(i)'];<BR>end<BR>v=polyval(jj,pt);<BR>[m,i]=min(v);<BR>t=pt(i);<BR>xp=polyval([ax bx cx x0],t);<BR>yp=polyval([ay by cy y0],t);<BR>d=norm([xp yp]-[X Y]);<BR><BR>??? function [xp,yp,t,d]=calculate_distance(b,X,Y)<BR> |<BR>Error: Function definitions are not permitted at the prompt or in scripts.<BR>后边两行提示的错误~<BR> |
|