我这样实现了,提提意见
procedure DoPaintNHLine(nCanvas:TCanvas;P:Array of TPoint;nCount:Integer);
Type
TXs=Record
A,B,C:Real;
end;
pXs=^AXs;
AXs=Array[0..1000] of TXs;
var
TmpP:Array [0..2] of TPoint;
A,B,C:real;
i,J,TmpY:integer;
JQXs:real;
Xs
Xs;
procedure GetXs(var a,b,c:real;P:Array of TPoint);
var iFz,iFm:real;
function Pf(n:integer):integer;
begin
Result:=n*n;
end;
begin
iFz:=(P[0].Y-P[2].Y)*(P[0].X-P[1].X)-(P[0].Y-P[1].Y)*(P[0].X-P[2].X);
iFm:=(Pf(P[0].X)-Pf(P[2].X))*(P[0].X-P[1].X)-(Pf(P[0].X)-Pf(P[1].X))*(P[0].X-P[2].X);
a:=iFz/iFm;
b:=((P[0].Y-P[1].Y)-(Pf(P[0].X)-Pf(P[1].X))*a)/(P[0].X-P[1].X);
c:=P[0].Y-a*Pf(P[0].X)-b*P[0].X;
end;
function GetYValue(A,B,C:real;X:integer):integer;
begin
Result:=Round(A*X*X+B*X+C);
end;
begin
For i:=0 to nCount-1 do
nCanvas.Ellipse(p
.X-2,P.Y-2,P.X+2,p.Y+2);
GetMem(Xs,(nCount-2)*SizeOf(TXs));
For i:=0 to nCount-1-2 do
begin
MoveMemory(@TmpP[0],@P,3*SizeOf(TPoint));
GetXs(A,B,C,TmpP);
Xs^.A:=A;Xs^.B:=B;Xs^.C:=C;
end;
nCanvas.MoveTo(P[0].X,P[0].Y);
For i:=0 to nCount-1-1 do
begin
JQXs:=0;
For J:=P.X to P[i+1].X do
begin
if (i=0) or (i=nCount-2) then
begin
if i=0 then
TmpY:=GetYValue(Xs.A,Xs.B,Xs.C,J)
else
TmpY:=GetYValue(Xs[i-1].A,Xs[i-1].B,Xs[i-1].C,J)
end
else
begin
TmpY:=Round(GetYValue(Xs[i-1].A,Xs[i-1].B,Xs[i-1].C,J)*(1-JQxs)+GetYValue(Xs.A,Xs.B,Xs.C,J)*JQXs);
JqXs:=JqXs+1/(P[i+1].X-P.X);
end;
nCanvas.LineTo(J,TmpY);
end;
end;
FreeMem(Xs);
end;