Functions
core/vgl/vgl_closest_point.h File Reference

Set of closest-point functions. More...

#include <vgl/vgl_fwd.h>
#include <vcl_utility.h>

Go to the source code of this file.

Functions

template<class T >
void vgl_closest_point_to_linesegment (T &ret_x, T &ret_y, T x1, T y1, T x2, T y2, T x, T y)
 Closest point to (x,y) on the line segment (x1,y1)-(x2,y2).
template<class T >
void vgl_closest_point_to_linesegment (T &ret_x, T &ret_y, T &ret_z, T x1, T y1, T z1, T x2, T y2, T z2, T x, T y, T z)
 Closest point to (x,y,z) on the line segment (x1,y1,z1)-(x2,y2,z2).
template<class T >
int vgl_closest_point_to_non_closed_polygon (T &ret_x, T &ret_y, T const px[], T const py[], unsigned int n, T x, T y)
 Closest point to (x,y) on open polygon (px[i],py[i]).
template<class T >
int vgl_closest_point_to_non_closed_polygon (T &ret_x, T &ret_y, T &ret_z, T const px[], T const py[], T const pz[], unsigned int n, T x, T y, T z)
 Closest point to (x,y,z) on open polygon (px[i],py[i],pz[i]).
template<class T >
int vgl_closest_point_to_closed_polygon (T &ret_x, T &ret_y, T const px[], T const py[], unsigned int n, T x, T y)
 Closest point to (x,y) on closed polygon (px[i],py[i]).
template<class T >
int vgl_closest_point_to_closed_polygon (T &ret_x, T &ret_y, T &ret_z, T const px[], T const py[], T const pz[], unsigned int n, T x, T y, T z)
 Closest point to (x,y,z) on closed polygon (px[i],py[i],pz[i]).
template<class T >
vgl_point_2d< T > vgl_closest_point_origin (vgl_line_2d< T > const &l)
 Return the point on the given line closest to the origin.
template<class T >
vgl_homg_point_2d< T > vgl_closest_point_origin (vgl_homg_line_2d< T > const &l)
 Return the point on the given line closest to the origin.
template<class T >
vgl_point_3d< T > vgl_closest_point_origin (vgl_plane_3d< T > const &pl)
 Return the point on the given plane closest to the origin.
template<class T >
vgl_homg_point_3d< T > vgl_closest_point_origin (vgl_homg_plane_3d< T > const &pl)
 Return the point on the given plane closest to the origin.
template<class T >
vgl_point_3d< T > vgl_closest_point_origin (vgl_line_3d_2_points< T > const &l)
 Return the point on the given line closest to the origin.
template<class T >
vgl_homg_point_3d< T > vgl_closest_point_origin (vgl_homg_line_3d_2_points< T > const &l)
 Return the point on the given line closest to the origin.
template<class T >
vgl_point_2d< T > vgl_closest_point (vgl_line_2d< T > const &l, vgl_point_2d< T > const &p)
 Return the point on the given line closest to the given point.
template<class T >
vgl_point_2d< T > vgl_closest_point (vgl_point_2d< T > const &p, vgl_line_2d< T > const &l)
template<class T >
vgl_homg_point_2d< T > vgl_closest_point (vgl_homg_line_2d< T > const &l, vgl_homg_point_2d< T > const &p)
 Return the point on the given line closest to the given point.
template<class T >
vgl_homg_point_2d< T > vgl_closest_point (vgl_homg_point_2d< T > const &p, vgl_homg_line_2d< T > const &l)
template<class T >
vgl_point_3d< T > vgl_closest_point (vgl_plane_3d< T > const &pl, vgl_point_3d< T > const &p)
 Return the point on the given plane closest to the given point.
template<class T >
vgl_point_3d< T > vgl_closest_point (vgl_point_3d< T > const &p, vgl_plane_3d< T > const &pl)
template<class T >
vgl_homg_point_3d< T > vgl_closest_point (vgl_homg_plane_3d< T > const &pl, vgl_homg_point_3d< T > const &p)
 Return the point on the given plane closest to the given point.
template<class T >
vgl_homg_point_3d< T > vgl_closest_point (vgl_homg_point_3d< T > const &p, vgl_homg_plane_3d< T > const &pl)
template<class T >
vgl_point_2d< T > vgl_closest_point (vgl_polygon< T > const &poly, vgl_point_2d< T > const &point, bool closed=true)
 Return the point on the given polygon closest to the given point.
