per_face_normals.cpp 651 B

1234567891011121314151617
  1. #include "per_face_normals.h"
  2. template <typename DerivedV, typename DerivedF>
  3. IGL_INLINE void igl::per_face_normals(
  4. const Eigen::PlainObjectBase<DerivedV>& V,
  5. const Eigen::PlainObjectBase<DerivedF>& F,
  6. Eigen::PlainObjectBase<DerivedV> & N)
  7. {
  8. N.resize(F.rows(),3);
  9. // loop over faces
  10. for(int i = 0; i < F.rows();i++)
  11. {
  12. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v1 = V.row(F(i,1)) - V.row(F(i,0));
  13. Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v2 = V.row(F(i,2)) - V.row(F(i,0));
  14. N.row(i) = (v1.cross(v2)).normalized();
  15. }
  16. }