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:
parent
983c411b85
commit
775944c872
1 changed files with 27 additions and 9 deletions
36
src/Shape.jl
36
src/Shape.jl
|
@ -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)
|
||||
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
|
||||
|
||||
function center_of_mass_from_proj_sums(
|
||||
x_proj_sum::SVector{2,Float64}, y_proj_sum::SVector{2,Float64}, half_box_len::Float64
|
||||
)
|
||||
# Prevent for example atan(1e-16, 1e-15) != 0 with rounding
|
||||
digits = 5
|
||||
|
||||
|
@ -50,6 +44,30 @@ function center_of_mass(particles::Vector{Particle}, half_box_len::Float64)
|
|||
return SVector(COM_x, COM_y)
|
||||
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)
|
||||
COM = center_of_mass(particles, half_box_len)
|
||||
|
||||
|
|
Loading…
Reference in a new issue