There is a family of functions called squared_distance that compute the square of the Euclidean distance between two geometric objects. For arbitrary three-dimensional geometric objects obj1 and obj2 the squared distance is defined as the minimal squared_distance(p1, p2), where p1 is a point of obj1 and p2 is a point of obj2. Note that for objects that have an inside (a bounded region), this inside is part of the object. So, the squared distance from a point inside is zero, not the squared distance to the closest point on the boundary.
The general format of the functions is:
|
|
| |
where the types Type1 and Type2 can be any of the following:
Those routines are defined in the header file CGAL/squared_distance_3.h.
Why the square?
There are routines that compute the square of the Euclidean distance, but no
routines that compute the distance itself. See Section
if
you want to know why.
Instead of computing distances and then comparing them the following predicates can be used:
#include <CGAL/distance_predicates_3.h>
|
|
| |||
| compares the distances of points q and r to point p. returns SMALLER, iff q is closer to p than r, LARGER, iff r is closer to p than q, and EQUAL otherwise. | ||||
|
|
| |||
| returns true iff the distance between q and p is larger than the distance between r and p. | ||||
|
|
| |||
| returns true iff the distance between q and p is smaller than the distance between r and p. | ||||
The following compares the signed distances of two points and an oriented plane. The sign of the distance of a point to an oriented plane is positive (negative) iff the point lies on the positive (negative) side of the plane, and zero otherwise.
|
|
| |||
| returns LARGER iff the signed distance of p and l is larger than the signed distance of q and l, SMALLER, iff it is smaller, and EQUAL iff both are equal. | ||||
|
|
| |||
| returns true iff the signed distance of p and l is larger than the signed distance of q and l. | ||||
|
|
| |||
| returns true iff the signed distance of p and l is smaller than the signed distance of q and l. | ||||
The following functions corresponds to the preceding ones with the exception that the plane is implicitly given by the first three points p, q, and r. The points whose signed distance to the plane is compared are s and t.
Precondition: Points defining the plane are not equal.
|
|
| |||
|
|
| |||
|
|
| |||