Wolfram Research

Function Repository Resource:

CayleyMengerMatrix

Source Notebook

Evaluate the Cayley-Menger matrix of a simplex

Contributed by: Jan Mangaldan

ResourceFunction["CayleyMengerMatrix"][{p1,,pk}]

gives the Cayley-Menger matrix of the simplex spanned by points pi.

ResourceFunction["CayleyMengerMatrix"][reg]

gives the Cayley-Menger matrix of the region reg.

Details

The Cayley-Menger matrix of a simplex is the matrix of squared distances between each pair of vertices of the simplex, bordered by 1s at left and on top, and 0 in the upper left corner.
For ResourceFunction["CayleyMengerMatrix"][reg], reg can be any valid Triangle, Tetrahedron or Simplex.

Examples

Basic Examples (2) 

The Cayley-Menger matrix of a triangle represented as a list of its vertices:

In[1]:=
ResourceFunction[
  "CayleyMengerMatrix"][{{0, 0}, {11/10, 1}, {3/2, 0}}] // MatrixForm
Out[1]=

The Cayley-Menger matrix of a Triangle:

In[2]:=
ResourceFunction["CayleyMengerMatrix"][
  Triangle[{{0, 0}, {11/10, 1}, {3/2, 0}}]] // MatrixForm
Out[2]=

Scope (3) 

The Cayley-Menger matrix of a tetrahedron, specified by its vertex list:

In[3]:=
ResourceFunction[
  "CayleyMengerMatrix"][{{0, 0, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 1}}] // MatrixForm
Out[3]=

The Cayley-Menger matrix of a tetrahedron, specified as a Tetrahedron:

In[4]:=
ResourceFunction["CayleyMengerMatrix"][
  Tetrahedron[{{0, 0, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 1}}]] // MatrixForm
Out[4]=

The Cayley-Menger matrix of a tetrahedron, specified as a Simplex:

In[5]:=
ResourceFunction["CayleyMengerMatrix"][
  Simplex[{{0, 0, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 1}}]] // MatrixForm
Out[5]=

Applications (3) 

Use the Cayley-Menger matrix to evaluate the content of a simplex:

In[6]:=
simplexContent[reg_] := Module[{mat = ResourceFunction["CayleyMengerMatrix"][reg], d}, d = Length[mat] - 2; Sqrt[Abs[Det[mat]/(d! (2 d)!!)]]]

Compute the area of a triangle:

In[7]:=
tri = Triangle[{{0, 0}, {1, 2}, {2, 1}}];
{simplexContent[tri], Area[tri]}
Out[7]=

Compute the volume of a tetrahedron:

In[8]:=
tet = Tetrahedron[{{1, 0, 0}, {1, 0, 1}, {1, 1, 1}, {0, 0, 1}}];
{simplexContent[tet], Volume[tet]}
Out[8]=

Compute the content of a four-dimensional simplex:

In[9]:=
smp = Simplex[{{0, 0, 0, 0}, {1, 0, 0, 0}, {1, 1, 0, 0}, {1, 1, 1, 0}, {1, 1, 1, 1}}];
{simplexContent[smp], RegionMeasure[smp]}
Out[9]=

Use the Cayley-Menger matrix to obtain the circumsphere of a simplex:

In[10]:=
circumsphere[reg_] := Module[{cv, icm},
  icm = -2 Inverse[ResourceFunction["CayleyMengerMatrix"][reg]]; cv = icm[[1, 2 ;;]];
  {cv . First[reg]/Total[cv], First[Sqrt[Diagonal[icm]]]/2}]

Circumcenter and circumradius of a triangle:

In[11]:=
tri = Triangle[{{0, 0}, {1, 2}, {2, 1}}];
In[12]:=
circumsphere[tri]
Out[12]=

Compare with the result of Circumsphere:

In[13]:=
List @@ Circumsphere[tri]
Out[13]=

Circumcenter and circumradius of a tetrahedron:

In[14]:=
tet = Tetrahedron[{{1, 0, 0}, {1, 0, 1}, {1, 1, 1}, {0, 0, 1}}];
In[15]:=
circumsphere[tet]
Out[15]=

Compare with the result of Circumsphere:

In[16]:=
List @@ Circumsphere[tet]
Out[16]=

Use the Cayley-Menger matrix to obtain the insphere of a simplex:

In[17]:=
insphere[reg_] := Module[{iv},
  iv = Rest[
    Sqrt[Diagonal[-2 Inverse[
        ResourceFunction["CayleyMengerMatrix"][reg]]]]];
  {iv . First[reg], 1}/Total[iv]]

Incenter and inradius of a triangle:

In[18]:=
tri = Triangle[{{0, 0}, {1, 2}, {2, 1}}];
In[19]:=
insphere[tri] // RootReduce
Out[19]=

Compare with the result of Insphere

In[20]:=
List @@ Insphere[tri] // RootReduce
Out[20]=

Incenter and inradius of a tetrahedron:

In[21]:=
tet = Tetrahedron[{{1, 0, 0}, {1, 0, 1}, {1, 1, 1}, {0, 0, 1}}];
In[22]:=
insphere[tet] // FullSimplify
Out[22]=

Compare with the result of Insphere:

In[23]:=
List @@ Insphere[tet] // FullSimplify
Out[23]=

Properties and Relations (1) 

The Cayley-Menger matrix is symmetric:

In[24]:=
SymmetricMatrixQ[
 ResourceFunction["CayleyMengerMatrix"][
  Simplex[{{0, 0, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 1}}]]]
Out[24]=

Resource History

Source Metadata

Related Resources

License Information