to CJ, eYes: 没时间完成, 但是可以给你们一些小帮助如旋转,求教函数.
const
FPI180 = pi / 180;
F180PI = 180 / pi;
Delta = 0.0001;
type
HJPoint = record
x:do
uble;
y:do
uble;
z:do
uble;
end;
//Sin of angle given by degree
function SinA(value: integer):do
uble;
begin
result:=Sin(value*FPI180);
end;
//cos of degree
function CosA(value: integer):do
uble;
begin
Result:=Cos(value*FPI180);
end;
function TanA(value: integer):do
uble;
begin
result:=Sin(value*fPi180)/Cos(value*fPi180);
end;
//get a new point away from p1 with a given angle and distance
function Polar(p1: HJPoint;
angle: integer;
dist:do
uble): HJPoint;
begin
result.x:=cos(angle*FPi180)*abs(dist)+p1.x;
result.y:=sin(angle*FPi180)*abs(dist)+p1.y;
end;
//roatata a point p round baseP, at a given angle
function RotatePoint(const P, baseP: HJPoint;
angle: integer): HJPoint;
var
x,y:do
uble;
begin
x:=p.x-baseP.x;
y:=p.y-BaseP.y;
result.x:=BaseP.x+x*CosA(Angle)-y*SinA(Angle);
result.y:=BaseP.y+x*SinA(Angle)+y*CosA(Angle);
result.z:=p.z;
end;
//get the intercecting state of two lines p1p2, p3p4, if they are not
//parall out Parameter, PinL returns the new point position in line1
function Intersect(p1,p2,p3,p4: HJPoint;
var PinL:do
uble): boolean;
//pinl: location of point in line1(p1,p2), <0 left, 0 start, 1 end, >1 right
var
k1,k2,k3,
y21,x21,y43,x43,y13,
xx1,yy1,
x,y:do
uble;
lstate: integer;
{ 1-l1hor, 2-l1ver, 4-l2hor, 8-l2ver }
begin
result:=false;
lstate:=0;
y21:=p2.y-p1.y;
x21:=p2.x-p1.x;
y43:=p4.y-p3.y;
x43:=p4.x-p3.x;
y13:=p1.y-p3.y;
if abs(y21) < delta then
lstate:=lstate or 1;
{l1 horrizental}
if abs(x21) < delta then
lstate:=lstate or 2;
{l1 vertical}
if abs(y43) <= delta then
lstate:=lstate or 4;
{l2 horrizental}
if abs(x43) <= delta then
lstate:=lstate or 8;
{l2 vertical}
case lstate of
0: //both nomal
begin
K1:=y21/x21;
k2:=x43/y43;
k3:=y43/x43;
if not (abs(k1-k3) <= delta) then
begin
result:=true;
x:=(k2*y13-k1*k2*p1.x+p3.x)/(1-k1*k2);
xx1:=x-p1.x;
PinL:=xx1/x21;
end;
end;
1: //line1 is hor
begin
result:=true;
y:=p1.y;
k2:=x43/y43;
x:=k2*(y-p3.y)+p3.x;
xx1:=x-p1.x;
PInL:=xx1/x21;
end;
2: { l1 ver }
begin
result:=true;
x:=p1.x;
k2:=y43/x43;
y:=k2*(x-p3.x)+p3.y;
yy1:=y-p1.y;
PInL:=yy1/y21;
end;
4: { l2 hor }
begin
result:=true;
y:=p3.y;
k1:=x21/y21;
x:=k1*(y-p1.y)+p1.x;
xx1:=x-p1.x;
PInL:=xx1/x21;
end;
3,5,7,10,12,13,14,15:{ both hor/both ver/null length }
result:=false;
6: { l1 ver l2 hor }
begin
result:=true;
y:=p3.y;
yy1:=y-p1.y;
PInL:=yy1/y21;
end;
8: { l2 ver }
begin
result:=true;
x:=p3.x;
xx1:=x-p1.x;
PInL:=xx1/x21;
end;
9: { l1 hor l2 ver }
begin
result:=true;
xx1:=p3.x-p1.x;
PInL:=xx1/x21;
end;
end;
{case}
if abs(pinl)<=delta then
pinl:=0
else
if abs(1-pinl)<=delta then
pinl:=1;
end;