gradMat.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef IGL_GRAD_MAT_H
  2. #define IGL_GRAD_MAT_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. #include <Eigen/Sparse>
  6. namespace igl {
  7. // GRAD
  8. // G = grad(V,F)
  9. //
  10. // Compute the numerical gradient operator
  11. //
  12. // Inputs:
  13. // V #vertices by 3 list of mesh vertex positions
  14. // F #faces by 3 list of mesh face indices
  15. // Outputs:
  16. // G #faces*dim by #V Gradient operator
  17. //
  18. // Gradient of a scalar function defined on piecewise linear elements (mesh)
  19. // is constant on each triangle i,j,k:
  20. // grad(Xijk) = (Xj-Xi) * (Vi - Vk)^R90 / 2A + (Xk-Xi) * (Vj - Vi)^R90 / 2A
  21. // where Xi is the scalar value at vertex i, Vi is the 3D position of vertex
  22. // i, and A is the area of triangle (i,j,k). ^R90 represent a rotation of
  23. // 90 degrees
  24. //
  25. template <typename T, typename S>
  26. IGL_INLINE void gradMat(const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &V,
  27. const Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic> &F,
  28. Eigen::SparseMatrix<T> &G);
  29. }
  30. #ifdef IGL_HEADER_ONLY
  31. # include "gradMat.cpp"
  32. #endif
  33. #endif