1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-11-12 22:40:44 +00:00
ReCo.jl/src/Particle.jl

73 lines
1.7 KiB
Julia
Raw Normal View History

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-12 17:27:56 +00:00
function gen_tmp_particle()
return Particle(0, SVector(0.0, 0.0), 0.0)
end
2021-12-10 02:16:18 +00: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 14:41:04 +00:00
end
return value
end
2021-12-15 03:45:15 +00:00
function restrict_coordinates(v::SVector{2,Float64}, half_box_len::Float64)
2021-12-10 02:16:18 +00:00
return SVector(
restrict_coordinate(v[1], half_box_len), restrict_coordinate(v[2], half_box_len)
)
2021-12-08 20:53:15 +00:00
end
2021-12-10 02:16:18 +00:00
function restrict_coordinates!(p::Particle, half_box_len::Float64)
2021-12-15 03:45:15 +00:00
p.tmp_c = restrict_coordinates(p.tmp_c, half_box_len)
2021-11-10 14:41:04 +00:00
return nothing
end
2021-12-10 02:16:18 +00:00
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
2021-11-10 14:41:04 +00:00
end
return value
end
2021-12-10 02:16:18 +00:00
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),
)
2021-11-10 14:41:04 +00:00
end
2021-12-08 20:53:15 +00:00
function are_overlapping(
2021-12-10 02:16:18 +00:00
c1::SVector{2,Float64},
c2::SVector{2,Float64},
overlapping_r²::Float64,
half_box_len::Float64,
2021-12-08 20:53:15 +00:00
)
r⃗₁₂ = c2 - c1 # 1 -> 2
2021-11-10 14:41:04 +00:00
2021-12-10 02:16:18 +00:00
r⃗₁₂ = minimum_image(r⃗₁₂, half_box_len)
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