Navigation: Up, Table of Contents, Bibliography, Index, Title Page

3D Squared Distances

Introduction

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:

R::FT squared_distance ( Type1<R> obj1, Type2<R> obj2)

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 reference if you want to know why.

3D Distance Comparisons

Instead of computing distances and then comparing them the following predicates can be used:

#include <CGAL/distance_predicates_3.h>

Comparison_result
cmp_dist_to_point ( Point_3<R> p,
Point_3<R> q,
Point_3<R> r)
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.

bool
has_larger_dist_to_point ( Point_3<R> p,
Point_3<R> q,
Point_3<R> r)
returns true iff the distance between q and p is larger than the distance between r and p.

bool
has_smaller_dist_to_point ( Point_3<R> p,
Point_3<R> q,
Point_3<R> r)
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.

Comparison_result
cmp_signed_dist_to_plane ( Plane_3<R> l,
Point_3<R> p,
Point_3<R> q)
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.

bool
has_larger_signed_dist_to_plane ( Plane_3<R> l,
Point_3<R> p,
Point_3<R> q)
returns true iff the signed distance of p and l is larger than the signed distance of q and l.

bool
has_smaller_signed_dist_to_plane ( Plane_3<R> l,
Point_3<R> p,
Point_3<R> q)
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.

Comparison_result
cmp_signed_dist_to_plane ( Point_3<R> p,
Point_3<R> q,
Point_3<R> r,
Point_3<R> s,
Point_3<R> t)

bool
has_smaller_signed_dist_to_plane ( Point_3<R> p,
Point_3<R> q,
Point_3<R> r,
Point_3<R> s,
Point_3<R> t)

bool
has_larger_signed_dist_to_plane ( Point_3<R> p,
Point_3<R> q,
Point_3<R> r,
Point_3<R> s,
Point_3<R> t)


Next chapter: The dD Kernel: an Overview
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The GALIA project. Jan 18, 2000.