icosahedron.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { createPrimitive, Primitive } from './primitive';
  7. import { Cage, createCage } from './cage';
  8. const t = (1 + Math.sqrt(5)) / 2;
  9. const icosahedronVertices: ReadonlyArray<number> = [
  10. -1, t, 0, 1, t, 0, -1, -t, 0, 1, -t, 0,
  11. 0, -1, t, 0, 1, t, 0, -1, -t, 0, 1, -t,
  12. t, 0, -1, t, 0, 1, -t, 0, -1, -t, 0, 1
  13. ];
  14. const icosahedronIndices: ReadonlyArray<number> = [
  15. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  17. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  18. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  19. ];
  20. const icosahedronEdges: ReadonlyArray<number> = [
  21. 0, 11, 5, 11, 0, 5, 1, 5, 0, 1, 1, 7, 0, 7, 7, 10, 0, 10, 10, 11,
  22. 5, 9, 4, 11, 2, 10, 6, 7, 1, 8, 3, 9, 4, 9, 3, 4, 2, 4, 2, 3,
  23. 2, 6, 3, 6, 6, 8, 3, 8, 8, 9, 4, 5, 2, 11, 6, 10, 7, 8, 1, 9
  24. ]
  25. let icosahedron: Primitive
  26. export function Icosahedron(): Primitive {
  27. if (!icosahedron) icosahedron = createPrimitive(icosahedronVertices, icosahedronIndices)
  28. return icosahedron
  29. }
  30. const icosahedronCage = createCage(icosahedronVertices, icosahedronEdges)
  31. export function IcosahedronCage(): Cage {
  32. return icosahedronCage
  33. }