mirror of
https://gitlab.rlp.net/mobitar/ReCo.jl.git
synced 2024-11-08 22:21:08 +00:00
72 lines
1.7 KiB
Julia
72 lines
1.7 KiB
Julia
mutable struct Particle
|
|
id::Int64
|
|
|
|
c::SVector{2,Float64} # Center
|
|
tmp_c::SVector{2,Float64} # Temporary center
|
|
|
|
φ::Float64 # Angle
|
|
|
|
function Particle(id::Int64, c::SVector{2,Float64}, φ::Float64)
|
|
return new(id, c, c, φ)
|
|
end
|
|
end
|
|
|
|
function gen_tmp_particle()
|
|
return Particle(0, SVector(0.0, 0.0), 0.0)
|
|
end
|
|
|
|
function restrict_coordinate(value::Float64, half_box_len::Float64)
|
|
if value < -half_box_len
|
|
value += 2 * half_box_len
|
|
elseif value >= half_box_len
|
|
value -= 2 * half_box_len
|
|
end
|
|
|
|
return value
|
|
end
|
|
|
|
function restrict_coordinates(v::SVector{2,Float64}, half_box_len::Float64)
|
|
return SVector(
|
|
restrict_coordinate(v[1], half_box_len), restrict_coordinate(v[2], half_box_len)
|
|
)
|
|
end
|
|
|
|
function restrict_coordinates!(p::Particle, half_box_len::Float64)
|
|
p.tmp_c = restrict_coordinates(p.tmp_c, half_box_len)
|
|
|
|
return nothing
|
|
end
|
|
|
|
function minimum_image_coordinate(value::Float64, half_box_len::Float64)
|
|
if value <= -half_box_len
|
|
value += 2 * half_box_len
|
|
elseif value > half_box_len
|
|
value -= 2 * half_box_len
|
|
end
|
|
|
|
return value
|
|
end
|
|
|
|
function minimum_image(v::SVector{2,Float64}, half_box_len::Float64)
|
|
return SVector(
|
|
minimum_image_coordinate(v[1], half_box_len),
|
|
minimum_image_coordinate(v[2], half_box_len),
|
|
)
|
|
end
|
|
|
|
function are_overlapping(
|
|
c1::SVector{2,Float64},
|
|
c2::SVector{2,Float64},
|
|
overlapping_r²::Float64,
|
|
half_box_len::Float64,
|
|
)
|
|
r⃗₁₂ = c2 - c1 # 1 -> 2
|
|
|
|
r⃗₁₂ = minimum_image(r⃗₁₂, half_box_len)
|
|
|
|
distance² = r⃗₁₂[1]^2 + r⃗₁₂[2]^2
|
|
|
|
overlapping = distance² < overlapping_r²
|
|
|
|
return (; overlapping, r⃗₁₂, distance²)
|
|
end
|