icosahedron.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "icosahedron.h"
  2. #include "PI.h"
  3. template <typename DerivedV, typename DerivedF>
  4. IGL_INLINE void igl::icosahedron(
  5. Eigen::PlainObjectBase<DerivedV> & V,
  6. Eigen::PlainObjectBase<DerivedF> & F)
  7. {
  8. V.resize(12,3);
  9. V.row(0) << 0,0,1;
  10. const auto r = (1+sqrt(5))/2 - 0.5;
  11. const auto z = 0.5/r;
  12. const auto pi = atan(1)*4;
  13. for(int i = 0;i<5;i++)
  14. {
  15. const auto beta = (i*2)*igl::PI/5;
  16. V.row(i+6) << cos(beta)/r,sin(beta)/r,-z;
  17. const auto alpha = beta - igl::PI/5;
  18. V.row(i+1) << cos(alpha)/r,sin(alpha)/r,z;
  19. }
  20. V.row(11) << 0,0,-1;
  21. F.resize(20,3);
  22. F<<
  23. 0,1,2,
  24. 0,2,3,
  25. 0,3,4,
  26. 0,4,5,
  27. 0,5,1,
  28. 1,6,2,
  29. 2,7,3,
  30. 3,8,4,
  31. 4,9,5,
  32. 5,10,1,
  33. 6,7,2,
  34. 7,8,3,
  35. 8,9,4,
  36. 9,10,5,
  37. 10,6,1,
  38. 6,11,7,
  39. 7,11,8,
  40. 8,11,9,
  41. 9,11,10,
  42. 10,11,6;
  43. }
  44. #ifdef IGL_STATIC_LIBRARY
  45. // Explicit template instantiation
  46. // generated by autoexplicit.sh
  47. template void igl::icosahedron<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  48. #endif