project_to_line.h 2.2 KB

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