forked from fogleman/demsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shapes.go
50 lines (49 loc) · 815 Bytes
/
shapes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package demsphere
func NewIcosahedron() []Triangle {
const a = 0.8506507174597755
const b = 0.5257312591858783
vertices := []Vector{
{-a, -b, 0},
{-a, b, 0},
{-b, 0, -a},
{-b, 0, a},
{0, -a, -b},
{0, -a, b},
{0, a, -b},
{0, a, b},
{b, 0, -a},
{b, 0, a},
{a, -b, 0},
{a, b, 0},
}
indices := [][3]int{
{0, 3, 1},
{1, 3, 7},
{2, 0, 1},
{2, 1, 6},
{4, 0, 2},
{4, 5, 0},
{5, 3, 0},
{6, 1, 7},
{6, 7, 11},
{7, 3, 9},
{8, 2, 6},
{8, 4, 2},
{8, 6, 11},
{8, 10, 4},
{8, 11, 10},
{9, 3, 5},
{10, 5, 4},
{10, 9, 5},
{11, 7, 9},
{11, 9, 10},
}
triangles := make([]Triangle, len(indices))
for i, idx := range indices {
p1 := vertices[idx[0]]
p2 := vertices[idx[1]]
p3 := vertices[idx[2]]
triangles[i] = Triangle{p1, p2, p3}
}
return triangles
}