super_fibonacci.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "super_fibonacci.h"
  2. #include "PI.h"
  3. #include <cmath>
  4. template <typename DerivedQ>
  5. IGL_INLINE void igl::super_fibonacci(
  6. const int n,
  7. Eigen::PlainObjectBase<DerivedQ> & Q)
  8. {
  9. typedef typename DerivedQ::Scalar Scalar;
  10. // https://marcalexa.github.io/superfibonacci/
  11. Scalar dn = 1.0 / (Scalar)n;
  12. Scalar mc0 = 1.0 / std::sqrt(2.0);
  13. Scalar mc1 = 1.0 / 1.533751168755204288118041;
  14. Q.resize(n,4);
  15. for (int i = 0; i < n; i++)
  16. {
  17. Scalar s = (Scalar)i+0.5;
  18. Scalar ab = 2.0 * igl::PI * s;
  19. Scalar alpha = ab * mc0;
  20. Scalar beta = ab * mc1;
  21. s *= dn;
  22. Scalar r = std::sqrt(s);
  23. Scalar R = std::sqrt(1.0-s);
  24. Q(i,0) = r*std::sin(alpha);
  25. Q(i,1) = r*std::cos(alpha);
  26. Q(i,2) = R*std::sin(beta);
  27. Q(i,3) = R*std::cos(beta);
  28. }
  29. }
  30. #ifdef IGL_STATIC_LIBRARY
  31. // Explicit template instantiation
  32. template void igl::super_fibonacci<Eigen::Matrix<double, -1, 4, 1, -1, 4>>(int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 4, 1, -1, 4>>&);
  33. template void igl::super_fibonacci<Eigen::Matrix<double, -1, -1, 0, -1, -1>>(int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&);
  34. #endif