template<class T >
vgl_point_2d< T > vgl_closest_point (vgl_point_2d< T > const &point, vgl_polygon< T > const &poly, bool closed=true)
template<class T >
vcl_pair< vgl_homg_point_3d< T >
, vgl_homg_point_3d< T > > 
vgl_closest_points (vgl_homg_line_3d_2_points< T > const &line1, vgl_homg_line_3d_2_points< T > const &line2)
 Return the two points of nearest approach of two 3D lines, one on each line.
template<class T >
vgl_homg_point_3d< T > vgl_closest_point (vgl_homg_line_3d_2_points< T > const &l, vgl_homg_point_3d< T > const &p)
 Return the point on the given line which is closest to the given point.
template<class T >
vgl_homg_point_3d< T > vgl_closest_point (vgl_homg_point_3d< T > const &p, vgl_homg_line_3d_2_points< T > const &l)
template<class T >
vgl_point_3d< T > vgl_closest_point (vgl_line_3d_2_points< T > const &l, vgl_point_3d< T > const &p)
 Return the point on the given line which is closest to the given point.
template<class T >
vgl_point_3d< T > vgl_closest_point (vgl_point_3d< T > const &p, vgl_line_3d_2_points< T > const &l)
template<class T >
vgl_point_3d< T > vgl_closest_point (vgl_point_3d< T > const &p, vgl_infinite_line_3d< T > const &l)
template<class T >
vgl_point_3d< T > vgl_closest_point (vgl_infinite_line_3d< T > const &l, vgl_point_3d< T > const &p)
template<class T >
vgl_point_3d< T > vgl_closest_point (vgl_point_3d< T > const &p, vgl_ray_3d< T > const &r)
template<class T >
vgl_point_3d< T > vgl_closest_point (vgl_ray_3d< T > const &r, vgl_point_3d< T > const &p)
template<class T >
double vgl_closest_point_t (vgl_line_3d_2_points< T > const &l, vgl_point_3d< T > const &p)
 Return the point on the given line which is closest to the given point.
template<class T >
double vgl_closest_point_t (vgl_point_3d< T > const &p, vgl_line_3d_2_points< T > const &l)
template<class T >
vcl_pair< vgl_point_3d< T >
, vgl_point_3d< T > > 
vgl_closest_points (const vgl_line_3d_2_points< T > &l1, const vgl_line_3d_2_points< T > &l2, bool *unique=0)
 Return the points of closest approach on 2 3D lines.
template<class T >
vcl_pair< vgl_point_3d< T >
, vgl_point_3d< T > > 
vgl_closest_points (const vgl_infinite_line_3d< T > &l1, const vgl_infinite_line_3d< T > &l2, bool *unique=0)
 Return the points of closest approach on two infinite 3D lines.
template<class T >
vcl_pair< vgl_point_3d< T >
, vgl_point_3d< T > > 
vgl_closest_points (const vgl_line_segment_3d< T > &l1, const vgl_line_segment_3d< T > &l2, bool *unique=0)
 Return the points of closest approach on 2 3D line segments.
template<class T >
vgl_point_2d< T > vgl_closest_point (vgl_line_segment_2d< T > const &l, vgl_point_2d< T > const &p)
 Return the closest point on a line segment l to a point p in 2D.
template<class T >
vgl_point_2d< T > vgl_closest_point (vgl_point_2d< T > const &p, vgl_line_segment_2d< T > const &l)
template<class T >
vgl_point_3d< T > vgl_closest_point (vgl_line_segment_3d< T > const &l, vgl_point_3d< T > const &p)
 Return the closest point on a line segment l to a point p in 3D.
template<class T >
vgl_point_3d< T > vgl_closest_point (vgl_point_3d< T > const &p, vgl_line_segment_3d< T > const &l)

Detailed Description

Set of closest-point functions.

Author:
Peter Vanroose

All these functions have two arguments which are geometry objects, and return either a pair of points (one from each object) which are the ones closest to each other, or just 1 point in case one of the objects is a point.

See also vgl_distance if you only need the shortest distance between two geometric objects and not the actual closest points.

    Modifications
      5 June 2003 Peter Vanroose created from bits and pieces in vgl_distance
      5 June 2003 Brendan McCane added closest-point algo for 3D lines
     11 June 2003 Peter Vanroose added closest-point on 3D line from point
     14 Nov. 2003 Peter Vanroose made all functions templated
     25 Sept 2004 Peter Vanroose added full 3D interface
   

