Open bdice opened 7 years ago
@bdice could you flesh this out potentially for the hackathon? I agree that this would be a good feature to have.
@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).
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}')
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:
@bdice thanks!
Original report by RoseCers (Bitbucket: RoseCers, ).