How to plot a 5D Polytope using Python?

136 Views Asked by At

5D Polytopes play an interesting role in physics (string theory, see for example Modularity of strings on F-theory backgrounds).

There is a paper A completely unambiguous 5-polyhedral graph giving an idea how to plot such 5D polytopes.

My idea was to use a projection from 5D into 3D space, inspired by this post (SO) and this post (MSE):

import numpy as np
import plotly.graph_objects as go
from scipy.spatial import ConvexHull

V = np.array([[-1,0,1,1,-1], [0,1,-1,-1,1], [0,-3,-1,1,0], [-1,0,0,-1,0], [-1,1,-1,-1,1], [0,-1,1,1,0], [0,0,0,-1,0]])

def nsphere(mat, littleD=3):
    projected_mat = np.empty([0, 3])
    for a in mat:
        a = a / np.sqrt(np.dot(a, a))
        z = a[littleD:].sum()
        projected_mat = np.append(projected_mat, np.array([a[:littleD] / (1. - z)]), axis=0)
    return projected_mat

V = nsphere(V)

hull = ConvexHull(V)
hull_points = hull.points
hull_simplices = hull.simplices

x = hull_points[:, 0]
y = hull_points[:, 1]
z = hull_points[:, 2]

i = hull_simplices[:, 0]
j = hull_simplices[:, 1]
k = hull_simplices[:, 2]

mesh3d  = go.Mesh3d(x=x, y=y, z=z, i=i, j=j, k=k, opacity=1.0, flatshading=True, color="#ce6a6b")
layout = go.Layout(width=600, height=600, title_text='polytope', title_x=0.5)
fig = go.Figure(data=[mesh3d], layout=layout)
fig.layout.scene.update(xaxis_showticklabels=False, xaxis_ticks='', xaxis_title='',
                        yaxis_showticklabels=False, yaxis_ticks='',yaxis_title='',
                        zaxis_showticklabels=False, zaxis_ticks='', zaxis_title='')
fig.data[0].update(lighting=dict(ambient=0.5, diffuse=1, fresnel=4, specular=0.5, roughness=0.5))

fig.show()

As a result I get the following plot:

enter image description here

Question: How can I make the interaction (rotation) 5-dimensional such as shown in this video? It means that I have to tell the visualization framework that at each rotation the projection from (5D to 3D) has to be repeated.

I would be very grateful for any advice on how I can visualize 5D polytopes with python frameworks (ideally using the given example [[-1,0,1,1,-1], [0,1,-1,-1,1], [0,-3,-1,1,0], [-1,0,0,-1,0], [-1,1,-1,-1,1], [0,-1,1,1,0], [0,0,0,-1,0]]).

0

There are 0 best solutions below