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,

CodePudding user response:

refer to the second floor yyfhz response:
to make a suggestion, a direct comparison R and D * * R D, avoid SQRT can speed up,


The path! Do multiplication is soon, now the CPU has the hardware multiplier, but open square will invoke the floating point arithmetic of
 function PtInCircle (const P, CP: TPoint; Const R: cardinal) : integer; 
Var
D2, R2, dX, dY: Integer;
The begin
R2:=R * R;
DX:=P.X - CP. X;
DY:=P.Y - CP. Y;
D2:=dX + dY dX * * dY;
Result:=r2-d2;
end;

CodePudding user response:

Point to determine the distance to the center of the circle, not to root operation, a direct comparison square, will hurry up,

CodePudding user response:

reference 4 floor SupermanTm response:
Quote: refer to the second floor yyfhz response:

To make a suggestion, a direct comparison R * R and D * D, avoid SQRT can speed up,


The path! Do multiplication is soon, now the CPU has the hardware multiplier, but open square will invoke the floating point arithmetic of
 function PtInCircle (const P, CP: TPoint; Const R: cardinal) : integer; 
Var
D2, R2, dX, dY: Integer;
The begin
R2:=R * R;
DX:=P.X - CP. X;
DY:=P.Y - CP. Y;
D2:=dX + dY dX * * dY;
Result:=r2-d2;
end;


Study it!
  • Related