Definition in file vgl_closest_point.h.


Function Documentation

template<class T >
vgl_point_2d< T > vgl_closest_point ( vgl_line_2d< T > const &  l,
vgl_point_2d< T > const &  p 
)

Return the point on the given line closest to the given point.

Definition at line 244 of file vgl_closest_point.txx.

template<class T >
vgl_point_2d<T> vgl_closest_point ( vgl_point_2d< T > const &  p,
vgl_line_2d< T > const &  l 
) [inline]

Definition at line 113 of file vgl_closest_point.h.

template<class T >
vgl_homg_point_2d< T > vgl_closest_point ( vgl_homg_line_2d< T > const &  l,
vgl_homg_point_2d< T > const &  p 
)

Return the point on the given line closest to the given point.

Definition at line 254 of file vgl_closest_point.txx.

template<class T >
vgl_homg_point_2d<T> vgl_closest_point ( vgl_homg_point_2d< T > const &  p,
vgl_homg_line_2d< T > const &  l 
) [inline]

Definition at line 124 of file vgl_closest_point.h.

template<class T >
vgl_point_3d< T > vgl_closest_point ( vgl_plane_3d< T > const &  pl,
vgl_point_3d< T > const &  p 
)

Return the point on the given plane closest to the given point.

Definition at line 265 of file vgl_closest_point.txx.

template<class T >
vgl_point_3d<T> vgl_closest_point ( vgl_point_3d< T > const &  p,
vgl_plane_3d< T > const &  pl 
) [inline]

Definition at line 135 of file vgl_closest_point.h.

template<class T >
vgl_homg_point_3d< T > vgl_closest_point ( vgl_homg_plane_3d< T > const &  pl,
vgl_homg_point_3d< T > const &  p 
)

Return the point on the given plane closest to the given point.

Definition at line 278 of file vgl_closest_point.txx.

template<class T >
vgl_homg_point_3d<T> vgl_closest_point ( vgl_homg_point_3d< T > const &  p,
vgl_homg_plane_3d< T > const &  pl 
) [inline]

Definition at line 146 of file vgl_closest_point.h.

template<class T >
vgl_point_2d< T > vgl_closest_point ( vgl_polygon< T > const &  poly,
vgl_point_2d< T > const &  point,
bool  closed = true 
)

Return the point on the given polygon closest to the given point.

If the third argument is "false", the edge from last to first point of each polygon sheet is not considered part of the polygon.

Definition at line 288 of file vgl_closest_point.txx.

template<class T >
vgl_point_2d<T> vgl_closest_point ( vgl_point_2d< T > const &  point,
vgl_polygon< T > const &  poly,
bool  closed = true 
) [inline]

Definition at line 161 of file vgl_closest_point.h.

template<class T >
vgl_homg_point_3d< T > vgl_closest_point ( vgl_homg_line_3d_2_points< T > const &  l,
vgl_homg_point_3d< T > const &  p 
)

Return the point on the given line which is closest to the given point.

If the given point is at infinity, the point at infinity of the line is returned.

Definition at line 372 of file vgl_closest_point.txx.

template<class T >
vgl_homg_point_3d<T> vgl_closest_point ( vgl_homg_point_3d< T > const &  p,
vgl_homg_line_3d_2_points< T > const &  l 
) [inline]

Definition at line 205 of file vgl_closest_point.h.

template<class T >
vgl_point_3d< T > vgl_closest_point ( vgl_line_3d_2_points< T > const &  l,
vgl_point_3d< T > const &  p 
)

Return the point on the given line which is closest to the given point.

Definition at line 407 of file vgl_closest_point.txx.

template<class T >
vgl_point_3d<T> vgl_closest_point ( vgl_point_3d< T > const &  p,
vgl_line_3d_2_points< T > const &  l 
) [inline]

Definition at line 217 of file vgl_closest_point.h.

template<class T >
vgl_point_3d<T> vgl_closest_point ( vgl_point_3d< T > const &  p,
vgl_infinite_line_3d< T > const &  l 
) [inline]

Definition at line 222 of file vgl_closest_point.h.

template<class T >
vgl_point_3d<T> vgl_closest_point ( vgl_infinite_line_3d< T > const &  l,
vgl_point_3d< T > const &  p 
) [inline]

Definition at line 228 of file vgl_closest_point.h.

template<class T >
vgl_point_3d<T> vgl_closest_point ( vgl_point_3d< T > const &  p,
vgl_ray_3d< T > const &  r 
)

