先写一个求线段方向的函数,然后计算累计角度:
function GetDirection(X1,Y1,NX,NY : double)
ouble;
var
BufLen,Direction : Double;
begin
BufLen := Sqrt(Sqr(X1-NX)+Sqr(Y1-NY));
if (Abs(NX-X1)< 10e-300) then begin
if (Abs(Y1-NY)< 10e-300) then begin
//等于没有移动}
end
else begin
if (Y1-NY)>0 then Direction := PI/2
else Direction := 3*PI/2;
end;
end
else begin
if ArcTan((Y1-NY)/(NX-X1))>0 then begin
if (Sin((Y1-NY)/BufLen)>0) then
Direction := ArcTan((Y1-NY)/(NX-X1))
else
Direction := ArcTan((Y1-NY)/(NX-X1))+PI;
end
else begin
if (Sin((Y1-NY)/BufLen)>0) then
Direction := ArcTan((Y1-NY)/(NX-X1))+PI
else begin
Direction := ArcTan((Y1-NY)/(NX-X1));
if (Direction = 0) and (X1 > NX) then Direction := PI;
end;
end;
end;
if Direction < 0 then Direction := 2 * PI + Direction;
Result := -Direction;
end;