Code-Eli  0.3.6
minimum_distance_plane_test_suite.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 minimum_distance_plane_test_suite_hpp
14 #define minimum_distance_plane_test_suite_hpp
15 
16 #include <cmath> // cos(), sin()
17 
18 #include <typeinfo> // typeid
19 
20 #include "eli/util/tolerance.hpp"
21 
23 
24 template<typename data__>
25 class minimum_distance_plane_test_suite : public Test::Suite
26 {
27  private:
28  typedef data__ data_type;
29  typedef Eigen::Matrix<data_type, 1, 3> point_type;
31 
32  tolerance_type tol;
33 
34  protected:
35  void AddTests(const float &)
36  {
37  // add the tests
39  }
40  void AddTests(const double &)
41  {
42  // add the tests
44  }
45  void AddTests(const long double &)
46  {
47  // add the tests
49  }
50 
51  public:
53  {
54  AddTests(data__());
55  }
57  {
58  }
59 
60  private:
62  {
63  point_type a, b, c, pt;
64  data_type dist, u, v, dist_ref, u_ref, v_ref;
65 
66  // xy-plane as plane
67  a << 1, 0, 0;
68  b << 0, 1, 0;
69  c << 0, 0, 0;
70  pt << 2, 4, 2;
71  dist=eli::geom::intersect::minimum_distance(u, v, a, b, c, pt);
72  u_ref=2;
73  v_ref=4;
74  dist_ref=2;
75  TEST_ASSERT(tol.approximately_equal(u, u_ref));
76  TEST_ASSERT(tol.approximately_equal(v, v_ref));
77  TEST_ASSERT(tol.approximately_equal(dist, dist_ref));
78 
79  // xz-plane as plane
80  a << 1, 0, 0;
81  b << 0, 0, 1;
82  c << 0, 0, 0;
83  pt << 2, 4, 2;
84  dist=eli::geom::intersect::minimum_distance(u, v, a, b, c, pt);
85  u_ref=2;
86  v_ref=2;
87  dist_ref=4;
88  TEST_ASSERT(tol.approximately_equal(u, u_ref));
89  TEST_ASSERT(tol.approximately_equal(v, v_ref));
90  TEST_ASSERT(tol.approximately_equal(dist, dist_ref));
91 
92  // yz-plane as plane
93  a << 0, 1, 0;
94  b << 0, 0, 1;
95  c << 0, 0, 0;
96  pt << 2, 4, 2;
97  dist=eli::geom::intersect::minimum_distance(u, v, a, b, c, pt);
98  u_ref=4;
99  v_ref=2;
100  dist_ref=2;
101  TEST_ASSERT(tol.approximately_equal(u, u_ref));
102  TEST_ASSERT(tol.approximately_equal(v, v_ref));
103  TEST_ASSERT(tol.approximately_equal(dist, dist_ref));
104 
105  // plane degenerates as point
106  a << 0, 0, 0;
107  b << 0, 0, 0;
108  c << 0, 0, 0;
109  pt << 2, 4, 2;
110  dist=eli::geom::intersect::minimum_distance(u, v, a, b, c, pt);
111  u_ref=0;
112  v_ref=0;
113  dist_ref=pt.norm();
114  TEST_ASSERT(tol.approximately_equal(u, u_ref));
115  TEST_ASSERT(tol.approximately_equal(v, v_ref));
116  TEST_ASSERT(tol.approximately_equal(dist, dist_ref));
117 
118  // plane degenerates as line
119  a << 1, 2, 1;
120  b << 2, 4, 2;
121  c << 1, 1, 1;
122  pt << 2, 4, 2;
123  dist=eli::geom::intersect::minimum_distance(u, v, a, b, c, pt);
124  v_ref=0;
125  dist_ref=eli::geom::intersect::minimum_distance(u_ref, c, a, pt);
126  TEST_ASSERT(tol.approximately_equal(u, u_ref));
127  TEST_ASSERT(tol.approximately_equal(v, v_ref));
128  TEST_ASSERT(tol.approximately_equal(dist, dist_ref));
129 
130  // general plane at origin intersecting point
131  dist_ref=0;
132  u_ref=0.5;
133  v_ref=1;
134  a << 1, 2,-1;
135  b <<-2, 1, 2;
136  c << 0, 0, 0;
137  pt=u_ref*a+v_ref*b+c;
138  dist=eli::geom::intersect::minimum_distance(u, v, a, b, c, pt);
139  TEST_ASSERT(tol.approximately_equal(u, u_ref));
140  TEST_ASSERT(tol.approximately_equal(v, v_ref));
141  TEST_ASSERT(tol.approximately_equal(dist, dist_ref));
142 
143  // general plane at origin
144  dist_ref=1.5;
145  u_ref=0.5;
146  v_ref=1;
147  a << 1, 2,-1;
148  b <<-2, 1, 2;
149  c << 0, 0, 0;
150  pt=(u_ref*a+v_ref*b+c)+dist_ref*a.cross(b)/a.cross(b).norm();
151  dist=eli::geom::intersect::minimum_distance(u, v, a, b, c, pt);
152  TEST_ASSERT(tol.approximately_equal(u, u_ref));
153  TEST_ASSERT(tol.approximately_equal(v, v_ref));
154  TEST_ASSERT(tol.approximately_equal(dist, dist_ref));
155 
156  // general plane intersecting point
157  dist_ref=0;
158  u_ref=0.5;
159  v_ref=1;
160  a << 1, 2,-1;
161  b <<-2, 1, 2;
162  c << 1,-1, 3;
163  pt=(u_ref*a+v_ref*b+c)+dist_ref*a.cross(b)/a.cross(b).norm();
164  dist=eli::geom::intersect::minimum_distance(u, v, a, b, c, pt);
165  TEST_ASSERT(tol.approximately_equal(u, u_ref));
166  TEST_ASSERT(tol.approximately_equal(v, v_ref));
167  TEST_ASSERT(tol.approximately_equal(dist, dist_ref));
168 
169  // general plane
170  dist_ref=1;
171  u_ref=2.5;
172  v_ref=0.5;
173  a << 1, 2,-1;
174  b <<-2, 1, 2;
175  c << 1,-1, 3;
176  pt=(u_ref*a+v_ref*b+c)+dist_ref*a.cross(b)/a.cross(b).norm();
177  dist=eli::geom::intersect::minimum_distance(u, v, a, b, c, pt);
178  TEST_ASSERT(tol.approximately_equal(u, u_ref));
179  TEST_ASSERT(tol.approximately_equal(v, v_ref));
180  TEST_ASSERT(tol.approximately_equal(dist, dist_ref));
181  }
182 };
183 
184 #endif
185 
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)
~minimum_distance_plane_test_suite()
Definition: minimum_distance_plane_test_suite.hpp:56
Definition: minimum_distance_plane_test_suite.hpp:25
bool approximately_equal(const Eigen::MatrixBase< Derived1 > &m1, const Eigen::MatrixBase< Derived2 > &m2) const
Definition: tolerance.hpp:99
void point_3d_test()
Definition: minimum_distance_plane_test_suite.hpp:61
void AddTests(const float &)
Definition: minimum_distance_plane_test_suite.hpp:35
tolerance_type tol
Definition: minimum_distance_plane_test_suite.hpp:32
Eigen::Matrix< data_type, 1, 3 > point_type
Definition: minimum_distance_plane_test_suite.hpp:29
minimum_distance_plane_test_suite()
Definition: minimum_distance_plane_test_suite.hpp:52
data__ data_type
Definition: minimum_distance_plane_test_suite.hpp:28
void AddTests(const long double &)
Definition: minimum_distance_plane_test_suite.hpp:45
void AddTests(const double &)
Definition: minimum_distance_plane_test_suite.hpp:40
eli::util::tolerance< data_type > tolerance_type
Definition: minimum_distance_plane_test_suite.hpp:30