Code-Eli  0.3.6
minimum_distance_bounding_box.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef eli_geom_intersect_minimum_distance_bounding_box_hpp
14 #define eli_geom_intersect_minimum_distance_bounding_box_hpp
15 
16 #include "eli/code_eli.hpp"
17 
20 
21 
22 namespace eli
23 {
24  namespace geom
25  {
26  namespace intersect
27  {
28  template<typename data__, unsigned short dim__, typename tol__>
31  {
32  data__ dist2(0), len;
34  bool below_min, above_max;
35 
36  // for each dimension that is outside corresponding min/max add that to distance
37  for (i=0; i<dim__; ++i)
38  {
39  below_min=pt(0, i) < bb.get_min()(0, i);
40  above_max=pt(0, i) > bb.get_max()(0, i);
41 
42  if (below_min)
43  {
44  len=bb.get_min()(0,i)-pt(0,i);
45  }
46  else if (above_max)
47  {
48  len=pt(0,i)-bb.get_max()(0,i);
49  }
50  else
51  {
52  len=0;
53  }
54  dist2+=len*len;
55  }
56 
57  return std::sqrt(dist2);
58  }
59 
60  template<typename data__, unsigned short dim__, typename tol__>
63  {
64  data__ dist2(0), len;
66  bool below_min, above_max;
67 
68  // for each dimension that is outside corresponding min/max add that to distance
69  for (i=0; i<dim__; ++i)
70  {
71  below_min=pt(0, i) < bb.get_min()(0, i);
72  above_max=pt(0, i) > bb.get_max()(0, i);
73 
74  if (below_min)
75  {
76  len=bb.get_max()(0,i)-pt(0,i);
77  }
78  else if (above_max)
79  {
80  len=pt(0,i)-bb.get_min()(0,i);
81  }
82  else
83  {
84  data__ l1, l2;
85  l1 = pt(0,i)-bb.get_min()(0,i);
86  l2 = bb.get_max()(0,i)-pt(0,i);
87 
88  if(l1>=l2)
89  len=l1;
90  else
91  len=l2;
92  }
93  dist2+=len*len;
94  }
95 
96  return std::sqrt(dist2);
97  }
98 
99  template<typename data__, unsigned short dim__, typename tol__>
102  data__ &dmin,
103  data__ &dmax)
104  {
105  data__ maxdist2(0), mindist2(0), minlen, maxlen;
107  bool below_min, above_max;
108 
109  // for each dimension that is outside corresponding min/max add that to distance
110  for (i=0; i<dim__; ++i)
111  {
112  below_min=pt(0, i) < bb.get_min()(0, i);
113  above_max=pt(0, i) > bb.get_max()(0, i);
114 
115  if (below_min)
116  {
117  minlen=bb.get_min()(0,i)-pt(0,i);
118  maxlen=bb.get_max()(0,i)-pt(0,i);
119  }
120  else if (above_max)
121  {
122  minlen=pt(0,i)-bb.get_max()(0,i);
123  maxlen=pt(0,i)-bb.get_min()(0,i);
124  }
125  else
126  {
127  minlen=0;
128 
129  data__ l1, l2;
130  l1 = pt(0,i)-bb.get_min()(0,i);
131  l2 = bb.get_max()(0,i)-pt(0,i);
132 
133  if(l1>=l2)
134  maxlen=l1;
135  else
136  maxlen=l2;
137  }
138  mindist2+=minlen*minlen;
139  maxdist2+=maxlen*maxlen;
140  }
141  dmin=std::sqrt(mindist2);
142  dmax=std::sqrt(maxdist2);
143  }
144 
145  }
146  }
147 }
148 #endif
Definition: math.hpp:20
curve::piecewise< curve1__, data1__, dim1__, tol1__ >::data_type minimum_distance(typename curve::piecewise< curve1__, data1__, dim1__, tol1__ >::data_type &t, const curve::piecewise< curve1__, data1__, dim1__, tol1__ > &pc, const typename curve::piecewise< curve1__, data1__, dim1__, tol1__ >::point_type &pt)
point_type::Index index_type
Definition: bounding_box.hpp:33
Definition: bounding_box.hpp:27
Eigen::Matrix< data_type, 1, dim__ > point_type
Definition: bounding_box.hpp:32
point_type get_max() const
Definition: bounding_box.hpp:104
data__ maximum_distance(const eli::geom::general::bounding_box< data__, dim__, tol__ > &bb, const typename eli::geom::general::bounding_box< data__, dim__, tol__ >::point_type &pt)
Definition: minimum_distance_bounding_box.hpp:61
point_type get_min() const
Definition: bounding_box.hpp:93
void minmax_distance(const eli::geom::general::bounding_box< data__, dim__, tol__ > &bb, const typename eli::geom::general::bounding_box< data__, dim__, tol__ >::point_type &pt, data__ &dmin, data__ &dmax)
Definition: minimum_distance_bounding_box.hpp:100