dodecahedron.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Copyright (c) 2019 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 a = 1;
  10. const b = 1 / t;
  11. const c = 2 - t;
  12. export const dodecahedronVertices: ReadonlyArray<number> = [
  13. c, 0, a, -c, 0, a, -b, b, b, 0, a, c, b, b, b,
  14. b, -b, b, 0, -a, c, -b, -b, b, c, 0, -a, -c, 0, -a,
  15. -b, -b, -b, 0, -a, -c, b, -b, -b, b, b, -b, 0, a, -c,
  16. -b, b, -b, a, c, 0, -a, c, 0, -a, -c, 0, a, -c, 0
  17. ];
  18. /** indices of pentagonal faces, groups of five */
  19. export const dodecahedronFaces: ReadonlyArray<number> = [
  20. 4, 3, 2, 1, 0,
  21. 7, 6, 5, 0, 1,
  22. 12, 11, 10, 9, 8,
  23. 15, 14, 13, 8, 9,
  24. 14, 3, 4, 16, 13,
  25. 3, 14, 15, 17, 2,
  26. 11, 6, 7, 18, 10,
  27. 6, 11, 12, 19, 5,
  28. 4, 0, 5, 19, 16,
  29. 12, 8, 13, 16, 19,
  30. 15, 9, 10, 18, 17,
  31. 7, 1, 2, 17, 18
  32. ];
  33. const dodecahedronIndices: ReadonlyArray<number> = [ // pentagonal faces
  34. 4, 3, 2, 2, 1, 0, 4, 2, 0, // 4, 3, 2, 1, 0
  35. 7, 6, 5, 5, 0, 1, 7, 5, 1, // 7, 6, 5, 0, 1
  36. 12, 11, 10, 10, 9, 8, 12, 10, 8, // 12, 11, 10, 9, 8
  37. 15, 14, 13, 13, 8, 9, 15, 13, 9, // 15, 14, 13, 8, 9
  38. 14, 3, 4, 4, 16, 13, 14, 4, 13, // 14, 3, 4, 16, 13
  39. 3, 14, 15, 15, 17, 2, 3, 15, 2, // 3, 14, 15, 17, 2
  40. 11, 6, 7, 7, 18, 10, 11, 7, 10, // 11, 6, 7, 18, 10
  41. 6, 11, 12, 12, 19, 5, 6, 12, 5, // 6, 11, 12, 19, 5
  42. 4, 0, 5, 5, 19, 16, 4, 5, 16, // 4, 0, 5, 19, 16
  43. 12, 8, 13, 13, 16, 19, 12, 13, 19, // 12, 8, 13, 16, 19
  44. 15, 9, 10, 10, 18, 17, 15, 10, 17, // 15, 9, 10, 18, 17
  45. 7, 1, 2, 2, 17, 18, 7, 2, 18, // 7, 1, 2, 17, 18
  46. ];
  47. const dodecahedronEdges: ReadonlyArray<number> = [
  48. 0, 1, 0, 4, 0, 5, 1, 2, 1, 7, 2, 3, 2, 17, 3, 4, 3, 14, 4, 16,
  49. 5, 6, 5, 19, 6, 7, 6, 11, 7, 18, 8, 9, 8, 12, 8, 13, 9, 10, 9, 15,
  50. 10, 11, 10, 18, 11, 12, 12, 19, 13, 14, 13, 16, 14, 15, 15, 17, 16, 19, 17, 18,
  51. ]
  52. let dodecahedron: Primitive
  53. export function Dodecahedron(): Primitive {
  54. if (!dodecahedron) dodecahedron = createPrimitive(dodecahedronVertices, dodecahedronIndices)
  55. return dodecahedron
  56. }
  57. const dodecahedronCage = createCage(dodecahedronVertices, dodecahedronEdges)
  58. export function DodecahedronCage(): Cage {
  59. return dodecahedronCage
  60. }