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