200分求B样条曲线拟合源码! ( 积分: 100 )

  • 主题发起人 主题发起人 xiaose109
  • 开始时间 开始时间
X

xiaose109

Unregistered / Unconfirmed
GUEST, unregistred user!
我的问题是有许多点的坐标(x,y),坐标值为实数,想把这些点连成光滑曲线,经过查资料知道我想做的就是B样条曲线的拟合,由于时间比较紧迫,所以也来不及自己去做,想问哪位兄弟有源码,帮帮兄弟,不甚感激,送上200分!
邮箱:xiaose109@163.com
 
我的问题是有许多点的坐标(x,y),坐标值为实数,想把这些点连成光滑曲线,经过查资料知道我想做的就是B样条曲线的拟合,由于时间比较紧迫,所以也来不及自己去做,想问哪位兄弟有源码,帮帮兄弟,不甚感激,送上200分!
邮箱:xiaose109@163.com
 
不好意思,点错了,本来是200分的,但给点到100上了!
 
bezier吗?
 
不是的,bezier不通过控制点,而B样条是通过控制点的曲线
 
哦,想起来了,有点搅了。
按照它的算法自己写就是了啊。
 
GDI+ 去Ms网站下载
 
¹¦ÄÜ:ÓÃ×îС¶þ³Ë·¨Äâ½øÐÐy=a+bxÖ±ÏßÄâºÏ
×÷Õß:ÕÅÊÀƽ
ʱ¼ä:2005Äê6ÔÂ6ÈÕ

}

type
TLeastSquarFit = class
private
z: array[1..365*2, 1..itWidth + 1] of double;
PXi: array[1..365*2] of double;
s: array[1..365*2, 1..itWidth + 1] of double;
ResultY: array[1..itWidth + 1] of double;
ForecastDate: tdatetime;
N: integer;
a: double;
b: double;
protected
ii: integer;
sgm_pxi: double;
iss: double;
ips: double;
xip: double;
sip: double;
ds: double;
ms: double;
ys: double;
function LoadData(): boolean; //×°ÔؾØÕó
function Get_ii(): integer;
procedure Set_pxi();
function get_sgm_pxi: double;
function get_iss: double;
function get_ips: double;
function get_a: double;
function get_b: double;
procedure Set_s;
procedure Set_s_of_N_add_1;
procedure calc_result();

procedure save();

public
constructor Create(LForecastDate: tdatetime;
LhistoryN: integer); //¹¹Ô캯
// ForecastDate:string Ô¤²âδÀ´ÈÕÆÚ
// historyN:integer£ºÔ¤²â¸ù¾Ý ForecastDate Ç° historyNÌìµÄÊý¾Ý

function Execute(): boolean;
end;
var LeastSquarFit: TLeastSquarFit;
implementation

uses Pdm;

constructor TLeastSquarFit.Create(LForecastDate: tdatetime; LhistoryN: integer); //¹¹Ô캯Êý
begin
N := LhistoryN;
ForecastDate := LForecastDate;

end;

procedure TLeastSquarFit.save();
var i: integer;
begin
for i := 1 to itwidth do l_array := z[n + 1, i];
if not dm.save(ForecastDate, 'T_Forecast_3Result') then exit;
//--»¹Òª¼ÓÉÏÒѾ­ÖªµÀµÄÐÞÕýÖµ
DM.sq:=FORMAT(GetTxtFile('./SQL/¼ÓÐÞÕýÖµ.sql'),[FORMATDATETIME('YYYY-MM-DD',ForecastDate)]);
DM.Exe_SQ;
//----
// ɾ³ý T_Forecast_2DFastCalculate ÖеĵÚÒ»Ìõ
// dm.sq:='delete from T_Forecast_2DFastCalculate where iid in (select min(iid) as iid from T_Forecast_2DFastCalculate )';
// dm.Exe_SQ;

