Algorithmic Solutions > LEDA > LEDA Guide > Geometry > Length and Distance

Length and Distance

If p and q are POINTs and l is a LINE then the following functions compute the square of the distance between p and q, and l and q, respectively.
	RAT_TYPE p.sqr_dist(q);
	RAT_TYPE l.sqr_dist(q);

Remark: In the rational kernel there are no functions to compute distances, in the floating point kernel there are, but it is not recommended to use them.

We use the notation POINT (LINE) to indicate that the algorithm works both for points (lines) and rat_points (rat_lines). RAT_TYPE is double for the floating point kernel and Rational for the rational kernel. (More information on Writing Kernel Independent Code.)


Do not compute distances in the floating point kernel!

Here is the reason why: The distance between two points p and q in the plane is equal to ((x_p-x_q)2+(y_p-y_q)2)1/2 and, therefore, in general, not a rational number. The squared distance is a rational number.

The rational kernel only provides functions to compute squared distances.

The floating point kernel uses the sqrt function from the standard math-library to compute distances.

Remark: The LEDA authors find that the computation of distances is rarely needed.

See also:

Data Types for 2D Geometry

Writing Kernel Independent Code



Advanced Data types for 2-D geometry

Data Types for 3-D Geometry

Geometry Algorithms


Please send any suggestions, comments or questions to
© Copyright 2001-2003, Algorithmic Solutions Software GmbH