grid.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2016 Intel Corporation. All rights reserved.
  2. #
  3. # This file is free software: you can redistribute it and/or modify it
  4. # under the terms of the GNU General Public License as published by the
  5. # Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This file is distributed in the hope that it will be useful, but
  9. # WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. # See the GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License along
  14. # with this program. If not, see <http://www.gnu.org/licenses/>.
  15. import icosahedron as ico
  16. def section_triangle(s):
  17. a, b, c = ico.triangles[s / 4]
  18. # project the middle points to the sphere
  19. alpha = a.length() / (2.0 * ico.g)
  20. ma, mb, mc = alpha * (a + b), alpha * (b + c), alpha * (c + a)
  21. sub = s % 4
  22. if sub == 0:
  23. return ico.Triangle(ma, mb, mc)
  24. elif sub == 1:
  25. return ico.Triangle(a, ma, mc)
  26. elif sub == 2:
  27. return ico.Triangle(ma, b, mb)
  28. else:
  29. return ico.Triangle(mc, mb, c)