uses System.Types;function PtInCircle(const P, CP: TPoint; const R: cardinal): integer;
var
  D: cardinal;
begin
  if P.X = CP.X then D := abs(CP.Y - P.Y) else
    if P.Y = CP.Y then D := abs(CP.X - P.X) else
      D := round(sqrt(abs((CP.X - P.X) * (CP.X - P.X)) + 
                      abs((CP.Y - P.Y) * (CP.Y - P.Y))));
  if D < R then Result := 1 else
    if D = R then Result := 0 else
      Result := -1;
end;
P是点坐标,CP是圆心坐标,R是园半径,返回值1: 点在圆内,0: 点在圆上,-1: 点在圆外
使用:writeln(PtInCircle(Point(9, 9), Point(1, 2), 5));

解决方案 »

  1.   

    给LZ一个建议,直接比较R*R和D*D,避免SQRT可以加快速度 。
      

  2.   


    正道!做乘法是很快的,现在的CPU都有硬件乘法器,但开平方就一定要调用浮点运算的
    function PtInCircle(const P, CP: TPoint; const R: cardinal): integer;
    var
      D2, R2, dX, dY: Integer;
    begin
      R2:= R * R;
      dX:= P.X - CP.X;
      dY:= P.Y - CP.Y;
      D2:= dX * dX + dY * dY;
      Result:= R2 - D2;
    end;
      

  3.   


    正道!做乘法是很快的,现在的CPU都有硬件乘法器,但开平方就一定要调用浮点运算的
    function PtInCircle(const P, CP: TPoint; const R: cardinal): integer;
    var
      D2, R2, dX, dY: Integer;
    begin
      R2:= R * R;
      dX:= P.X - CP.X;
      dY:= P.Y - CP.Y;
      D2:= dX * dX + dY * dY;
      Result:= R2 - D2;
    end;
    Study it !