这是三点拟合的程序.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
Button1: TButton;
procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Index: Byte;
Point: array [1..3] of TPoint;
procedure Par(xs, ys, xm, ym, xe, ye: Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.Par(xs, ys, xm, ym, xe, ye: Integer);
var
d, d1, ax, ay, bx, by: Double;
n, i: Integer;
begin
ax:=(xe-2*xm+xs)*2;
ay:=(ye-2*ym+ys)*2;
bx:=xe-xs-ax;
by:=ye-ys-ay;
n:=Trunc(Sqrt(ax*ax+ay*ay));
n:=Trunc(Sqrt(n*100));
PaintBox1.Canvas.MoveTo(xs, ys);
d:=1/n;
d1:=d;
for i:=0 to n do
begin
PaintBox1.Canvas.LineTo(Trunc(ax*d1*d1+bx*d1+xs), Trunc(ay*d1*d1+by*d1+ys));
d1:=d1+d
end;
PaintBox1.Canvas.LineTo(xe, ye)
end;
procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Inc(Index);
if Index<4 then
begin
Point[Index].X:=x;
Point[Index].Y:=y;
PaintBox1.Canvas.Pixels[x,y]:=clred
end
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Index:=0;
Par(Point[1].X, Point[1].Y, Point[2].X, Point[2].Y, Point[3].X, Point[3].Y)
end;
end.