Sign in Join
FPDoc Onlineexperiment

Distance function

In unit GraphMath

Gets the distance between two points, or the distance of a point from a specified line.

Declaration

pascal
function Distance(const PT1: TPoint; const Pt2: TPoint): Extended
 ; overload

Arguments

PT1

Starting point for the calculated distance.

Pt2

Ending point for the calculated distance.

Function result

Straight-line distance between the specified coordinates or objects.

Description

Distance is an overloaded function with variants that operate on either two point coordinates, or on a point and a line defined by two additional points values. The Distance() function is used primarily for internal purposes (such as in Bezier2PolyLine and EccentricAngle) but can be used for any purpose.

The return value is an Extended type with the calculated distance between the argument values. The return value is always a positive value.

The variants using two point arguments (TPoint or TFloatPoint) calculates the length of a straight line between the coordinates in PT1 and PT2 using the Pythagorean theorem. The distance between identical points is always zero (0).

The variant with three TFloatPoint arguments calculates the distance between the point Pt and the line represented by the points in SP and EP using Euclidean geometry. The distance is derived by finding the length of an imaginary line between Pt and the closest point that intersects the slope of the line in SP and EP. The distance for a point which lies on the defined line is always zero (0).

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.