1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-12-21 00:51:21 +00:00

Center of mass of centers

This commit is contained in:
Mo8it 2021-12-28 17:13:31 +01:00
parent 983c411b85
commit 775944c872

View file

@ -18,15 +18,9 @@ function project_back_from_unit_circle(θ::T, half_box_len::Float64) where {T<:R
return restrict_coordinate(x, half_box_len) return restrict_coordinate(x, half_box_len)
end end
function center_of_mass(particles::Vector{Particle}, half_box_len::Float64) function center_of_mass_from_proj_sums(
x_proj_sum = SVector(0.0, 0.0) x_proj_sum::SVector{2,Float64}, y_proj_sum::SVector{2,Float64}, half_box_len::Float64
y_proj_sum = SVector(0.0, 0.0) )
for p in particles
x_proj_sum += project_to_unit_circle(p.c[1], half_box_len)
y_proj_sum += project_to_unit_circle(p.c[2], half_box_len)
end
# Prevent for example atan(1e-16, 1e-15) != 0 with rounding # Prevent for example atan(1e-16, 1e-15) != 0 with rounding
digits = 5 digits = 5
@ -50,6 +44,30 @@ function center_of_mass(particles::Vector{Particle}, half_box_len::Float64)
return SVector(COM_x, COM_y) return SVector(COM_x, COM_y)
end end
function center_of_mass(centers::AbstractVector{SVector{2,Float64}}, half_box_len::Float64)
x_proj_sum = SVector(0.0, 0.0)
y_proj_sum = SVector(0.0, 0.0)
for c in centers
x_proj_sum += project_to_unit_circle(c[1], half_box_len)
y_proj_sum += project_to_unit_circle(c[2], half_box_len)
end
return center_of_mass_from_proj_sums(x_proj_sum, y_proj_sum, half_box_len)
end
function center_of_mass(particles::Vector{Particle}, half_box_len::Float64)
x_proj_sum = SVector(0.0, 0.0)
y_proj_sum = SVector(0.0, 0.0)
for p in particles
x_proj_sum += project_to_unit_circle(p.c[1], half_box_len)
y_proj_sum += project_to_unit_circle(p.c[2], half_box_len)
end
return center_of_mass_from_proj_sums(x_proj_sum, y_proj_sum, half_box_len)
end
function gyration_tensor(particles::Vector{Particle}, half_box_len::Float64) function gyration_tensor(particles::Vector{Particle}, half_box_len::Float64)
COM = center_of_mass(particles, half_box_len) COM = center_of_mass(particles, half_box_len)