point_simplex_squared_distance.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_POINT_SIMPLEX_SQUARED_DISTANCE_H
  9. #define IGL_POINT_SIMPLEX_SQUARED_DISTANCE_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Determine squared distance from a point to linear simplex.
  15. ///
  16. /// @param[in] p d-long query point
  17. /// @param[in] V #V by d list of vertices
  18. /// @param[in] Ele #Ele by ss<=d+1 list of simplex indices into V
  19. /// @param[in] i index into Ele of simplex
  20. /// @param[out] sqr_d squared distance of Ele(i) to p
  21. /// @param[out] c closest point on Ele(i)
  22. ///
  23. template <
  24. int DIM,
  25. typename Derivedp,
  26. typename DerivedV,
  27. typename DerivedEle,
  28. typename Derivedsqr_d,
  29. typename Derivedc>
  30. IGL_INLINE void point_simplex_squared_distance(
  31. const Eigen::MatrixBase<Derivedp> & p,
  32. const Eigen::MatrixBase<DerivedV> & V,
  33. const Eigen::MatrixBase<DerivedEle> & Ele,
  34. const typename DerivedEle::Index i,
  35. Derivedsqr_d & sqr_d,
  36. Eigen::MatrixBase<Derivedc> & c);
  37. /// Determine squared distance from a point to linear simplex.
  38. /// Also return barycentric coordinate of closest point.
  39. ///
  40. /// @param[in] p d-long query point
  41. /// @param[in] V #V by d list of vertices
  42. /// @param[in] Ele #Ele by ss<=d+1 list of simplex indices into V
  43. /// @param[in] i index into Ele of simplex
  44. /// @param[out] sqr_d squared distance of Ele(i) to p
  45. /// @param[out] c closest point on Ele(i)
  46. /// @param[out] b barycentric coordinates of closest point on Ele(i)
  47. ///
  48. template <
  49. int DIM,
  50. typename Derivedp,
  51. typename DerivedV,
  52. typename DerivedEle,
  53. typename Derivedsqr_d,
  54. typename Derivedc,
  55. typename Derivedb>
  56. IGL_INLINE void point_simplex_squared_distance(
  57. const Eigen::MatrixBase<Derivedp> & p,
  58. const Eigen::MatrixBase<DerivedV> & V,
  59. const Eigen::MatrixBase<DerivedEle> & Ele,
  60. const typename DerivedEle::Index i,
  61. Derivedsqr_d & sqr_d,
  62. Eigen::MatrixBase<Derivedc> & c,
  63. Eigen::PlainObjectBase<Derivedb> & b);
  64. }
  65. #ifndef IGL_STATIC_LIBRARY
  66. # include "point_simplex_squared_distance.cpp"
  67. #endif
  68. #endif