//p:圆外点; center:圆心; radius:半径; q:1=(切点1坐标)、2=(切点2坐标)
function gTangentPoint(p,center:TPoint; radius:Double; q:Integer = 1):TPoint;
var d:TPoint;
r1, r2, r3, d1: Double;
begin
d.X := p.X - center.X;
d.Y := p.Y - center.Y;
//计算p点与圆心相对于X轴的夹角
r1 := arctan2(d.Y, d.X);
//计算p点与圆心、点与切点1这两条线段间的夹角
d1:= sqrt(d.X*d.X + d.Y*d.Y);
r2:= arcsin(radius/d1);
case q of
1: //计算切点1相对于圆心的x、y坐标
begin
//计算从切点1向圆的垂直直径做垂线形成的直角三角形的一个角
r3:= r1 - r2 + PI/2;
end;
else //计算切点2相对于圆心的x、y坐标
begin
//计算p点与切线2相对于X轴的夹角
r3:= r1 + r2 -PI/2;
end;
end;
Result.X := center.X + Round(radius * cos(r3));
Result.Y := center.Y + Round(radius * sin(r3));
end;