project_to_line.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  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_TO_LINES project points onto vectors, that is find the paramter
  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. // [T,sqrD] = project_to_lines(P,S,D)
  20. //
  21. // Inputs:
  22. // P #P by dim list of points to be projected
  23. // S size dim start position of line vector
  24. // D size dim destination position of line vector
  25. // Outputs:
  26. // T #P by 1 list of parameters
  27. // sqrD #P by 1 list of squared distances
  28. //
  29. //
  30. template <
  31. typename DerivedP,
  32. typename DerivedS,
  33. typename DerivedD,
  34. typename Derivedt,
  35. typename DerivedsqrD>
  36. IGL_INLINE void project_to_line(
  37. const Eigen::MatrixBase<DerivedP> & P,
  38. const Eigen::MatrixBase<DerivedS> & S,
  39. const Eigen::MatrixBase<DerivedD> & D,
  40. Eigen::PlainObjectBase<Derivedt> & t,
  41. Eigen::PlainObjectBase<DerivedsqrD> & sqrD);
  42. // Same as above but for a single query point
  43. template <typename Scalar>
  44. IGL_INLINE void project_to_line(
  45. const Scalar px,
  46. const Scalar py,
  47. const Scalar pz,
  48. const Scalar sx,
  49. const Scalar sy,
  50. const Scalar sz,
  51. const Scalar dx,
  52. const Scalar dy,
  53. const Scalar dz,
  54. Scalar & projpx,
  55. Scalar & projpy,
  56. Scalar & projpz,
  57. Scalar & t,
  58. Scalar & sqrd);
  59. // Same as above but for a single query point
  60. template <typename Scalar>
  61. IGL_INLINE void project_to_line(
  62. const Scalar px,
  63. const Scalar py,
  64. const Scalar pz,
  65. const Scalar sx,
  66. const Scalar sy,
  67. const Scalar sz,
  68. const Scalar dx,
  69. const Scalar dy,
  70. const Scalar dz,
  71. Scalar & t,
  72. Scalar & sqrd);
  73. }
  74. #ifndef IGL_STATIC_LIBRARY
  75. # include "project_to_line.cpp"
  76. #endif
  77. #endif