//v1.0 ²ÉÓò»É¾³ý·ñÔòÊý¾ÝϽµÃ÷ÏÔ

//°Ñ¸Õ¸ÕÔ¤²âµÄÒ²±£´æµ½T_Forecast_2DFastCalculate£¬´Ó¶øʵÏÖÁËÏÂÒ»´Îfast ¼ÆËã
if not dm.save(ForecastDate, 'T_Forecast_2DFastCalculate') then exit;



end;

function TLeastSquarFit.Execute: boolean;
begin
result := false;
if N < 2 then begin MSG('&amp;Icirc;&amp;THORN;·¨&amp;Ocirc;¤&amp;sup2;&amp;acirc;&amp;pound;&amp;iexcl;&amp;Ograve;&amp;ordf;&amp;Ccedil;ó&amp;cedil;ù&amp;frac34;&amp;Yacute;2&amp;Igrave;ì&amp;Ograve;&amp;Ocirc;&amp;Eacute;&amp;Iuml;&amp;micro;&amp;Auml;&amp;Agrave;ú&amp;Ecirc;·&amp;Ecirc;&amp;yacute;&amp;frac34;&amp;Yacute;&amp;sup2;&amp;Aring;&amp;Auml;&amp;Uuml;&amp;Ocirc;¤&amp;sup2;&amp;acirc;!'); EXIT; end;
if not LoadData() then exit;
ii := Get_ii();
Set_PXi();
sgm_pxi := get_sgm_pxi();
iss := Get_iss();
ips := Get_ips();
a := Get_a();
b := Get_b();

Set_s();
Set_s_of_N_add_1(); //&amp;cedil;ù&amp;frac34;&amp;Yacute;&amp;Agrave;ú&amp;Ecirc;·&amp;pound;&amp;not;&amp;Ograve;&amp;sup2;&amp;frac34;&amp;Iacute;&amp;Ecirc;&amp;Ccedil;&amp;Eacute;&amp;Iuml;&amp;Atilde;&amp;aelig;&amp;micro;&amp;Auml;s,&amp;Ccedil;ó&amp;AElig;&amp;frac12;&amp;frac34;ùs
PXi[n + 1] := a + b * (n + 1);
calc_result();
save();
result := true;
end;

procedure TLeastSquarFit.calc_result();
var i: integer;
begin
for i := 1 to itwidth do
begin
z[n + 1, i] := s[n + 1, i] * PXi[n + 1];
end;
end;

function TLeastSquarFit.Get_ii(): integer;
var i: integer;
begin
result := 0;
for i := 1 to n do result := result + i * i;
end;

procedure TLeastSquarFit.Set_PXi;
var i, t: integer;
d: double; //×&amp;cent;&amp;Ograve;&amp;acirc; &amp;cedil;ù&amp;frac34;&amp;Yacute;&amp;Icirc;ó&amp;sup2;&amp;icirc;&amp;Ocirc;&amp;shy;&amp;Agrave;í&amp;pound;&amp;not;&amp;sup2;&amp;raquo;&amp;Ograve;&amp;ordf;&amp;Ograve;&amp;Ocirc;&amp;Icirc;&amp;ordf;&amp;sup2;&amp;Eacute;&amp;Oacute;&amp;Atilde;d&amp;Acirc;é·&amp;sup3;
begin
for i := 1 to n do
begin
d := 0;
for t := 1 to itwidth do
begin
d := d + z[i, t];
end;
PXi := d / itwidth;

end;

end;


function TLeastSquarFit.get_sgm_pxi(): double;
var i: integer;
begin
result := 0;
for i := 1 to N do result := result + PXi;

end;

function TLeastSquarFit.get_iss: double;
var i: integer;
begin
result := 0;
for i := 1 to N do result := result + i;
end;

function TLeastSquarFit.get_ips: double;
var i: integer;
begin
result := 0;
for i := 1 to N do result := result + i * PXi;
end;



