Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

# -*- coding: utf-8 -*- 

r""" 

Platonic solids 

 

The methods defined here appear in :mod:`sage.graphs.graph_generators`. 

 

""" 

########################################################################### 

# 

# Copyright (C) 2006 Robert L. Miller <rlmillster@gmail.com> 

# and Emily A. Kirkman 

# Copyright (C) 2009 Michael C. Yurko <myurko@gmail.com> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# http://www.gnu.org/licenses/ 

########################################################################### 

 

# import from Sage library 

from sage.graphs.graph import Graph 

from math import sin, cos, pi 

 

def TetrahedralGraph(): 

""" 

Returns a tetrahedral graph (with 4 nodes). 

 

A tetrahedron is a 4-sided triangular pyramid. The tetrahedral 

graph corresponds to the connectivity of the vertices of the 

tetrahedron. This graph is equivalent to a wheel graph with 4 nodes 

and also a complete graph on four nodes. (See examples below). 

 

PLOTTING: The tetrahedral graph should be viewed in 3 dimensions. 

We chose to use the default spring-layout algorithm here, so that 

multiple iterations might yield a different point of reference for 

the user. We hope to add rotatable, 3-dimensional viewing in the 

future. In such a case, a string argument will be added to select 

the flat spring-layout over a future implementation. 

 

EXAMPLES: Construct and show a Tetrahedral graph 

 

:: 

 

sage: g = graphs.TetrahedralGraph() 

sage: g.show() # long time 

 

The following example requires networkx:: 

 

sage: import networkx as NX 

 

Compare this Tetrahedral, Wheel(4), Complete(4), and the 

Tetrahedral plotted with the spring-layout algorithm below in a 

Sage graphics array:: 

 

sage: tetra_pos = graphs.TetrahedralGraph() 

sage: tetra_spring = Graph(NX.tetrahedral_graph()) 

sage: wheel = graphs.WheelGraph(4) 

sage: complete = graphs.CompleteGraph(4) 

sage: g = [tetra_pos, tetra_spring, wheel, complete] 

sage: j = [] 

sage: for i in range(2): 

....: n = [] 

....: for m in range(2): 

....: n.append(g[i + m].plot(vertex_size=50, vertex_labels=False)) 

....: j.append(n) 

sage: G = sage.plot.graphics.GraphicsArray(j) 

sage: G.show() # long time 

""" 

import networkx 

G = networkx.tetrahedral_graph() 

return Graph(G, name="Tetrahedron", pos = 

{ 0 : (0, 0), 

1 : (0, 1), 

2 : (cos(3.5*pi/3), sin(3.5*pi/3)), 

3 : (cos(5.5*pi/3), sin(5.5*pi/3))} 

) 

 

def HexahedralGraph(): 

""" 

Returns a hexahedral graph (with 8 nodes). 

 

A regular hexahedron is a 6-sided cube. The hexahedral graph 

corresponds to the connectivity of the vertices of the hexahedron. 

This graph is equivalent to a 3-cube. 

 

PLOTTING: The hexahedral graph should be viewed in 3 dimensions. We 

chose to use the default spring-layout algorithm here, so that 

multiple iterations might yield a different point of reference for 

the user. We hope to add rotatable, 3-dimensional viewing in the 

future. In such a case, a string argument will be added to select 

the flat spring-layout over a future implementation. 

 

EXAMPLES: Construct and show a Hexahedral graph 

 

:: 

 

sage: g = graphs.HexahedralGraph() 

sage: g.show() # long time 

 

Create several hexahedral graphs in a Sage graphics array. They 

will be drawn differently due to the use of the spring-layout 

algorithm. 

 

:: 

 

sage: g = [] 

sage: j = [] 

sage: for i in range(9): 

....: k = graphs.HexahedralGraph() 

....: g.append(k) 

sage: for i in range(3): 

....: n = [] 

....: for m in range(3): 

....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) 

....: j.append(n) 

sage: G = sage.plot.graphics.GraphicsArray(j) 

sage: G.show() # long time 

""" 

return Graph({0:[1,3,4], 1:[2,5], 2:[3,6], 3:[7], 4:[5,7], 5:[6], 6:[7]}, 

name="Hexahedron", 

pos = { 

0 : (0,0), 

1 : (1,0), 

3 : (0,1), 

2 : (1,1), 

4 : (.5,.5), 

5 : (1.5,.5), 

7 : (.5,1.5), 

6 : (1.5,1.5) 

}) 

 

def OctahedralGraph(): 

""" 

Returns an Octahedral graph (with 6 nodes). 

 

The regular octahedron is an 8-sided polyhedron with triangular 

faces. The octahedral graph corresponds to the connectivity of the 

vertices of the octahedron. It is the line graph of the tetrahedral 

graph. The octahedral is symmetric, so the spring-layout algorithm 

will be very effective for display. 

 

PLOTTING: The Octahedral graph should be viewed in 3 dimensions. We 

chose to use the default spring-layout algorithm here, so that 

multiple iterations might yield a different point of reference for 

the user. We hope to add rotatable, 3-dimensional viewing in the 

future. In such a case, a string argument will be added to select 

the flat spring-layout over a future implementation. 

 

EXAMPLES: Construct and show an Octahedral graph 

 

:: 

 

sage: g = graphs.OctahedralGraph() 

sage: g.show() # long time 

 

Create several octahedral graphs in a Sage graphics array They will 

be drawn differently due to the use of the spring-layout algorithm 

 

:: 

 

sage: g = [] 

sage: j = [] 

sage: for i in range(9): 

....: k = graphs.OctahedralGraph() 

....: g.append(k) 

sage: for i in range(3): 

....: n = [] 

....: for m in range(3): 

....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) 

....: j.append(n) 

sage: G = sage.plot.graphics.GraphicsArray(j) 

sage: G.show() # long time 

""" 

