project_to_line.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef IGL_PROJECT_TO_LINE
  2. #define IGL_PROJECT_TO_LINE
  3. #include "igl_inline.h"
  4. namespace igl
  5. {
  6. // PROJECT_TO_LINES project points onto vectors, that is find the paramter
  7. // t for a point p such that proj_p = (y-x).*t, additionally compute the
  8. // squared distance from p to the line of the vector, such that
  9. // |p - proj_p|² = sqr_d
  10. //
  11. // [T,sqrD] = project_to_lines(P,S,D)
  12. //
  13. // Templates:
  14. // MatP matrix template for P, implementing .cols(), .rows()
  15. // MatL matrix template for S and D, implementing .size(), .array(), .sum()
  16. // Matt matrix template for t
  17. // MatsqrD matrix template for sqrD
  18. // Inputs:
  19. // P #P by dim list of points to be projected
  20. // S size dim start position of line vector
  21. // D size dim destination position of line vector
  22. // Outputs:
  23. // T #P by 1 list of parameters
  24. // sqrD #P by 1 list of squared distances
  25. //
  26. //
  27. template <
  28. typename MatP,
  29. typename MatL,
  30. typename Matt,
  31. typename MatsqrD>
  32. IGL_INLINE void project_to_line(
  33. const MatP & P,
  34. const MatL & S,
  35. const MatL & D,
  36. Matt & t,
  37. MatsqrD & sqrD);
  38. // Same as above but for a single query point
  39. template <typename Scalar>
  40. IGL_INLINE void project_to_line(
  41. const Scalar px,
  42. const Scalar py,
  43. const Scalar pz,
  44. const Scalar sx,
  45. const Scalar sy,
  46. const Scalar sz,
  47. const Scalar dx,
  48. const Scalar dy,
  49. const Scalar dz,
  50. Scalar & projpx,
  51. Scalar & projpy,
  52. Scalar & projpz,
  53. Scalar & t,
  54. Scalar & sqrd);
  55. // Same as above but for a single query point
  56. template <typename Scalar>
  57. IGL_INLINE void project_to_line(
  58. const Scalar px,
  59. const Scalar py,
  60. const Scalar pz,
  61. const Scalar sx,
  62. const Scalar sy,
  63. const Scalar sz,
  64. const Scalar dx,
  65. const Scalar dy,
  66. const Scalar dz,
  67. Scalar & t,
  68. Scalar & sqrd);
  69. }
  70. #ifdef IGL_HEADER_ONLY
  71. # include "project_to_line.cpp"
  72. #endif
  73. #endif