Home > Back-end > To known circle radius and center coordinates for some relation with the location of the circle of D
To known circle radius and center coordinates for some relation with the location of the circle of D
Time:09-16
CodePudding user response:
USES the System. The Types;
The function PtInCircle (const P, CP: TPoint; Const R: cardinal) : integer; Var D: the cardinal; The begin If P.X=CP. Then D: X=abs (CP) Y - P.Y) else If P.Y=CP. Then D: Y=abs (CP) X-ray P.X) else D:=round (SQRT (abs ((CP. X-ray P.X) * (CP. X-ray P.X)) + Abs ((CP) Y - P.Y) * (CP) Y - P.Y)))); If D & lt; R then Result:=1 else If D=R then Result:=0 else Result:=1; end;
P is point coordinates, the CP is center, R is the radius of the return value 1: point within the circle, 0: point on the circle, 1: point outside the circle Use: writeln (PtInCircle (Point (9, 9), Point (1, 2), 5));
CodePudding user response:
To make a suggestion, a direct comparison R and D * * R D, avoid SQRT can speed up,
CodePudding user response:
Calculated two distance is greater than the radius, is equal to the radius, the radius of less than,