Definition at line 473 of file vgl_closest_point.txx.

template<class T >
vgl_point_3d<T> vgl_closest_point ( vgl_ray_3d< T > const &  r,
vgl_point_3d< T > const &  p 
) [inline]

Definition at line 237 of file vgl_closest_point.h.

template<class T >
vgl_point_2d< T > vgl_closest_point ( vgl_line_segment_2d< T > const &  l,
vgl_point_2d< T > const &  p 
)

Return the closest point on a line segment l to a point p in 2D.

See also:
vgl_distance_to_linesegment()

Definition at line 602 of file vgl_closest_point.txx.

template<class T >
vgl_point_2d<T> vgl_closest_point ( vgl_point_2d< T > const &  p,
vgl_line_segment_2d< T > const &  l 
) [inline]

Definition at line 309 of file vgl_closest_point.h.

template<class T >
vgl_point_3d< T > vgl_closest_point ( vgl_line_segment_3d< T > const &  l,
vgl_point_3d< T > const &  p 
)

Return the closest point on a line segment l to a point p in 3D.

See also:
vgl_distance_to_linesegment()

Definition at line 614 of file vgl_closest_point.txx.

template<class T >
vgl_point_3d<T> vgl_closest_point ( vgl_point_3d< T > const &  p,
vgl_line_segment_3d< T > const &  l 
) [inline]

Definition at line 320 of file vgl_closest_point.h.

template<class T >
vgl_point_2d< T > vgl_closest_point_origin ( vgl_line_2d< T > const &  l)

Return the point on the given line closest to the origin.

Definition at line 188 of file vgl_closest_point.txx.

template<class T >
vgl_homg_point_2d< T > vgl_closest_point_origin ( vgl_homg_line_2d< T > const &  l)

Return the point on the given line closest to the origin.

Definition at line 195 of file vgl_closest_point.txx.

template<class T >
vgl_point_3d< T > vgl_closest_point_origin ( vgl_plane_3d< T > const &  pl)

Return the point on the given plane closest to the origin.

Definition at line 202 of file vgl_closest_point.txx.

template<class T >
vgl_homg_point_3d< T > vgl_closest_point_origin ( vgl_homg_plane_3d< T > const &  pl)

Return the point on the given plane closest to the origin.

Definition at line 209 of file vgl_closest_point.txx.

template<class T >
vgl_point_3d< T > vgl_closest_point_origin ( vgl_line_3d_2_points< T > const &  l)

Return the point on the given line closest to the origin.

Definition at line 230 of file vgl_closest_point.txx.

template<class T >
vgl_homg_point_3d< T > vgl_closest_point_origin ( vgl_homg_line_3d_2_points< T > const &  l)

Return the point on the given line closest to the origin.

Definition at line 216 of file vgl_closest_point.txx.

template<class T >
double vgl_closest_point_t ( vgl_line_3d_2_points< T > const &  l,
vgl_point_3d< T > const &  p 
)

Return the point on the given line which is closest to the given point.

The closest point is expressed in parametric form.

See also:
vgl_line_3d_2_points::point_t()
vgl_closest_point(vgl_line_3d_2_points<T> const&, vgl_point_3d<T> const&)

Definition at line 390 of file vgl_closest_point.txx.

template<class T >
double vgl_closest_point_t ( vgl_point_3d< T > const &  p,
vgl_line_3d_2_points< T > const &  l 
) [inline]

Definition at line 251 of file vgl_closest_point.h.

template<class T >
int vgl_closest_point_to_closed_polygon ( T &  ret_x,
T &  ret_y,
T const  px[],
T const  py[],
unsigned int  n,
x,
y 
)

Closest point to (x,y) on closed polygon (px[i],py[i]).

Also returns the index of the polygon line segment where this point lies.

Definition at line 146 of file vgl_closest_point.txx.

template<class T >
int vgl_closest_point_to_closed_polygon ( T &  ret_x,
T &  ret_y,
T &  ret_z,
T const  px[],
T const  py[],
T const  pz[],
unsigned int  n,
x,
y,
z 
)

Closest point to (x,y,z) on closed polygon (px[i],py[i],pz[i]).

Also returns the index of the polygon line segment where this point lies.

Definition at line 166 of file vgl_closest_point.txx.

template<class T >
void vgl_closest_point_to_linesegment ( T &  ret_x,
T &  ret_y,
x1,
y1,
x2,
y2,
x,
y 
)

