vgl_distance.h
Go to the documentation of this file.
1 // This is core/vgl/vgl_distance.h
2 #ifndef vgl_distance_h_
3 #define vgl_distance_h_
4 //:
5 // \file
6 // \brief Set of distance functions
7 // \author fsm
8 //
9 // Note that these functions return double, not the template parameter Type,
10 // since e.g. the distance between two vgl_point_2d<int> is not always an int,
11 // but even the squared distance between such a point and a line is not integer.
12 //
13 // \verbatim
14 // Modifications
15 // 2 July 2001 Peter Vanroose added vgl_distance(point,line) and (point,plane)
16 // 2 July 2001 Peter Vanroose inlined 4 functions and made return types double
17 // 2 Jan. 2003 Peter Vanroose corrected functions returning negative distance
18 // 5 June 2003 Peter Vanroose added vgl_distance(line_3d,line_3d)
19 // 11 June 2003 Peter Vanroose added vgl_distance(line_3d,point_3d)
20 // 14 Nov. 2003 Peter Vanroose made all functions templated
21 // 25 Sept 2004 Peter Vanroose added 3D vgl_distance_to_linesegment()
22 // 25 Sept 2004 Peter Vanroose added 3D vgl_distance_to_*_polygon()
23 // \endverbatim
24 
25 #include <vgl/vgl_fwd.h> // forward declare various vgl classes
26 
27 //: Squared distance between point \a (x,y) and closest point on line segment \a (x1,y1)-(x2,y2)
28 template <class T>
29 double vgl_distance2_to_linesegment(T x1, T y1,
30  T x2, T y2,
31  T x, T y);
32 
33 //: Distance between point \a (x,y) and closest point on line segment \a (x1,y1)-(x2,y2)
34 template <class T>
35 double vgl_distance_to_linesegment(T x1, T y1,
36  T x2, T y2,
37  T x, T y);
38 
39 //: Squared distance between point \a (x,y,z) and closest point on line segment \a (x1,y1,z1)-(x2,y2,z2)
40 template <class T>
41 double vgl_distance2_to_linesegment(T x1, T y1, T z1,
42  T x2, T y2, T z2,
43  T x, T y, T z);
44 
45 //: Distance between point \a (x,y,z) and closest point on line segment \a (x1,y1,z1)-(x2,y2,z2)
46 template <class T>
47 double vgl_distance_to_linesegment(T x1, T y1, T z1,
48  T x2, T y2, T z2,
49  T x, T y, T z);
50 
51 //: Distance between point \a (x,y) and closest point on open polygon \a (px[i],py[i])
52 template <class T>
53 double vgl_distance_to_non_closed_polygon(T const px[], T const py[], unsigned int n,
54  T x, T y);
55 
56 //: Distance between point \a (x,y,z) and closest point on open polygon \a (px[i],py[i],pz[i])
57 template <class T>
58 double vgl_distance_to_non_closed_polygon(T const px[], T const py[], T const pz[], unsigned int n,
59  T x, T y, T z);
60 
61 //: Distance between point \a (x,y) and closest point on closed polygon \a (px[i],py[i])
62 template <class T>
63 double vgl_distance_to_closed_polygon(T const px[], T const py[], unsigned int n,
64  T x, T y);
65 
66 //: Distance between point \a (x,y,z) and closest point on closed polygon \a (px[i],py[i]),pz[i]
67 template <class T>
68 double vgl_distance_to_closed_polygon(T const px[], T const py[], T const pz[], unsigned int n,
69  T x, T y, T z);
70 
71 //: find the shortest distance of the line to the origin
72 // \relatesalso vgl_line_2d
73 template <class T>
74 double vgl_distance_origin(vgl_line_2d<T> const& l);
75 
76 //: find the shortest distance of the plane to the origin
77 // \relatesalso vgl_plane_3d
78 template <class T>
79 double vgl_distance_origin(vgl_plane_3d<T> const& pl);
80 
81 //: find the shortest distance of the line to the origin
82 // \relatesalso vgl_line_3d_2_points
83 template <class T>
85 
86 //: find the shortest distance of the line to the origin
87 // \relatesalso vgl_homg_line_2d
88 template <class T>
90 
91 //: find the shortest distance of the plane to the origin
92 // \relatesalso vgl_homg_plane_3d
93 template <class T>
95 
96 //: find the shortest distance of the line to the origin
97 // \relatesalso vgl_homg_line_3d_2_points
98 template <class T>
100 
101 //: return the distance between two points
102 // \relatesalso vgl_point_2d
103 template <class T> inline
105  vgl_point_2d<T>const& p2) { return length(p2-p1); }
106 
107 //: return the distance between two points
108 // \relatesalso vgl_point_3d
109 template <class T> inline
111  vgl_point_3d<T>const& p2) { return length(p2-p1); }
112 
113 //: return the distance between two points
114 // \relatesalso vgl_homg_point_1d
115 template <class T>
116 double vgl_distance(vgl_homg_point_1d<T>const& p1,
117  vgl_homg_point_1d<T>const& p2);
118 
119 //: return the distance between two points
120 // \relatesalso vgl_homg_point_2d
121 template <class T> inline
123  vgl_homg_point_2d<T>const& p2) { return length(p2-p1); }
124 
125 //: return the distance between two points
126 // \relatesalso vgl_homg_point_3d
127 template <class T> inline
129  vgl_homg_point_3d<T>const& p2) { return length(p2-p1); }
130 
131 //: return the perpendicular distance from a point to a line in 2D
132 // \relatesalso vgl_point_2d
133 // \relatesalso vgl_line_2d
134 template <class T>
135 double vgl_distance(vgl_line_2d<T> const& l,
136  vgl_point_2d<T> const& p);
137 template <class T> inline
139  vgl_line_2d<T> const& l) { return vgl_distance(l,p); }
140 
141 //: return the perpendicular distance from a point to a line in 2D
142 // \relatesalso vgl_homg_point_2d
143 // \relatesalso vgl_homg_line_2d
144 template <class T>
145 double vgl_distance(vgl_homg_line_2d<T> const& l,
146  vgl_homg_point_2d<T> const& p);
147 template <class T> inline
149  vgl_homg_line_2d<T> const& l) { return vgl_distance(l,p); }
150 
151 //: return the perpendicular distance from a point to a plane in 3D
152 // \relatesalso vgl_point_3d
153 // \relatesalso vgl_plane_3d
154 template <class T>
155 double vgl_distance(vgl_plane_3d<T> const& l,
156  vgl_point_3d<T> const& p);
157 template <class T> inline
159  vgl_plane_3d<T> const& l) { return vgl_distance(l,p); }
160 
161 //: return the perpendicular distance from a point to a plane in 3D
162 // \relatesalso vgl_homg_point_3d
163 // \relatesalso vgl_homg_plane_3d
164 template <class T>
165 double vgl_distance(vgl_homg_plane_3d<T> const& l,
166  vgl_homg_point_3d<T> const& p);
167 template <class T> inline
169  vgl_homg_plane_3d<T> const& l) { return vgl_distance(l,p); }
170 
171 template <class T>
172 double vgl_distance(vgl_point_3d<T> const& p,
173  vgl_sphere_3d<T> const& s);
174 //: distance between a point and the closest point on the polygon.
175 // If the third argument is "false", the edge from last to first point of
176 // each polygon sheet is not considered part of the polygon.
177 // \relatesalso vgl_point_2d
178 // \relatesalso vgl_polygon
179 template <class T>
180 double vgl_distance(vgl_polygon<T> const& poly,
181  vgl_point_2d<T> const& point,
182  bool closed=true);
183 
184 template <class T> inline
185 double vgl_distance(vgl_point_2d<T> const& point,
186  vgl_polygon<T> const& poly,
187  bool closed=true) { return vgl_distance(poly,point,closed); }
188 
189 //: Return the perpendicular distance between two lines in 3D.
190 // See vgl_closest_point.h for more information.
191 // \relatesalso vgl_homg_line_3d_2_points
192 
193 template <class T>
194 double vgl_distance(vgl_homg_line_3d_2_points<T> const& line1,
195  vgl_homg_line_3d_2_points<T> const& line2);
196 
197 //: Return the perpendicular distance from a point to a line in 3D.
198 // See vgl_closest_point.h for more information.
199 // \relatesalso vgl_homg_line_3d_2_points
200 template <class T>
202  vgl_homg_point_3d<T> const& p);
203 
204 template <class T> inline
206  vgl_homg_line_3d_2_points<T> const& l) { return vgl_distance(l,p); }
207 
208 //: Return the perpendicular distance from a point to a line in 3D.
209 // See vgl_closest_point.h for more information.
210 // \relatesalso vgl_line_3d_2_points
211 template <class T>
213  vgl_point_3d<T> const& p);
214 
215 template <class T> inline
217  vgl_line_3d_2_points<T> const& l) { return vgl_distance(l,p); }
218 
219 //: return the closest distance from a point to a ray
220 template <class T>
221 double vgl_distance(vgl_ray_3d<T> const& r,
222  vgl_point_3d<T> const& p);
223 
224 template <class T> inline
226  vgl_ray_3d<T> const& r) { return vgl_distance(r,p); }
227 
228 //: return the closest distance from a point to an infinite line
229 template <class T>
231  vgl_point_3d<T> const& p);
232 
233 template <class T> inline
235  vgl_infinite_line_3d<T> const& l) { return vgl_distance(l,p); }
236 //: Closest distance from a point \a p to a line segment \a l in 2D
237 // \relatesalso vgl_point_2d
238 // \relatesalso vgl_line_segment_2d
239 // \sa vgl_distance_to_linesegment()
240 // \sa vgl_distance2_to_linesegment()
241 template <class T>
243  vgl_point_2d<T> const& p);
244 template <class T> inline
246  vgl_line_segment_2d<T> const& l) { return vgl_distance(l,p); }
247 
248 
249 //: Closest distance from a point \a p to a line segment \a l in 3D
250 // \relatesalso vgl_point_3d
251 // \relatesalso vgl_line_segment_3d
252 // \sa vgl_distance_to_linesegment()
253 // \sa vgl_distance2_to_linesegment()
254 template <class T>
256  vgl_point_3d<T> const& p);
257 template <class T> inline
259  vgl_line_segment_3d<T> const& l) { return vgl_distance(l,p); }
260 
261 //: closest distance from a point to a box (2d)
262 template <class T>
263 double vgl_distance(vgl_point_2d<T> const& p, vgl_box_2d<T> const& b);
264 template <class T>
265 double vgl_distance(vgl_box_2d<T> const& b, vgl_point_2d<T> const& p){return vgl_distance(p,b);}
266 
267 
268 #endif // vgl_distance_h_
Represents a homogeneous 2D line.
Definition: vgl_fwd.h:14
double length(v const &a)
Return the length of a vector.
Definition: vgl_vector_2d.h:94
Represents a homogeneous 3D point.
Definition: vgl_fwd.h:9
double vgl_distance_to_linesegment(T x1, T y1, T x2, T y2, T x, T y)
Distance between point (x,y) and closest point on line segment (x1,y1)-(x2,y2).
A class to hold a non-homogeneous representation of a 3D line.
Definition: vgl_fwd.h:17
double vgl_distance_to_non_closed_polygon(T const px[], T const py[], unsigned int n, T x, T y)
Distance between point (x,y) and closest point on open polygon (px[i],py[i]).
double vgl_distance_origin(vgl_line_2d< T > const &l)
find the shortest distance of the line to the origin.
Represents a Euclidean 3D plane.
Definition: vgl_fwd.h:23
Represents a 3D line segment using two points.
Definition: vgl_fwd.h:19
Represents a 3-d ray.
Definition: vgl_fwd.h:21
double vgl_distance2_to_linesegment(T x1, T y1, T x2, T y2, T x, T y)
Squared distance between point (x,y) and closest point on line segment (x1,y1)-(x2,...
Represents a 3-d line with position defined in the orthogonal plane passing through the origin.
Definition: vgl_fwd.h:20
double vgl_distance(vgl_point_2d< T >const &p1, vgl_point_2d< T >const &p2)
return the distance between two points.
Definition: vgl_distance.h:104
#define l
double vgl_distance_to_closed_polygon(T const px[], T const py[], unsigned int n, T x, T y)
Distance between point (x,y) and closest point on closed polygon (px[i],py[i]).
Represents a homogeneous 1-D point, i.e., a homogeneous pair (x,w).
Definition: vgl_fwd.h:7
Represents a homogeneous 2D point.
Definition: vgl_fwd.h:8
Store a polygon.
Definition: vgl_area.h:6
Represents a homogeneous 3D line using two points.
Definition: vgl_fwd.h:15