glotzerlab / coxeter

Collection of tools to help initialize and manipulate shapes.
https://coxeter.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
22 stars 5 forks source link

Dual Shapes for Convex Polyhedra #1

Open bdice opened 7 years ago

bdice commented 7 years ago

Original report by RoseCers (Bitbucket: RoseCers, ).


b-butler commented 4 years ago

@bdice could you flesh this out potentially for the hackathon? I agree that this would be a good feature to have.

bdice commented 4 years ago

@b-butler Here's a starting point. This needs to be tested (with actual tests written) and visually inspected for a few known cases (tetrahedron ↔ tetrahedron, cube ↔ octahedron, dodecahedron ↔ icosahedron). I used the scipy.spatial.HalfspaceIntersection code (see here for docs).

Sample dual generator script

import numpy as np
import scipy.spatial

tetrahedron_vertices = [[0.5, 0.5, 0.5],
                        [-0.5, -0.5, 0.5],
                        [-0.5, 0.5, -0.5],
                        [0.5, -0.5, -0.5]]

hull = scipy.spatial.ConvexHull(tetrahedron_vertices)

print(f'Convex Hull Vertices:\n{hull.points}')
print(f'Convex Hull Volume: {hull.volume}')
print(f'Convex Hull Equations:\n{hull.equations}')

dual = scipy.spatial.HalfspaceIntersection(
    halfspaces=hull.equations, interior_point=np.zeros(3))

print(f'Dual Vertices:\n{dual.dual_points}')
print(f'Dual Surface Area: {dual.dual_area}')
print(f'Dual Volume: {dual.dual_volume}')
print(f'Dual Equations:\n{dual.dual_equations}')
print(f'Dual Facets: {dual.dual_facets}')

Sample dual output

Convex Hull Vertices:
[[ 0.5  0.5  0.5]
 [-0.5 -0.5  0.5]
 [-0.5  0.5 -0.5]
 [ 0.5 -0.5 -0.5]]
Convex Hull Volume: 0.3333333333333334
Convex Hull Equations:
[[-0.57735027  0.57735027  0.57735027 -0.28867513]
 [ 0.57735027 -0.57735027  0.57735027 -0.28867513]
 [-0.57735027 -0.57735027 -0.57735027 -0.28867513]
 [ 0.57735027  0.57735027 -0.57735027 -0.28867513]]
Dual Vertices:
[[-2.  2.  2.]
 [ 2. -2.  2.]
 [-2. -2. -2.]
 [ 2.  2. -2.]]
Dual Surface Area: 55.425625842204084
Dual Volume: 21.33333333333334
Dual Equations:
[[-0.57735027 -0.57735027  0.57735027 -1.15470054]
 [ 0.57735027  0.57735027  0.57735027 -1.15470054]
 [-0.57735027  0.57735027 -0.57735027 -1.15470054]
 [ 0.57735027 -0.57735027 -0.57735027 -1.15470054]]
Dual Facets: [[2, 1, 0], [3, 1, 0], [3, 2, 0], [3, 2, 1]]

Additional references:

b-butler commented 4 years ago

@bdice thanks!