Closest point to (x,y) on the line segment (x1,y1)-(x2,y2).

Definition at line 54 of file vgl_closest_point.txx.

template<class T >
void vgl_closest_point_to_linesegment ( T &  ret_x,
T &  ret_y,
T &  ret_z,
x1,
y1,
z1,
x2,
y2,
z2,
x,
y,
z 
)

Closest point to (x,y,z) on the line segment (x1,y1,z1)-(x2,y2,z2).

Definition at line 83 of file vgl_closest_point.txx.

template<class T >
int vgl_closest_point_to_non_closed_polygon ( T &  ret_x,
T &  ret_y,
T const  px[],
T const  py[],
unsigned int  n,
x,
y 
)

Closest point to (x,y) on open polygon (px[i],py[i]).

Also returns the index of the polygon line segment where this point lies.

Definition at line 111 of file vgl_closest_point.txx.

template<class T >
int vgl_closest_point_to_non_closed_polygon ( T &  ret_x,
T &  ret_y,
T &  ret_z,
T const  px[],
T const  py[],
T const  pz[],
unsigned int  n,
x,
y,
z 
)

Closest point to (x,y,z) on open polygon (px[i],py[i],pz[i]).

Also returns the index of the polygon line segment where this point lies.

Definition at line 128 of file vgl_closest_point.txx.

template<class T >
vcl_pair< vgl_homg_point_3d< T >, vgl_homg_point_3d< T > > vgl_closest_points ( vgl_homg_line_3d_2_points< T > const &  line1,
vgl_homg_line_3d_2_points< T > const &  line2 
)

Return the two points of nearest approach of two 3D lines, one on each line.

There are 3 cases: the lines intersect (hence these two points are equal); the lines are parallel (an infinite number of solutions viz all points); the lines are neither parallel nor do they intersect (the general case). This method handles all 3 cases. In all cases, a pair of points is returned; in case 1, the two returned points are equal; in case 2, both points are the common point at infinity of the two lines.

Note that case 2 also comprises the case where the given lines are identical. Hence, when observing a point at infinity as a return value, one should interpret this as "all points are closest points".

Parameters:
line1
line2
Returns:
vcl_pair<vgl_homg_point_3d<T>,vgl_homg_point_3d<T> >
Author:
Paul Bourke, modified for use in VXL by Brendan McCane
Note:
This routine is adapted from code written by Paul Bourke and available online at http://astronomy.swin.edu.au/~pbourke/geometry/lineline3d/

Definition at line 321 of file vgl_closest_point.txx.

template<class T >
vcl_pair< vgl_point_3d< T >, vgl_point_3d< T > > vgl_closest_points ( const vgl_line_3d_2_points< T > &  l1,
const vgl_line_3d_2_points< T > &  l2,
bool *  unique = 0 
)

Return the points of closest approach on 2 3D lines.

Uses non-homogeneous representations.

Returns:
The pair of closest points, the first on l1, the second on l2.
Return values:
uniqueIf provided, will be set to true if the returned points are unique, otherwise many solutions exist and the returned points are an arbitrary choice. The distance between the points is still valid, however.

Definition at line 425 of file vgl_closest_point.txx.

template<class T >
vcl_pair< vgl_point_3d< T >, vgl_point_3d< T > > vgl_closest_points ( const vgl_infinite_line_3d< T > &  l1,
const vgl_infinite_line_3d< T > &  l2,
bool *  unique = 0 
)

Return the points of closest approach on two infinite 3D lines.

Uses non-homogeneous representations.

Returns:
The pair of closest points, the first on l1, the second on l2.
Return values:
uniqueIf provided, will be set to true if the returned points are unique, otherwise many solutions exist and the returned points are an arbitrary choice. The distance between the points is still valid, however.

Definition at line 279 of file vgl_closest_point.h.

template<class T >
vcl_pair< vgl_point_3d< T >, vgl_point_3d< T > > vgl_closest_points ( const vgl_line_segment_3d< T > &  l1,
const vgl_line_segment_3d< T > &  l2,
bool *  unique = 0 
)

Return the points of closest approach on 2 3D line segments.

Uses non-homogeneous representations.

Returns:
The pair of closest points, the first on l1, the second on l2.
Return values:
uniqueIf provided, will be set to true if the returned points are unique, otherwise many solutions exist and the returned points are an arbitrary choice. The distance between the points is still valid, however.

Definition at line 483 of file vgl_closest_point.txx.