Random IVM Tetrahedron Volumes

According to a proof by Dr. Robert Gray, at one time archived on a Synergetics listserv, any tetrahedron of IVM vertexes (assuming non-coplanar) will have a whole number volume.

In this Notebook, we randomly generate IVM tetrahedrons and compute their volumes. Within the error of floating point, we demonstrate this result.

In :
from tetravolume import Qvector

In :
from itertools import permutations

In :
combos = set()
for combo in permutations((0,1,1,2)):
combos = list(combos)
combos

Out:
[(0, 1, 1, 2),
(1, 2, 0, 1),
(0, 2, 1, 1),
(0, 1, 2, 1),
(2, 1, 0, 1),
(1, 1, 2, 0),
(1, 2, 1, 0),
(2, 1, 1, 0),
(1, 0, 2, 1),
(2, 0, 1, 1),
(1, 0, 1, 2),
(1, 1, 0, 2)]

One frequency:

In :
import random

def any_ball():
# random coefficients for arbitrary choice of vectors...
coeffs = [random.randint(0, 300) for _ in range(12)]
vectors = ([coeffs[i] * Qvector(combos[i]) for i in range(12)])
vector_sum = Qvector((0,0,0,0))
for v in vectors:
vector_sum = vector_sum + v
return vector_sum

any_ball()

Out:
ivm_vector(a=365, b=159, c=336, d=0)

In :
A,B,C,D = any_ball(), any_ball(), any_ball(), any_ball()

In :
lengths = [("AB", (A-B).length()),
("AC", (A-C).length()),
("BC", (B-C).length()),
("CD", (C-D).length()),
("DB", (D-B).length())]

In :
lengths

Out:
[('AB', 373.0321701944753),
('AC', 333.39616074574104),
('BC', 534.9635501601955),
('CD', 544.9155897935019),
('DB', 280.3194606159194)]

In :
from tetravolume import Tetrahedron

In :
t = Tetrahedron(*[lengths[i] for i in range(6)])

In :
t.ivm_volume()

Out:
44190451.00000004

In :
def demo():
A,B,C,D = any_ball(), any_ball(), any_ball(), any_ball()
lengths = [("AB", (A-B).length()),
("AC", (A-C).length()),
("BC", (B-C).length()),
("CD", (C-D).length()),
("DB", (D-B).length())]
t = Tetrahedron(*[lengths[i] for i in range(6)])
return t.ivm_volume()

demo()

Out:
14170140.999999965

In :
t.xyz_volume()

Out:
41663156.754389174

In :