Function Repository Resource:

GyrationTensor

Source Notebook

Compute the gyration tensor and derived metrics quantifying the shape of particle distributions

Contributed by: Nicholas E. Brunk, Wolfram|Alpha Math Team

ResourceFunction["GyrationTensor"][{p1,p2,}]

returns the gyration tensor of points {p1,p2,}.

ResourceFunction["GyrationTensor"][{p1,p2,},type]

returns the derived metric specified via type.

Details

ResourceFunction["GyrationTensor"] allows points {p1,p2,}of any consistent dimensionality n.
Metric type availability depends upon the dimensionality of the coordinates in n:
Dimension ntype
any"ResourceFunction["GyrationTensor"]", "RadiusOfGyration", "Eigenvalues"
2"Acircularity", "NormalizedAcircularity"
3"Asphericity", "NormalizedAsphericity", "RelativeAnisotropy"
>3"HyperAsphericity", "NormalizedHyperAsphericity"

Examples

Basic Examples (1) 

By default, GyrationTensor returns the tensor itself:

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

Scope (2) 

Other metrics derived from the gyration tensor may be computed:

In[2]:=
ResourceFunction[
 "GyrationTensor"][{{0, 0, 0}, {1, 0, 0}}, "Asphericity"]
Out[2]=

Metrics may be computed in other dimensions, for example 2D and 4D, respectively:

In[3]:=
ResourceFunction["GyrationTensor"][{{0, 0}, {1, 0}}, "Acircularity"]
Out[3]=
In[4]:=
ResourceFunction[
 "GyrationTensor"][{{0, 0, 0, 0}, {1, 0, 0, 0}}, "HyperAsphericity"]
Out[4]=

Properties and Relations (2) 

The metrics "NormalizedAsphericity" and "RelativeAnisotropy" have the same limiting behavior in describing spherically symmetric vs. linear distributions:

In[5]:=
ResourceFunction[
 "GyrationTensor"][{{0, 0, 0}, {1, 0, 0}}, "NormalizedAsphericity"]
Out[5]=
In[6]:=
ResourceFunction[
 "GyrationTensor"][{{0, 0, 0}, {1, 0, 0}}, "RelativeAnisotropy"]
Out[6]=

These metrics do, however, differ in non-limiting cases:

In[7]:=
ResourceFunction[
 "GyrationTensor"][{{0, 0, 0}, {0, 1, 0}, {1, 0, 0}}, "NormalizedAsphericity"]
Out[7]=
In[8]:=
ResourceFunction[
 "GyrationTensor"][{{0, 0, 0}, {0, 1, 0}, {1, 0, 0}}, "RelativeAnisotropy"]
Out[8]=

Possible Issues (2) 

Available metrics are determined by the dimensions of the input vectors, such that "Acircularity"—a 2D metric—is not computed for 3D:

In[9]:=
coords = {{0, 0, 0}, {1, 0, 0}};
ResourceFunction["GyrationTensor"][coords, "Acircularity"]
Out[9]=

A given dimension can be omitted to check symmetry in the remaining fewer dimensions:

In[10]:=
ResourceFunction["GyrationTensor"][
 Take[#, 2] & /@ coords, "Acircularity"]
Out[10]=

Non-normalized metrics scale with the size of the distribution:

In[11]:=
ResourceFunction["GyrationTensor"][{{0, 0}, {1, 0}}, "Acircularity"]
Out[11]=
In[12]:=
ResourceFunction["GyrationTensor"][{{0, 0}, {100, 0}}, "Acircularity"]
Out[12]=

Normalized equivalents do not and are scaled between 0 and 1:

In[13]:=
ResourceFunction[
 "GyrationTensor"][{{0, 0}, {1, 0}}, "NormalizedAcircularity"]
Out[13]=
In[14]:=
ResourceFunction[
 "GyrationTensor"][{{0, 0}, {100, 0}}, "NormalizedAcircularity"]
Out[14]=

Neat Examples (8) 

Closely approximate the radius of gyration of a given 2D region, for example, reproducing known quantities such as a hoop (unit circle):

In[15]:=
coords = RandomPoint[ImplicitRegion[x^2 + y^2 == 1, {x, y}], 300];
Graphics3D[{Point[coords /. {x_, y_} :> {x, y, 0}]}]
Out[15]=
In[16]:=
ResourceFunction["GyrationTensor"][coords, "RadiusOfGyration"]
Out[16]=

The same works for a hollow, 3D unit sphere:

In[17]:=
coords = SpherePoints[30];
Graphics3D[{{Opacity[0.5], Sphere[]}, Point[coords], {Thickness[0.005], Line[{{0, 0, 0}, {1, 0, 0}}]}}]
Out[17]=

The hollow sphere has a known radius of gyration Rg=R=1, which can be approximated (quite accurately, given the SpherePoints function):

In[18]:=
ResourceFunction["GyrationTensor"][coords, "RadiusOfGyration"]
Out[18]=

The same works for a solid, 3D unit sphere, using ImplicitRegion:

In[19]:=
coords = RandomPoint[ImplicitRegion[x^2 + y^2 + z^2 <= 1, {x, y, z}], 30000];
Graphics3D[{{Opacity[0.5], Sphere[]}, Point[coords], {Thickness[0.005], Line[{{0, 0, 0}, {1, 0, 0}}]}}]
Out[19]=

The solid sphere has a known radius of gyration :

In[20]:=
ResourceFunction["GyrationTensor"][coords, "RadiusOfGyration"]
Out[20]=

The intermediate result of a hollow spherical shell of a given thickness may also be estimated, using ImplicitRegion:

In[21]:=
\[ScriptCapitalR] = ImplicitRegion[.75 <= x^2 + y^2 + z^2 <= 1, {x, y, z}];
coords = RandomPoint[\[ScriptCapitalR], 300];
Show[RegionPlot3D[\[ScriptCapitalR], PlotStyle -> Opacity[0.5], PlotPoints -> 50], Graphics3D[
  Point[coords], {Thickness[0.005], Line[{{0, 0, 0}, +{1, 0, 0}}]}]]
Out[21]=

The radius of gyration may be estimated:

In[22]:=
ResourceFunction["GyrationTensor"][coords, "RadiusOfGyration"]
Out[22]=

This result can be verified, in that it converges on the previous answer for the perfectly hollow unit sphere as thickness t0:

In[23]:=
\[ScriptCapitalR] = ImplicitRegion[.99 <= x^2 + y^2 + z^2 <= 1, {x, y, z}];
coords = RandomPoint[\[ScriptCapitalR], 300];

ResourceFunction["GyrationTensor"][coords, "RadiusOfGyration"]
Out[23]=

The same works for a solid, 3D cylinder, e.g. with unit radius and length, for which a Region may be defined from a pre-existing graphics primitive:

In[24]:=
\[ScriptCapitalR] = Region@Cylinder[{{0, 0, 0}, {0, 0, 1}}];
coords = RandomPoint[\[ScriptCapitalR], 30000];
Show[RegionPlot3D[\[ScriptCapitalR], PlotStyle -> Opacity[0.5], PlotPoints -> 50], Graphics3D[
  Point[coords], {Thickness[0.005], Line[{{0, 0, 0}, +{1, 0, 0}}]}], AspectRatio -> 1]
Out[24]=

A solid cylinder has a known radius of gyration :

In[25]:=
ResourceFunction["GyrationTensor"][coords, "RadiusOfGyration"]
Out[25]=

Estimate the radius of gyration of a rabbit from ExampleData:

In[26]:=
\[ScriptCapitalR] = ExampleData[{"Geometry3D", "StanfordBunny"}, "Region"];
coords = RandomPoint[\[ScriptCapitalR], 30000];
Show[\[ScriptCapitalR], Graphics3D[{Point[coords]}], Boxed -> True]
Out[26]=

Note that this is a hollow rabbit, so it is more relevant to the Easter chocolate shell version than a live rabbit:

In[27]:=
ResourceFunction["GyrationTensor"][coords, "RadiusOfGyration"]
Out[27]=

Shape metrics derived from the gyration tensor may be used to characterize the shape of a random walk. An unbiased random walk will generally have lower normalized asphericity than a biased random walk:

In[28]:=
coordsUnbiased = N@Transpose[
    RandomFunction[RandomWalkProcess[0.5], {0, 500}, 3][
     "ValueList"]];
coordsBiased = N@Transpose[
    RandomFunction[RandomWalkProcess[0.75], {0, 500}, 3]["ValueList"]];

Graphics3D[{Line[coordsUnbiased], {Green, Line[coordsBiased]}}, BoxRatios -> Automatic]
Out[28]=

The unbiased walk (black) is much more spherically symmetric than the predominantly linear, biased random walk (green):

In[29]:=
ResourceFunction["GyrationTensor"][#, "NormalizedAsphericity"] & /@ {coordsUnbiased, coordsBiased}
Out[29]=

The relative anisotropy may be used to show that caffeine is a less linear molecule than THC:

In[30]:=
Grid[Transpose[{#, ResourceFunction["GyrationTensor"][
      QuantityMagnitude /@ ChemicalData[#, "AtomPositions"], "RelativeAnisotropy"], ChemicalData[#, "MoleculePlot"]} & /@ {"Caffeine", "Tetrahydrocannabinol"}], Frame -> All]
Out[30]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 2.0.0 – 23 March 2023
  • 1.0.1 – 16 March 2021
  • 1.0.0 – 18 September 2020

Source Metadata

Related Resources

Author Notes

To view the source code for this function, evaluate the following:

License Information