function LenBetween(p1, p2: TGLVector): Single;
var
r: Single;
begin
//计算p1和p2之间的距离
if ((p1.X = 0) and (p1.Y = 0)) or ((p2.X = 0) and (p2.Y = 0)) then
begin
if (p1.X = 0) and (p1.Y = 0) then
r := sqrt(sqr(p2.X) + sqr(p2.Y));
if (p2.X = 0) and (p2.Y = 0) then
r := sqrt(sqr(p1.X) + sqr(p1.Y));
end
else
begin
if (p1.X = p2.X) or (p1.Y = p2.Y) then
begin
if p1.X = p2.X then
r := ABS(p2.Y - p1.Y);
if p1.Y = p2.Y then
r := ABS(p2.X - p1.X);
end
else
r := sqrt(sqr(p2.X - p1.X) + sqr(p2.Y - p1.Y));
end;
result := r;
end;