molgri.space.polytopes
NetworkX graphs representing Platonic solids in 3- or 4D.
Specifically, we implement the 3D polytopes icosahedron and cube and the 4D polytope hypercube. As a start, vertices of the polytope are added as nodes and edges as connections between them. For the cube, a point is also added in the middle of each face diagonal and the edges from these face points to the four vertices are added. For the hypercube, a point is added at the center of each of the 8 sub-cells and in the middle of all square faces, edges to these points are also added.
It’s important that polytopes can also be subdivided in smaller units so that grids with larger numbers of points can be created. For this, use divide_edges() command. 3D polytopes (polyhedra) can also be plotted - for 4D polyhedra, each 3D cell can be plotted.
Points and their projections should always be accessed with getters and include only non-repeating rotation quaternions for cube4D.
- Objects:
Polytope (abstract)
Polyhedron (abstract, only 3D, implements plotting)
PolyhedronFromG (helper for testing/plotting, initiated with an existing graph)
Cube4DPolytope
IcosahedronPolytope
Cube3DPolytope
Functions
|
See detect_all_squares, but now a cube consists of: a node, 3 direct neighbours, 3 second neighbours, 1 third neighbour. |
|
Each node of the graph is represented by 3- or 4-dimensional coordinates, meaning that distances and even angles to other nodes can be calculated. |
|
Yield second neighbors of node in graph. |
|
Yield second neighbors of node in graph. |
Classes
In the beginning, each node is a vertex of a 3D cube + 6 vertices at mid-faces. |
|
CubeGrid is a graph object, its central feature is self.G (networkx graph). |
|
IcosahedronPolytope is a graph object, its central feature is self.G (networkx graph). |
|
This is a mock polyhedron created from an existing graph. No guarantee that it represents a polyhedron. Args: G:. |
|
|
A polytope is a d-dim object consisting of a set of nodes (vertices) and connections between them (edges) saved in self.G (graph). |
- class molgri.space.polytopes.Polytope(d: int = 3, is_quat: bool = False)
A polytope is a d-dim object consisting of a set of nodes (vertices) and connections between them (edges) saved in self.G (graph).
The basic polytope will be created when the object is initiated. All further divisions should be performed with the function self.divide_edges()
- Args:
d: number of dimensions is_quat: does the object represent quaternions (meaning that q and -q points are treated as equal)
- __init__(d: int = 3, is_quat: bool = False)
A polytope is a d-dim object consisting of a set of nodes (vertices) and connections between them (edges) saved in self.G (graph).
The basic polytope will be created when the object is initiated. All further divisions should be performed with the function self.divide_edges()
- Args:
d: number of dimensions is_quat: does the object represent quaternions (meaning that q and -q points are treated as equal)
- get_node_coordinates() ndarray[Any, dtype[ScalarType]]
Get an array in which each row represents the self.d - dimensional coordinates of the node. These are the points on the faces of the polytope, their norm may not be one.
If the object is_quat, approximately half of the nodes will be returned, since for quaternions q=-q.
- Returns:
a numpy array in which each row is one of the nodes in order of their addition to the graph (not sorted)
- get_projection_coordinates() ndarray[Any, dtype[ScalarType]]
Get an array in which each row represents the self.d - dimensional coordinates of the node projected on a self.d-dimensional unit sphere. These points must have norm 1.
If the object is_quat, approximately half of the nodes will be returned, since for quaternions q=-q.
- Returns:
a numpy array in which each row is one of the projections in order of their addition to the graph (not sorted)
- get_N_ordered_points(N: int | None = None, projections: bool = True) ndarray[Any, dtype[ScalarType]]
Get nodes or their projections - this getter implements sorting and truncation at N.
- Args:
N: wished number of points to return (if None, return all) projections: if True, use projections on unit sphere, if False, points on the polytope
- Returns:
an array of size (N, self.d) featuring N nodes/projections sorted for max distance between them
- Raises:
ValueError if N larger than the number of available unique nodes
- divide_edges()
Subdivide once by putting a new point at mid-point of each existing edge and replacing this sub-edge with two edges from the two old to the new point.
In sub-modules, additional edges may be added before performing divisions.
- class molgri.space.polytopes.PolyhedronFromG(G: Graph)
This is a mock polyhedron created from an existing graph. No guarantee that it represents a polyhedron. Args:
G:
- __init__(G: Graph)
This is a mock polyhedron created from an existing graph. No guarantee that it represents a polyhedron. Args:
G:
- class molgri.space.polytopes.Cube4DPolytope
CubeGrid is a graph object, its central feature is self.G (networkx graph). In the beginning, each node is a vertex of a 3D cube, its center or the center of its face. It is possible to subdivide the sides, in that case the volumes of sub-cubes are fully sub-divided.
Special: the attribute “face” that in 3D polyhedra actually means face here refers to the cell (3D object) to which this specific node belongs.
A polytope is a d-dim object consisting of a set of nodes (vertices) and connections between them (edges) saved in self.G (graph).
The basic polytope will be created when the object is initiated. All further divisions should be performed with the function self.divide_edges()
- Args:
d: number of dimensions is_quat: does the object represent quaternions (meaning that q and -q points are treated as equal)
- __init__()
A polytope is a d-dim object consisting of a set of nodes (vertices) and connections between them (edges) saved in self.G (graph).
The basic polytope will be created when the object is initiated. All further divisions should be performed with the function self.divide_edges()
- Args:
d: number of dimensions is_quat: does the object represent quaternions (meaning that q and -q points are treated as equal)
- divide_edges()
Subdivide once by putting a new point at mid-point of each existing edge and replacing this sub-edge with two edges from the two old to the new point.
In sub-modules, additional edges may be added before performing divisions.
- class molgri.space.polytopes.IcosahedronPolytope
IcosahedronPolytope is a graph object, its central feature is self.G (networkx graph). In the beginning, each node is a vertex of a 3D icosahedron. It is possible to subdivide the sides, in that case a new point always appears in the middle of each triangle side.
A polytope is a d-dim object consisting of a set of nodes (vertices) and connections between them (edges) saved in self.G (graph).
The basic polytope will be created when the object is initiated. All further divisions should be performed with the function self.divide_edges()
- Args:
d: number of dimensions is_quat: does the object represent quaternions (meaning that q and -q points are treated as equal)
- __init__()
A polytope is a d-dim object consisting of a set of nodes (vertices) and connections between them (edges) saved in self.G (graph).
The basic polytope will be created when the object is initiated. All further divisions should be performed with the function self.divide_edges()
- Args:
d: number of dimensions is_quat: does the object represent quaternions (meaning that q and -q points are treated as equal)
- divide_edges()
Subdivide once. If previous faces are triangles, adds one point at mid-point of each edge. If they are squares, adds one point at mid-point of each edge + 1 in the middle of the face. New points will have a higher level attribute.
- class molgri.space.polytopes.Cube3DPolytope
In the beginning, each node is a vertex of a 3D cube + 6 vertices at mid-faces. It is possible to subdivide the sides, in that case a new point always appears in the middle of a square and half of previous sides.
A polytope is a d-dim object consisting of a set of nodes (vertices) and connections between them (edges) saved in self.G (graph).
The basic polytope will be created when the object is initiated. All further divisions should be performed with the function self.divide_edges()
- Args:
d: number of dimensions is_quat: does the object represent quaternions (meaning that q and -q points are treated as equal)
- __init__()
A polytope is a d-dim object consisting of a set of nodes (vertices) and connections between them (edges) saved in self.G (graph).
The basic polytope will be created when the object is initiated. All further divisions should be performed with the function self.divide_edges()
- Args:
d: number of dimensions is_quat: does the object represent quaternions (meaning that q and -q points are treated as equal)
- divide_edges()
Subdivide once by putting a new point at mid-point of each existing edge and replacing this sub-edge with two edges from the two old to the new point.
In sub-modules, additional edges may be added before performing divisions.
- molgri.space.polytopes.second_neighbours(graph: Graph, node)
Yield second neighbors of node in graph. Ignore second neighbours that are also first neighbours. Second neighbors may repeat!
Example:
First neighbours of 1: 2, 6, 3, 8 Second neighbours of 1: 5, 7
- molgri.space.polytopes.third_neighbours(graph: Graph, node)
Yield second neighbors of node in graph. Analogous to second neighbours, one more degree of separation
Example:
5——6 | | 2 —- 1 —- 3 —- 7 —- 9
11__8__10
First neighbours of 1: 2, 6, 3, 11 Second neighbours of 1: 5, 8, 10, 7 Third neighbours of 1: 9
- molgri.space.polytopes.detect_all_squares(graph: Graph) list
Each node of the graph is represented by 3- or 4-dimensional coordinates, meaning that distances and even angles to other nodes can be calculated. Squares can be formed by a combination of: a node, 2 neighbours and 1 second neighbour. Detect all such occurrences and return a list in which each row is a new set of 4 points forming a square.
- Args:
graph: Graph in which each node is represented by a tuple of numbers representing coordinates
- Returns:
a list, each item a set of 4 vertices that are guaranteed to form a square
- molgri.space.polytopes.detect_all_cubes(graph: Graph) list
See detect_all_squares, but now a cube consists of: a node, 3 direct neighbours, 3 second neighbours, 1 third neighbour.
- Args:
graph: Graph in which each node is represented by a tuple of numbers representing coordinates
- Returns:
a list, each item a set of 8 vertices that are guaranteed to form a cube