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

56 lines
1.3 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-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
2022-01-27 17:48:25 +00:00
r⃗₁₂ = restrict_coordinates(r⃗₁₂, half_box_len)
2021-11-10 14:41:04 +00:00
2022-01-11 17:39:38 +00:00
distance² = sq_norm2d(r⃗₁₂)
2021-11-10 14:41:04 +00:00
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