2021-12-02 22:13:54 +00:00
|
|
|
using StaticArrays: SVector
|
|
|
|
|
2021-11-10 14:41:04 +00:00
|
|
|
mutable struct Particle
|
|
|
|
id::Int64
|
2021-11-26 02:35:39 +00:00
|
|
|
|
2021-12-07 04:52:10 +00:00
|
|
|
c::SVector{2,Float64} # Center
|
|
|
|
tmp_c::SVector{2,Float64} # Temporary center
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
|
|
φ::Float64 # Angle
|
|
|
|
|
2021-12-07 04:52:10 +00:00
|
|
|
function Particle(id::Int64, c::SVector{2,Float64}, φ::Float64)
|
|
|
|
return new(id, c, c, φ)
|
2021-11-10 14:41:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-07 00:36:47 +00:00
|
|
|
function restrict_coordinate(value::Float64, l::Float64)
|
2021-11-10 14:41:04 +00:00
|
|
|
if value < -l
|
|
|
|
value += 2 * l
|
|
|
|
elseif value >= l
|
|
|
|
value -= 2 * l
|
|
|
|
end
|
|
|
|
|
|
|
|
return value
|
|
|
|
end
|
|
|
|
|
2021-12-08 20:53:15 +00:00
|
|
|
function restrict_coordinates!(v::SVector{2,Float64}, l::Float64)
|
|
|
|
return SVector(restrict_coordinate(v[1], l), restrict_coordinate(v[2], l))
|
|
|
|
end
|
|
|
|
|
2021-12-07 00:36:47 +00:00
|
|
|
function restrict_coordinates!(p::Particle, l::Float64)
|
2021-12-08 20:53:15 +00:00
|
|
|
p.tmp_c = restrict_coordinates!(p.tmp_c, l)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|
|
|
|
|
2021-12-07 00:36:47 +00:00
|
|
|
function minimum_image_coordinate(value::Float64, l::Float64)
|
2021-11-10 14:41:04 +00:00
|
|
|
if value <= -l
|
|
|
|
value += 2 * l
|
|
|
|
elseif value > l
|
|
|
|
value -= 2 * l
|
|
|
|
end
|
|
|
|
|
|
|
|
return value
|
|
|
|
end
|
|
|
|
|
2021-12-07 00:36:47 +00:00
|
|
|
function minimum_image(v::SVector{2,Float64}, l::Float64)
|
2021-12-08 20:53:15 +00:00
|
|
|
return SVector(minimum_image_coordinate(v[1], l), minimum_image_coordinate(v[2], l))
|
2021-11-10 14:41:04 +00:00
|
|
|
end
|
|
|
|
|
2021-12-08 20:53:15 +00:00
|
|
|
function are_overlapping(
|
|
|
|
c1::SVector{2,Float64}, c2::SVector{2,Float64}, overlapping_r²::Float64, l::Float64
|
|
|
|
)
|
|
|
|
r⃗₁₂ = c2 - c1 # 1 -> 2
|
2021-11-10 14:41:04 +00:00
|
|
|
|
2021-12-07 00:36:47 +00:00
|
|
|
r⃗₁₂ = minimum_image(r⃗₁₂, l)
|
2021-11-10 14:41:04 +00:00
|
|
|
|
|
|
|
distance² = r⃗₁₂[1]^2 + r⃗₁₂[2]^2
|
|
|
|
|
2021-11-17 18:47:05 +00:00
|
|
|
overlapping = distance² < overlapping_r²
|
|
|
|
|
|
|
|
return (; overlapping, r⃗₁₂, distance²)
|
2021-11-10 14:41:04 +00:00
|
|
|
end
|