core/vgl/vgl_distance.h
Go to the documentation of this file.
00001 // This is core/vgl/vgl_distance.h
00002 #ifndef vgl_distance_h_
00003 #define vgl_distance_h_
00004 //:
00005 // \file
00006 // \brief Set of distance functions
00007 // \author fsm
00008 //
00009 // Note that these functions return double, not the template parameter Type,
00010 // since e.g. the distance between two vgl_point_2d<int> is not always an int,
00011 // but even the squared distance between such a point and a line is not integer.
00012 //
00013 // \verbatim
00014 //  Modifications
00015 //    2 July 2001 Peter Vanroose added vgl_distance(point,line) and (point,plane)
00016 //    2 July 2001 Peter Vanroose inlined 4 functions and made return types double
00017 //    2 Jan. 2003 Peter Vanroose corrected functions returning negative distance
00018 //    5 June 2003 Peter Vanroose added vgl_distance(line_3d,line_3d)
00019 //   11 June 2003 Peter Vanroose added vgl_distance(line_3d,point_3d)
00020 //   14 Nov. 2003 Peter Vanroose made all functions templated
00021 //   25 Sept 2004 Peter Vanroose added 3D vgl_distance_to_linesegment()
00022 //   25 Sept 2004 Peter Vanroose added 3D vgl_distance_to_*_polygon()
00023 // \endverbatim
00024 
00025 #include <vgl/vgl_fwd.h> // forward declare various vgl classes
00026 
00027 //: Squared distance between point \a (x,y) and closest point on line segment \a (x1,y1)-(x2,y2)
00028 template <class T>
00029 double vgl_distance2_to_linesegment(T x1, T y1,
00030                                     T x2, T y2,
00031                                     T x, T y);
00032 
00033 //: Distance between point \a (x,y) and closest point on line segment \a (x1,y1)-(x2,y2)
00034 template <class T>
00035 double vgl_distance_to_linesegment(T x1, T y1,
00036                                    T x2, T y2,
00037                                    T x, T y);
00038 
00039 //: Squared distance between point \a (x,y,z) and closest point on line segment \a (x1,y1,z1)-(x2,y2,z2)
00040 template <class T>
00041 double vgl_distance2_to_linesegment(T x1, T y1, T z1,
00042                                     T x2, T y2, T z2,
00043                                     T x,  T y,  T z);
00044 
00045 //: Distance between point \a (x,y,z) and closest point on line segment \a (x1,y1,z1)-(x2,y2,z2)
00046 template <class T>
00047 double vgl_distance_to_linesegment(T x1, T y1, T z1,
00048                                    T x2, T y2, T z2,
00049                                    T x,  T y,  T z);
00050 
00051 //: Distance between point \a (x,y) and closest point on open polygon \a (px[i],py[i])
00052 template <class T>
00053 double vgl_distance_to_non_closed_polygon(T const px[], T const py[], unsigned int n,
00054                                           T x, T y);
00055 
00056 //: Distance between point \a (x,y,z) and closest point on open polygon \a (px[i],py[i],pz[i])
00057 template <class T>
00058 double vgl_distance_to_non_closed_polygon(T const px[], T const py[], T const pz[], unsigned int n,
00059                                           T x, T y, T z);
00060 
00061 //: Distance between point \a (x,y) and closest point on closed polygon \a (px[i],py[i])
00062 template <class T>
00063 double vgl_distance_to_closed_polygon(T const px[], T const py[], unsigned int n,
00064                                       T x, T y);
00065 
00066 //: Distance between point \a (x,y,z) and closest point on closed polygon \a (px[i],py[i]),pz[i]
00067 template <class T>
00068 double vgl_distance_to_closed_polygon(T const px[], T const py[], T const pz[], unsigned int n,
00069                                       T x, T y, T z);
00070 
00071 //: find the shortest distance of the line to the origin
00072 // \relatesalso vgl_line_2d
00073 template <class T>
00074 double vgl_distance_origin(vgl_line_2d<T> const& l);
00075 
00076 //: find the shortest distance of the plane to the origin
00077 // \relatesalso vgl_plane_3d
00078 template <class T>
00079 double vgl_distance_origin(vgl_plane_3d<T> const& pl);
00080 
00081 //: find the shortest distance of the line to the origin
00082 // \relatesalso vgl_line_3d_2_points
00083 template <class T>
00084 double vgl_distance_origin(vgl_line_3d_2_points<T> const& l);
00085 
00086 //: find the shortest distance of the line to the origin
00087 // \relatesalso vgl_homg_line_2d
00088 template <class T>
00089 double vgl_distance_origin(vgl_homg_line_2d<T> const& l);
00090 
00091 //: find the shortest distance of the plane to the origin
00092 // \relatesalso vgl_homg_plane_3d
00093 template <class T>
00094 double vgl_distance_origin(vgl_homg_plane_3d<T> const& pl);
00095 
00096 //: find the shortest distance of the line to the origin
00097 // \relatesalso vgl_homg_line_3d_2_points
00098 template <class T>
00099 double vgl_distance_origin(vgl_homg_line_3d_2_points<T> const& l);
00100 
00101 //: return the distance between two points
00102 // \relatesalso vgl_point_2d
00103 template <class T> inline
00104 double vgl_distance(vgl_point_2d<T>const& p1,
00105                     vgl_point_2d<T>const& p2) { return length(p2-p1); }
00106 
00107 //: return the distance between two points
00108 // \relatesalso vgl_point_3d
00109 template <class T> inline
00110 double vgl_distance(vgl_point_3d<T>const& p1,
00111                     vgl_point_3d<T>const& p2) { return length(p2-p1); }
00112 
00113 //: return the distance between two points
00114 // \relatesalso vgl_homg_point_1d
00115 template <class T>
00116 double vgl_distance(vgl_homg_point_1d<T>const& p1,
00117                     vgl_homg_point_1d<T>const& p2);
00118 
00119 //: return the distance between two points
00120 // \relatesalso vgl_homg_point_2d
00121 template <class T> inline
00122 double vgl_distance(vgl_homg_point_2d<T>const& p1,
00123                     vgl_homg_point_2d<T>const& p2) { return length(p2-p1); }
00124 
00125 //: return the distance between two points
00126 // \relatesalso vgl_homg_point_3d
00127 template <class T> inline
00128 double vgl_distance(vgl_homg_point_3d<T>const& p1,
00129                     vgl_homg_point_3d<T>const& p2) { return length(p2-p1); }
00130 
00131 //: return the perpendicular distance from a point to a line in 2D
00132 // \relatesalso vgl_point_2d
00133 // \relatesalso vgl_line_2d
00134 template <class T>
00135 double vgl_distance(vgl_line_2d<T> const& l,
00136                     vgl_point_2d<T> const& p);
00137 template <class T> inline
00138 double vgl_distance(vgl_point_2d<T> const& p,
00139                     vgl_line_2d<T> const& l) { return vgl_distance(l,p); }
00140 
00141 //: return the perpendicular distance from a point to a line in 2D
00142 // \relatesalso vgl_homg_point_2d
00143 // \relatesalso vgl_homg_line_2d
00144 template <class T>
00145 double vgl_distance(vgl_homg_line_2d<T> const& l,
00146                     vgl_homg_point_2d<T> const& p);
00147 template <class T> inline
00148 double vgl_distance(vgl_homg_point_2d<T> const& p,
00149                     vgl_homg_line_2d<T> const& l) { return vgl_distance(l,p); }
00150 
00151 //: return the perpendicular distance from a point to a plane in 3D
00152 // \relatesalso vgl_point_3d
00153 // \relatesalso vgl_plane_3d
00154 template <class T>
00155 double vgl_distance(vgl_plane_3d<T> const& l,
00156                     vgl_point_3d<T> const& p);
00157 template <class T> inline
00158 double vgl_distance(vgl_point_3d<T> const& p,
00159                     vgl_plane_3d<T> const& l) { return vgl_distance(l,p); }
00160 
00161 //: return the perpendicular distance from a point to a plane in 3D
00162 // \relatesalso vgl_homg_point_3d
00163 // \relatesalso vgl_homg_plane_3d
00164 template <class T>
00165 double vgl_distance(vgl_homg_plane_3d<T> const& l,
00166                     vgl_homg_point_3d<T> const& p);
00167 template <class T> inline
00168 double vgl_distance(vgl_homg_point_3d<T> const& p,
00169                     vgl_homg_plane_3d<T> const& l) { return vgl_distance(l,p); }
00170 
00171 //: distance between a point and the closest point on the polygon.
00172 //  If the third argument is "false", the edge from last to first point of
00173 //  each polygon sheet is not considered part of the polygon.
00174 // \relatesalso vgl_point_2d
00175 // \relatesalso vgl_polygon
00176 template <class T>
00177 double vgl_distance(vgl_polygon<T> const& poly,
00178                     vgl_point_2d<T> const& point,
00179                     bool closed=true);
00180 
00181 template <class T> inline
00182 double vgl_distance(vgl_point_2d<T> const& point,
00183                     vgl_polygon<T> const& poly,
00184                     bool closed=true) { return vgl_distance(poly,point,closed); }
00185 
00186 //: Return the perpendicular distance between two lines in 3D.
00187 //  See vgl_closest_point.h for more information.
00188 // \relatesalso vgl_homg_line_3d_2_points
00189 
00190 template <class T>
00191 double vgl_distance(vgl_homg_line_3d_2_points<T> const& line1,
00192                     vgl_homg_line_3d_2_points<T> const& line2);
00193 
00194 //: Return the perpendicular distance from a point to a line in 3D.
00195 //  See vgl_closest_point.h for more information.
00196 // \relatesalso vgl_homg_line_3d_2_points
00197 template <class T>
00198 double vgl_distance(vgl_homg_line_3d_2_points<T> const& l,
00199                     vgl_homg_point_3d<T> const& p);
00200 
00201 template <class T> inline
00202 double vgl_distance(vgl_homg_point_3d<T> const& p,
00203                     vgl_homg_line_3d_2_points<T> const& l) { return vgl_distance(l,p); }
00204 
00205 //: Return the perpendicular distance from a point to a line in 3D.
00206 //  See vgl_closest_point.h for more information.
00207 // \relatesalso vgl_line_3d_2_points
00208 template <class T>
00209 double vgl_distance(vgl_line_3d_2_points<T> const& l,
00210                     vgl_point_3d<T> const& p);
00211 
00212 template <class T> inline
00213 double vgl_distance(vgl_point_3d<T> const& p,
00214                     vgl_line_3d_2_points<T> const& l) { return vgl_distance(l,p); }
00215 
00216 //: return the closest distance from a point to a ray
00217 template <class T>
00218 double vgl_distance(vgl_ray_3d<T> const& r,
00219                     vgl_point_3d<T> const& p);
00220 
00221 template <class T> inline
00222 double vgl_distance(vgl_point_3d<T> const& p,
00223                     vgl_ray_3d<T> const& r) { return vgl_distance(r,p); }
00224 
00225 //: Closest distance from a point \a p to a line segment \a l in 2D
00226 // \relatesalso vgl_point_2d
00227 // \relatesalso vgl_line_segment_2d
00228 // \sa vgl_distance_to_linesegment()
00229 // \sa vgl_distance2_to_linesegment()
00230 template <class T>
00231 double vgl_distance(vgl_line_segment_2d<T> const& l,
00232                     vgl_point_2d<T> const& p);
00233 template <class T> inline
00234 double vgl_distance(vgl_point_2d<T> const& p,
00235                     vgl_line_segment_2d<T> const& l) { return vgl_distance(l,p); }
00236 
00237 
00238 //: Closest distance from a point \a p to a line segment \a l in 3D
00239 // \relatesalso vgl_point_3d
00240 // \relatesalso vgl_line_segment_3d
00241 // \sa vgl_distance_to_linesegment()
00242 // \sa vgl_distance2_to_linesegment()
00243 template <class T>
00244 double vgl_distance(vgl_line_segment_3d<T> const& l,
00245                     vgl_point_3d<T> const& p);
00246 template <class T> inline
00247 double vgl_distance(vgl_point_3d<T> const& p,
00248                     vgl_line_segment_3d<T> const& l) { return vgl_distance(l,p); }
00249 
00250 
00251 #endif // vgl_distance_h_