From ea1d06e02b7e5c92c94871267a4db2dc95843a90 Mon Sep 17 00:00:00 2001 From: MoBit Date: Fri, 3 Dec 2021 14:41:01 +0100 Subject: [PATCH] gyration_tensor --- src/shape.jl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/shape.jl b/src/shape.jl index fbfc09b..084a88b 100644 --- a/src/shape.jl +++ b/src/shape.jl @@ -1,4 +1,4 @@ -using StaticArrays: SVector +using StaticArrays: SVector, SMatrix function project_to_unit_circle(x, l) φ = (x + l) * π / l @@ -42,4 +42,24 @@ function center_of_mass(args) project_back_from_unit_circle(x_θ, args.l), project_back_from_unit_circle(y_θ, args.l), ) +end + +function gyration_tensor(args) + COM = center_of_mass(args) + + S11 = 0.0 + S12 = 0.0 + S22 = 0.0 + + for p in args.particles + c = p.c + x = c[1] - COM[1] + y = c[2] - COM[2] + + S11 += x^2 + S12 += x * y + S22 += y^2 + end + + return SMatrix{2,2}(S11, S12, S12, S22) end \ No newline at end of file