function TLeastSquarFit.get_a: double;
var D: DOUBLE;
begin
D := (ii * sgm_pxi - iss * ips);
result := D / (N * ii - iss * iss);
end;

function TLeastSquarFit.get_b: double;
begin
result := (sgm_pxi - n * a) / iss;
end;

procedure TLeastSquarFit.Set_s();
var i, j: integer;
begin
for i := 1 to N do
begin
for j := 1 to itwidth do
begin
s[i, j] := z[i, j] / PXi;
end;
end;
end;

procedure TLeastSquarFit.Set_s_of_N_add_1(); //&amp;frac14;&amp;AElig;&amp;Euml;&amp;atilde;&amp;raquo;ú&amp;sup3;&amp;ouml;S N+1 &amp;Igrave;ì
var i, j: integer;
d: double;
begin
for I := 1 to itwidth do
begin
d := 0;
for j := 1 to N do d := d + s[j, i];
s[n + 1, i] := d / n;
end;

end;


function TLeastSquarFit.LoadData(): boolean; //×°&amp;Ocirc;&amp;Oslash;&amp;frac34;&amp;Oslash;&amp;Otilde;ó
var i, j: integer;
tmpdate: tdatetime;
IID:INTEGER;
begin
tmpdate := ForecastDate - n;
result := false;
DM.sq:='SELECT TOP 1 IID FROM T_Forecast_2DFastCalculate ORDER BY IID';
DM.Open_SQ;
IID:=DM.GFI('IID'); //IID±&amp;Oslash;&amp;Egrave;&amp;raquo;&amp;acute;&amp;aelig;&amp;Ocirc;&amp;Uacute;

for i := 1 to N do
begin
dm.sq := 'select * from T_Forecast_2DFastCalculate WHERE IID='+INTTOSTR(IID) ;
dm.Open_SQ;
if dm.Eof then
begin
showmessage('&amp;Icirc;&amp;acute;&amp;Ouml;&amp;ordf;&amp;acute;í&amp;Icirc;ó&amp;pound;&amp;not;&amp;Atilde;&amp;raquo;&amp;Oacute;&amp;ETH;iid=' + inttostr(iid) + '&amp;micro;&amp;Auml;&amp;Ocirc;¤&amp;sup2;&amp;acirc;&amp;Ecirc;&amp;yacute;&amp;frac34;&amp;Yacute;&amp;pound;&amp;iexcl;');
//&amp;AElig;&amp;auml;&amp;Ecirc;&amp;micro;&amp;Otilde;&amp;acirc;&amp;cedil;&amp;ouml;&amp;acute;í&amp;Icirc;ó&amp;Ecirc;&amp;Ccedil;&amp;sup2;&amp;raquo;&amp;iquest;&amp;Eacute;&amp;Auml;&amp;Uuml;·&amp;cent;&amp;Eacute;ú&amp;micro;&amp;Auml;&amp;pound;&amp;not;&amp;Ograve;ò&amp;Icirc;&amp;ordf;iid &amp;Oacute;&amp;brvbar;&amp;cedil;&amp;Atilde;&amp;Ecirc;&amp;Ccedil;&amp;Aacute;&amp;not;&amp;ETH;&amp;oslash;&amp;micro;&amp;Auml;
exit;
end;
for j := 1 to itWidth do z[i, j] := dm.gfn('&amp;Ecirc;±&amp;iquest;&amp;Igrave;' + fmt(j - 1));
tmpdate := tmpdate + 1;
inc(IID);
end;
result := true;
end;
 
to:13708782004
怎么注释都乱码了,怎么看啊?
好像不是我要的啊!
 
to:13708782004
老兄,可否注释详细一点啊!谢谢!
 
可以啊!我的电脑有问题啊!请qq:42872272
 
如果看得上眼,我开发的电力负荷预测转给你算了!
 
接受答案了.
 
后退
顶部