Difference between revisions of "Distance"
From SCAR Divi Manual
(Created page with "==Definition== <source lang="scar" lines="false"> function Distance(x1, y1, x2, y2: Integer): Integer; </source> ===Source Code=== <source lang="scar"> function Distance(x1, y1,...") |
|||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==Definition== | ==Definition== | ||
<source lang="scar" lines="false"> | <source lang="scar" lines="false"> | ||
− | function Distance( | + | function Distance(const X1, Y1, X2, Y2: Integer): Extended; |
</source> | </source> | ||
===Source Code=== | ===Source Code=== | ||
<source lang="scar"> | <source lang="scar"> | ||
− | function Distance( | + | function Distance(const X1, Y1, X2, Y2: Integer): Extended; |
var | var | ||
− | + | A, B: Extended; | |
− | |||
− | |||
begin | begin | ||
− | + | A := X1 - X2; | |
− | + | B := Y1 - Y2; | |
− | + | Result := Sqrt(A * A + B * B); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end; | end; | ||
</source> | </source> | ||
Line 27: | Line 18: | ||
==Availability== | ==Availability== | ||
SCAR Divi 3.00 > Current | SCAR Divi 3.00 > Current | ||
+ | |||
+ | *Before 3.21 the workaround for larger distances was not yet implemented. | ||
+ | *Bedore 3.37 returned an integer value | ||
==Description== | ==Description== | ||
− | Calculates the [http://mathworld.wolfram.com/Distance.html distance] between 2 given points defined by (''' | + | Calculates the [http://mathworld.wolfram.com/Distance.html distance] between 2 given points defined by ('''X1''', '''Y1''') and ('''X2''', '''Y2'''). |
==Example== | ==Example== | ||
Line 39: | Line 33: | ||
Output: | Output: | ||
− | 4 | + | 4.24264068711929 |
[[Category:Functions]] | [[Category:Functions]] | ||
[[Category:Math Functions]] | [[Category:Math Functions]] |
Latest revision as of 14:53, 12 November 2012
Definition
function Distance(const X1, Y1, X2, Y2: Integer): Extended;
Source Code
function Distance(const X1, Y1, X2, Y2: Integer): Extended; var A, B: Extended; begin A := X1 - X2; B := Y1 - Y2; Result := Sqrt(A * A + B * B); end;
Availability
SCAR Divi 3.00 > Current
- Before 3.21 the workaround for larger distances was not yet implemented.
- Bedore 3.37 returned an integer value
Description
Calculates the distance between 2 given points defined by (X1, Y1) and (X2, Y2).
Example
begin WriteLn(Distance(5, 6, 8, 9)); end.
Output:
4.24264068711929