import networkx 

G = networkx.octahedral_graph() 

 

pos = {} 

r1 = 5 

r2 = 1 

for i,v in enumerate([0,1,2]): 

i = i + 0.75 

pos[v] = (r1*cos(i*2*pi/3),r1*sin(i*2*pi/3)) 

 

for i,v in enumerate([4,3,5]): 

i = i + .25 

pos[v] = (r2*cos(i*2*pi/3),r2*sin(i*2*pi/3)) 

 

return Graph(G, name="Octahedron", pos=pos) 

 

def IcosahedralGraph(): 

""" 

Returns an Icosahedral graph (with 12 nodes). 

 

The regular icosahedron is a 20-sided triangular polyhedron. The 

icosahedral graph corresponds to the connectivity of the vertices 

of the icosahedron. It is dual to the dodecahedral graph. The 

icosahedron is symmetric, so the spring-layout algorithm will be 

very effective for display. 

 

PLOTTING: The Icosahedral graph should be viewed in 3 dimensions. 

We chose to use the default spring-layout algorithm here, so that 

multiple iterations might yield a different point of reference for 

the user. We hope to add rotatable, 3-dimensional viewing in the 

future. In such a case, a string argument will be added to select 

the flat spring-layout over a future implementation. 

 

EXAMPLES: Construct and show an Octahedral graph 

 

:: 

 

sage: g = graphs.IcosahedralGraph() 

sage: g.show() # long time 

 

Create several icosahedral graphs in a Sage graphics array. They 

will be drawn differently due to the use of the spring-layout 

algorithm. 

 

:: 

 

sage: g = [] 

sage: j = [] 

sage: for i in range(9): 

....: k = graphs.IcosahedralGraph() 

....: g.append(k) 

sage: for i in range(3): 

....: n = [] 

....: for m in range(3): 

....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) 

....: j.append(n) 

sage: G = sage.plot.graphics.GraphicsArray(j) 

sage: G.show() # long time 

""" 

import networkx 

G = networkx.icosahedral_graph() 

 

pos = {} 

r1 = 5 

r2 = 2 

for i,v in enumerate([2,8,7,11,4,6]): 

i = i + .5 

pos[v] = (r1*cos(i*pi/3),r1*sin(i*pi/3)) 

 

for i,v in enumerate([1,9,0,10,5,3]): 

i = i + .5 

pos[v] = (r2*cos(i*pi/3),r2*sin(i*pi/3)) 

 

return Graph(G, name="Icosahedron", pos = pos) 

 

def DodecahedralGraph(): 

""" 

Returns a Dodecahedral graph (with 20 nodes) 

 

The dodecahedral graph is cubic symmetric, so the spring-layout 

algorithm will be very effective for display. It is dual to the 

icosahedral graph. 

 

PLOTTING: The Dodecahedral graph should be viewed in 3 dimensions. 

We chose to use the default spring-layout algorithm here, so that 

multiple iterations might yield a different point of reference for 

the user. We hope to add rotatable, 3-dimensional viewing in the 

future. In such a case, a string argument will be added to select 

the flat spring-layout over a future implementation. 

 

EXAMPLES: Construct and show a Dodecahedral graph 

 

:: 

 

sage: g = graphs.DodecahedralGraph() 

sage: g.show() # long time 

 

Create several dodecahedral graphs in a Sage graphics array They 

will be drawn differently due to the use of the spring-layout 

algorithm 

 

:: 

 

sage: g = [] 

sage: j = [] 

sage: for i in range(9): 

....: k = graphs.DodecahedralGraph() 

....: g.append(k) 

sage: for i in range(3): 

....: n = [] 

....: for m in range(3): 

....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False)) 

....: j.append(n) 

sage: G = sage.plot.graphics.GraphicsArray(j) 

sage: G.show() # long time 

""" 

import networkx 

G = networkx.dodecahedral_graph() 

 

pos = {} 

r1 = 7 

r2 = 4.7 

r3 = 3.8 

r4 = 1.5 

 

for i,v in enumerate([19,0,1,2,3]): 

i = i + .25 

pos[v] = (r1*cos(i*2*pi/5),r1*sin(i*2*pi/5)) 

 

for i,v in enumerate([18,10,8,6,4]): 

i = i + .25 

pos[v] = (r2*cos(i*2*pi/5),r2*sin(i*2*pi/5)) 

 

for i,v in enumerate([17,11,9,7,5]): 

i = i - .25 

pos[v] = (r3*cos(i*2*pi/5),r3*sin(i*2*pi/5)) 

 

for i,v in enumerate([12,13,14,15,16]): 

i = i + .75 

pos[v] = (r4*cos(i*2*pi/5),r4*sin(i*2*pi/5)) 

 

return Graph(G, name="Dodecahedron", pos=pos)