Code-Eli  0.3.6
minimum_distance_plane.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_plane_hpp
14 #define eli_geom_intersect_minimum_distance_plane_hpp
15 
16 #include <cmath>
17 
18 #include "eli/code_eli.hpp"
19 
21 
22 namespace eli
23 {
24  namespace geom
25  {
26  namespace intersect
27  {
28  template<typename Derived1__, typename Derived2__, typename Derived3__, typename Derived4__>
29  typename Derived1__::Scalar minimum_distance(typename Derived1__::Scalar &u, typename Derived1__::Scalar &v,
30  const Eigen::MatrixBase<Derived1__> &a, const Eigen::MatrixBase<Derived2__> &b,
31  const Eigen::MatrixBase<Derived3__> &c, const Eigen::MatrixBase<Derived4__> &pt)
32  {
33  Eigen::Matrix<typename Derived1__::Scalar, 1, Eigen::Dynamic> pmc;
34  typename Derived1__::Scalar aa, ab, bb, denom;
35 
36  aa=a.dot(a);
37  ab=a.dot(b);
38  bb=b.dot(b);
39  pmc=pt-c;
40 
41  // degenerate point case
42  if ((aa==0) && (bb==0))
43  {
44  u=0;
45  v=0;
46  return eli::geom::point::distance(c, pt);
47  }
48 
49  // degenerate line case
50  if (ab*ab==aa*bb)
51  {
52  v=0;
53  return eli::geom::intersect::minimum_distance(u, c, a, pt);
54  }
55 
56  // surface & point case
57  denom=ab*ab-aa*bb;
58  u=(ab*b-bb*a).dot(pmc)/denom;
59  v=(ab*a-aa*b).dot(pmc)/denom;
60  return (a*u+b*v-pmc).norm();
61  }
62  }
63  }
64 }
65 #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)
Derived1__::Scalar distance(const Eigen::MatrixBase< Derived1__ > &p1, const Eigen::MatrixBase< Derived2__ > &p2)
Definition: distance.hpp:33