2022-09-25 15:54:46 +02:00
|
|
|
using StaticArrays: SVector
|
|
|
|
|
2021-11-10 15:41:04 +01:00
|
|
|
mutable struct Particle
|
|
|
|
id::Int64
|
2021-11-26 03:35:39 +01:00
|
|
|
|
2021-12-07 05:52:10 +01:00
|
|
|
c::SVector{2,Float64} # Center
|
|
|
|
tmp_c::SVector{2,Float64} # Temporary center
|
2021-11-10 15:41:04 +01:00
|
|
|
|
|
|
|
φ::Float64 # Angle
|
|
|
|
|
2021-12-07 05:52:10 +01:00
|
|
|
function Particle(id::Int64, c::SVector{2,Float64}, φ::Float64)
|
|
|
|
return new(id, c, c, φ)
|
2021-11-10 15:41:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-12 18:27:56 +01:00
|
|
|
function gen_tmp_particle()
|
|
|
|
return Particle(0, SVector(0.0, 0.0), 0.0)
|
|
|
|
end
|
|
|
|
|
2021-12-10 03:16:18 +01:00
|
|
|
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
|
2021-11-10 15:41:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return value
|
|
|
|
end
|
|
|
|
|
2021-12-15 04:45:15 +01:00
|
|
|
function restrict_coordinates(v::SVector{2,Float64}, half_box_len::Float64)
|
2021-12-10 03:16:18 +01:00
|
|
|
return SVector(
|
|
|
|
restrict_coordinate(v[1], half_box_len), restrict_coordinate(v[2], half_box_len)
|
|
|
|
)
|
2021-12-08 21:53:15 +01:00
|
|
|
end
|
|
|
|
|
2021-12-10 03:16:18 +01:00
|
|
|
function restrict_coordinates!(p::Particle, half_box_len::Float64)
|
2021-12-15 04:45:15 +01:00
|
|
|
p.tmp_c = restrict_coordinates(p.tmp_c, half_box_len)
|
2021-11-10 15:41:04 +01:00
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|
|
|
|
|
2021-12-08 21:53:15 +01:00
|
|
|
function are_overlapping(
|
2021-12-10 03:16:18 +01:00
|
|
|
c1::SVector{2,Float64},
|
|
|
|
c2::SVector{2,Float64},
|
|
|
|
overlapping_r²::Float64,
|
|
|
|
half_box_len::Float64,
|
2021-12-08 21:53:15 +01:00
|
|
|
)
|
|
|
|
r⃗₁₂ = c2 - c1 # 1 -> 2
|
2021-11-10 15:41:04 +01:00
|
|
|
|
2022-01-27 18:48:25 +01:00
|
|
|
r⃗₁₂ = restrict_coordinates(r⃗₁₂, half_box_len)
|
2021-11-10 15:41:04 +01:00
|
|
|
|
2022-01-11 18:39:38 +01:00
|
|
|
distance² = sq_norm2d(r⃗₁₂)
|
2021-11-10 15:41:04 +01:00
|
|
|
|
2021-11-17 19:47:05 +01:00
|
|
|
overlapping = distance² < overlapping_r²
|
|
|
|
|
|
|
|
return (; overlapping, r⃗₁₂, distance²)
|
2021-11-10 15:41:04 +01:00
|
|
|
end
|