Code-Eli  0.3.6
minimum_distance_line.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_line_hpp
14 #define eli_geom_intersect_minimum_distance_line_hpp
15 
16 #include <cmath>
17 
18 #include "eli/code_eli.hpp"
19 
20 namespace eli
21 {
22  namespace geom
23  {
24  namespace intersect
25  {
26  template<typename Derived1__, typename Derived2__, typename Derived3__>
27  typename Derived1__::Scalar minimum_distance(typename Derived1__::Scalar &t, const Eigen::MatrixBase<Derived1__> &a0,
28  const Eigen::MatrixBase<Derived2__> &a1, const Eigen::MatrixBase<Derived3__> &pt)
29  {
30  Eigen::Matrix<typename Derived1__::Scalar, 1, Eigen::Dynamic> pma0;
31  typename Derived1__::Scalar a1a1;
32 
33  a1a1=a1.dot(a1);
34  pma0=pt-a0;
35 
36  if (a1a1==0)
37  {
38  t=0;
39  return eli::geom::point::distance(a0, pt);
40  }
41 
42  t=pma0.dot(a1)/a1a1;
43  return std::sqrt(std::max(static_cast<typename Derived1__::Scalar>(0), pma0.dot(pma0)-a1a1*t*t));
44  }
45  }
46  }
47 }
48 #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