Defines | Functions | Variables
core/vgl/vgl_closest_point.txx File Reference
#include "vgl_closest_point.h"
#include <vgl/vgl_distance.h>
#include <vgl/vgl_line_2d.h>
#include <vgl/vgl_homg_line_2d.h>
#include <vgl/vgl_point_2d.h>
#include <vgl/vgl_point_3d.h>
#include <vgl/vgl_homg_point_2d.h>
#include <vgl/vgl_homg_point_3d.h>
#include <vgl/vgl_plane_3d.h>
#include <vgl/vgl_homg_plane_3d.h>
#include <vgl/vgl_homg_line_3d_2_points.h>
#include <vgl/vgl_line_3d_2_points.h>
#include <vgl/vgl_line_segment_2d.h>
#include <vgl/vgl_line_segment_3d.h>
#include <vgl/vgl_polygon.h>
#include <vgl/vgl_ray_3d.h>
#include <vcl_cassert.h>
#include <vcl_cmath.h>

Go to the source code of this file.

Defines

#define vgl_closest_point_txx_
#define DIST_SQR_TO_LINE_SEG_2D(T, x1, y1, x2, y2, x, y)   vgl_distance2_to_linesegment(x1, y1, x2, y2, x, y );
#define DIST_SQR_TO_LINE_SEG_3D(T, x1, y1, z1, x2, y2, z2, x, y, z)   vgl_distance2_to_linesegment(x1, y1, z1, x2, y2, z2, x, y, z );
#define VGL_CLOSEST_POINT_INSTANTIATE(T)

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 x0, T y0)
 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_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_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_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_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_point_3d< T > vgl_closest_point (vgl_plane_3d< T > const &l, vgl_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_plane_3d< T > const &l, vgl_homg_point_3d< T > const &p)
 Return the point on the given plane closest to the given point.
template<class T >
vgl_point_2d< T > vgl_closest_point (vgl_polygon< T > const &poly, vgl_point_2d< T > const &point, bool closed)
 Return the point on the given polygon closest to the given point.
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 >
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 >
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 >
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)
 Return the points of closest approach on 2 3D lines.
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 >
vcl_pair< vgl_point_3d< T >
, vgl_point_3d< T > > 
vgl_closest_points (vgl_line_segment_3d< T > const &l1, vgl_line_segment_3d< T > const &l2, bool *unique)
 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_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.

Variables

const double SMALL_DOUBLE = 1e-12

Detailed Description

Author:
Peter Vanroose, KULeuven, ESAT/PSI

Definition in file vgl_closest_point.txx.


Define Documentation

#define DIST_SQR_TO_LINE_SEG_2D (   T,
  x1,
  y1,
  x2,
  y2,
  x,
 
)    vgl_distance2_to_linesegment(x1, y1, x2, y2, x, y );

Definition at line 46 of file vgl_closest_point.txx.

#define DIST_SQR_TO_LINE_SEG_3D (   T,
  x1,
  y1,
  z1,
  x2,
  y2,
  z2,
  x,
  y,
 
)    vgl_distance2_to_linesegment(x1, y1, z1, x2, y2, z2, x, y, z );

Definition at line 48 of file vgl_closest_point.txx.

#define VGL_CLOSEST_POINT_INSTANTIATE (   T)

Definition at line 629 of file vgl_closest_point.txx.

#define vgl_closest_point_txx_

Definition at line 3 of file vgl_closest_point.txx.


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_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_point_3d<T> vgl_closest_point ( vgl_plane_3d< T > const &  l,
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_homg_point_3d<T> vgl_closest_point ( vgl_homg_plane_3d< T > const &  l,
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_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_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_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_ray_3d< T > const &  r 
)

Definition at line 473 of file vgl_closest_point.txx.

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_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_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_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 >
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 >
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 >
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,
x0,
y0 
)

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_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.


Variable Documentation

const double SMALL_DOUBLE = 1e-12

Definition at line 32 of file vgl_closest_point.txx.