How to build a polyhedron
Whether it's Python, C, or Matlab, it doesn't matter what language it is.
For example, suppose you have the following data on a regular dodecahedron:
This data shows at which three points for each vertex 0 to 11 of a regular 20 square, one triangle, or one plane of a regular 20 square.
You can connect vertices like this image.
Data1
640
4 9 0
9 3 0
3 11 0
11 6 0
4 6 1
6 8 1
8 2 1
2 10 1
10 4 1
8 7 2
7 5 2
5 10 2
10 9 4
9 10 5
7 11 3
5 7 3
9 5 3
11 8 6
8 11 7
I'm looking for a code that shows what a polyhedron looks like from this type of data.
The above data may be obvious, but if the data is complicated like the one below, you won't know right away.
Data 2
14012
13 14 12
13 6 14
12 4 13
12 0 15
16 12 15
16 4 12
15 9 16
15 0 17
18 15 17
18 9 15
17 3 18
17 0 19
20 17 19
20 3 17
19 11 20
19 0 14
21 19 14
21 11 19
14 6 21
23 1 22
13 23 22
13 4 23
22 6 13
22 1 24
25 22 24
25 6 22
24 8 25
24 1 26
27 24 26
27 8 24
26 2 27
26 1 28
29 26 28
29 2 26
28 10 29
28 1 23
30 28 23
30 10 28
23 4 30
27 2 31
32 27 31
32 8 27
31 7 32
31 2 33
34 31 33
34 7 31
33 5 34
33 2 29
35 33 29
35 5 33
29 10 35
30 4 16
36 30 16
36 10 30
16 9 36
37 5 35
36 37 35
36 9 37
35 10 36
39 3 20
38 39 20
38 7 39
20 11 38
40 3 39
34 40 39
34 5 40
39 7 34
18 3 40
37 18 40
37 9 18
40 5 37
21 6 25
41 21 25
41 11 21
25 8 41
32 7 38
41 32 38
41 8 32
38 11 41
Please let me know if anyone knows the code to achieve what I want to achieve.
algorithm graph-theory
This question can be addressed in Graph
, although there are many Graph
but Graph
in in graph.
Below is a sample code using Python's NetworkX
and the results.
import numpy as np
import matplotlib.pyplot asplt
import networkx as nx
US>'s = '
14 0 12
13 14 12
13 6 14
12 4 13
12 0 15
16 12 15
16 4 12
15 9 16
15 0 17
18 15 17
18 9 15
17 3 18
17 0 19
20 17 19
20 3 17
19 11 20
19 0 14
21 19 14
21 11 19
14 6 21
23 1 22
13 23 22
13 4 23
22 6 13
22 1 24
25 22 24
25 6 22
24 8 25
24 1 26
27 24 26
27 8 24
26 2 27
26 1 28
29 26 28
29 2 26
28 10 29
28 1 23
30 28 23
30 10 28
23 4 30
27 2 31
32 27 31
32 8 27
31 7 32
31 2 33
34 31 33
34 7 31
33 5 34
33 2 29
35 33 29
35 5 33
29 10 35
30 4 16
36 30 16
36 10 30
16 9 36
37 5 35
36 37 35
36 9 37
35 10 36
39 3 20
38 39 20
38 7 39
20 11 38
40 3 39
34 40 39
34 5 40
39 7 34
18 3 40
37 18 40
37 9 18
40 5 37
21 6 25
41 21 25
41 11 21
25 8 41
32 7 38
41 32 38
41 8 32
38 11 41
'''
data=np.fromstring(s,sep="").reshape(-1,3)
G=nx.Graph()
# Adding Nodes
nodes=np.unique(data)
G.add_nodes_from(nodes)
# Add Edge
For dind data:
G.add_edges_from ((d[0], d[1], (d[1], d[2], (d[2], d[0])])
# Get Layout
pos=nx.spring_layout(G)
# visualization
plt.figure(figsize=(6,6)))
nx.draw_networkx_edges(G,pos)
nx.draw_networkx_nodes(G,pos)
plt.axis()
plt.show()
The Graph drawing in English Wikipedia contains a lot of Graph drawing
software, so I would appreciate it if you could write a response using those software.
© 2024 OneMinuteCode. All rights reserved.