| ESBDistance Function |
Unit
QESBPCSMath
Declaration
Function ESBDistance(const X1, Y1, X2, Y2: Extended): Extended;
Description
Rather than the "traditional" algebraic solution, we use a method that improved accuracy, especially when either A or C or both are much closer to zero than B, then the discriminant is nearly equal to B and one of the calculations will involve the subtraction of two nearly equal quantities. Thanks to Rory Daulton for this improvement. Implementation
function ESBDistance (const X1, Y1, X2, Y2: Extended): Extended;
{ Rory Daulton suggested this more tolerant routine }
var
X, Y: Extended;
begin
X := Abs (X1 - X2);
Y := Abs (Y1 - Y2);
if X > Y then
Result := X * Sqrt (1 + Sqr (Y / X))
else if Y <> 0 then
Result := Y * Sqrt (1 + Sqr (X / Y))
else
Result := 0
End; |
|
|