type
TPosition = record
x: real;
y: real;
end;
// 计算两点之间的距离
function Distance(pt1, pt2: TPosition): real;
begin
Result := sqrt(sqr(pt1.x - pt2.x) + sqr(pt1.y - pt2.y));
end;
// 计算两点连线与X轴的夹角
function GetAngleToXAxis(posSrc1, posSrc2: TPosition): real;
var
len, cosv, sinv: real;
begin
len := Distance(posSrc1, posSrc2);
cosv := (posSrc2.x - posSrc1.x) / len;
sinv := (posSrc2.y - posSrc1.y) / len;
if sinv >= 0 then
Result := arccos(cosv)
else
Result := 2 * pi - arccos(cosv);
end;
// 计算圆弧最大坐标(圆弧为逆时针)
function GetMaxPoint(m_center, m_begin, m_end: TPosition): TPosition;
var
MaxX, MaxY ,tempX, tempY: real;
pb, i: integer;
radius, StartRa, EndRa: real;
begin
pb := 0 ;
radius := Distance(m_center, m_begin) ;
StartRa := GetAngleToXAxis(m_center, m_begin) ;
EndRa := GetAngleToXAxis(m_center, m_end) ;
MaxX := max( m_begin.x, m_end.x );
MaxY := max( m_begin.y, m_end.y );
if StartRa < EndRa then
pb := 1
else begin
MaxX := max(MaxX, m_center.x+radius) ;
MaxY := max(MaxY, m_center.y) ;
tempX := MaxX ;
tempY := MaxY ;
pb := 2 ;
end;
for i := 0 to 3 do
begin
if ((pb = 1) and (pi*i/2 > StartRa) and (pi*i/2 < EndRa)) or
((pb = 2) and not ((pi*i/2 > EndRa) and (pi*i/2 < StartRa))) then
begin
if i = 1 then
begin
tempX := m_center.x;
tempY := m_center.y + radius;
end
else if i = 2 then
begin
tempX := m_center.x - radius;
tempY := m_center.y;
end
else if i = 3 then
begin
tempX := m_center.x;
tempY := m_center.y - radius;
end;
MaxX := max(MaxX, tempX) ;
MaxY := max(MaxY, tempY) ;
end;
end;
Result.x := MaxX;
Result.y := MaxY;
end;