-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspm_mesh_polyhedron.m
83 lines (76 loc) · 2.74 KB
/
spm_mesh_polyhedron.m
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function M = spm_mesh_polyhedron(name)
% Return one of the Platonic solids with triangle faces
% FORMAT M = spm_mesh_polyhedron(name)
% name - polyhedron name
% (one of {'tetrahedron','octahedron','icosahedron'})
%
% M - patch structure
%__________________________________________________________________________
%
% See https://www.wikipedia.org/wiki/Platonic_solid
%__________________________________________________________________________
% Copyright (C) 2012-2018 Wellcome Trust Centre for Neuroimaging
% Guillaume Flandin
% $Id: spm_mesh_polyhedron.m 7383 2018-07-31 10:53:37Z guillaume $
switch lower(name)
case 'tetrahedron'
M.vertices = [ 1 0 -1/sqrt(2) ;
-1 0 -1/sqrt(2) ;
0 1 1/sqrt(2) ;
0 -1 1/sqrt(2) ];
M.faces = [ 1 2 3 ;
1 2 4 ;
2 3 4 ;
3 1 4];
case 'octahedron'
M.vertices = [ 0 0 1 ;
1 0 0 ;
0 1 0 ;
-1 0 0 ;
0 -1 0 ;
0 0 -1 ];
M.faces = [ 1 2 3 ;
1 3 4 ;
1 4 5 ;
1 5 2 ;
6 3 2 ;
6 4 3 ;
6 5 4 ;
6 2 5 ];
case 'icosahedron'
r = (1 + sqrt(5)) / 2;
M.vertices = [ 1 0 -r ;
0 r -1 ;
r 1 0 ;
r -1 0 ;
0 -r -1 ;
-1 0 -r ;
-r 1 0 ;
0 r 1 ;
1 0 r ;
0 -r 1 ;
-r -1 0 ;
-1 0 r ];
M.faces = [ 1 2 3
3 4 1
1 4 5
5 6 1
1 6 2
2 6 7
7 8 2
2 8 3
3 8 9
9 4 3
4 9 10
4 10 5
10 11 5
5 11 6
6 11 7
7 12 8
8 12 9
9 12 10
10 12 11
11 12 7 ];
otherwise
error('''%s'' is not a Platonic solid with triangle faces.',name);
end