cylinder.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "cylinder.h"
  2. #include <cassert>
  3. #include <cmath>
  4. #include <cstddef>
  5. template <typename DerivedV, typename DerivedF>
  6. IGL_INLINE void igl::cylinder(
  7. const int axis_devisions,
  8. const int height_devisions,
  9. Eigen::PlainObjectBase<DerivedV> & V,
  10. Eigen::PlainObjectBase<DerivedF> & F)
  11. {
  12. V.resize(axis_devisions*height_devisions,3);
  13. F.resize(2*(axis_devisions*(height_devisions-1)),3);
  14. int f = 0;
  15. typedef typename DerivedV::Scalar Scalar;
  16. for(int th = 0;th<axis_devisions;th++)
  17. {
  18. Scalar x = cos(2.*M_PI*Scalar(th)/Scalar(axis_devisions));
  19. Scalar y = sin(2.*M_PI*Scalar(th)/Scalar(axis_devisions));
  20. for(int h = 0;h<height_devisions;h++)
  21. {
  22. Scalar z = Scalar(h)/Scalar(height_devisions-1);
  23. V(th+h*axis_devisions,0) = x;
  24. V(th+h*axis_devisions,1) = y;
  25. V(th+h*axis_devisions,2) = z;
  26. if(h > 0)
  27. {
  28. F(f,0) = ((th+0)%axis_devisions)+(h-1)*axis_devisions;
  29. F(f,1) = ((th+1)%axis_devisions)+(h-1)*axis_devisions;
  30. F(f,2) = ((th+0)%axis_devisions)+(h+0)*axis_devisions;
  31. f++;
  32. F(f,0) = ((th+1)%axis_devisions)+(h-1)*axis_devisions;
  33. F(f,1) = ((th+1)%axis_devisions)+(h+0)*axis_devisions;
  34. F(f,2) = ((th+0)%axis_devisions)+(h+0)*axis_devisions;
  35. f++;
  36. }
  37. }
  38. }
  39. assert(f == F.rows());
  40. }
  41. #ifdef IGL_STATIC_LIBRARY
  42. template void igl::cylinder<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(int, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  43. #endif