project_to_line.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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_PROJECT_TO_LINE_H
  9. #define IGL_PROJECT_TO_LINE_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Project points onto vectors, that is find the parameter
  15. /// t for a point p such that proj_p = (y-x).*t, additionally compute the
  16. /// squared distance from p to the line of the vector, such that
  17. /// |p - proj_p|² = sqr_d
  18. ///
  19. ///
  20. /// @param[in] P #P by dim list of points to be projected
  21. /// @param[in] S size dim start position of line vector
  22. /// @param[in] D size dim destination position of line vector
  23. /// @param[out] T #P by 1 list of parameters
  24. /// @param[out] sqrD #P by 1 list of squared distances
  25. ///
  26. ///
  27. template <
  28. typename DerivedP,
  29. typename DerivedS,
  30. typename DerivedD,
  31. typename Derivedt,
  32. typename DerivedsqrD>
  33. IGL_INLINE void project_to_line(
  34. const Eigen::MatrixBase<DerivedP> & P,
  35. const Eigen::MatrixBase<DerivedS> & S,
  36. const Eigen::MatrixBase<DerivedD> & D,
  37. Eigen::PlainObjectBase<Derivedt> & t,
  38. Eigen::PlainObjectBase<DerivedsqrD> & sqrD);
  39. /// \overload
  40. /// \brief Same as above but for a single query point
  41. template <typename Scalar>
  42. IGL_INLINE void project_to_line(
  43. const Scalar px,
  44. const Scalar py,
  45. const Scalar pz,
  46. const Scalar sx,
  47. const Scalar sy,
  48. const Scalar sz,
  49. const Scalar dx,
  50. const Scalar dy,
  51. const Scalar dz,
  52. Scalar & projpx,
  53. Scalar & projpy,
  54. Scalar & projpz,
  55. Scalar & t,
  56. Scalar & sqrd);
  57. /// \overload
  58. template <typename Scalar>
  59. IGL_INLINE void project_to_line(
  60. const Scalar px,
  61. const Scalar py,
  62. const Scalar pz,
  63. const Scalar sx,
  64. const Scalar sy,
  65. const Scalar sz,
  66. const Scalar dx,
  67. const Scalar dy,
  68. const Scalar dz,
  69. Scalar & t,
  70. Scalar & sqrd);
  71. }
  72. #ifndef IGL_STATIC_LIBRARY
  73. # include "project_to_line.cpp"
  74. #endif
  75. #endif