2021-12-16 12:50:38 +00:00
|
|
|
module Geometry
|
|
|
|
|
2022-01-11 17:39:38 +00:00
|
|
|
export angle2, norm2d, sq_norm2d
|
2021-12-16 12:50:38 +00:00
|
|
|
|
|
|
|
using StaticArrays: SVector
|
|
|
|
|
2021-12-16 13:54:52 +00:00
|
|
|
"""
|
2022-01-18 01:17:52 +00:00
|
|
|
angle2(a::SVector{2,Real}, b::SVector{2,Real})
|
2021-12-16 13:54:52 +00:00
|
|
|
|
|
|
|
Returns the angle φ from vector a to b while φ ∈ [-π, π].
|
|
|
|
"""
|
2022-01-18 01:17:52 +00:00
|
|
|
function angle2(a::SVector{2,Real}, b::SVector{2,Real})
|
2021-12-16 12:50:38 +00:00
|
|
|
θ_a = atan(a[2], a[1])
|
|
|
|
θ_b = atan(b[2], b[1])
|
|
|
|
|
|
|
|
θ = θ_b - θ_a
|
|
|
|
|
|
|
|
return rem2pi(θ, RoundNearest)
|
|
|
|
end
|
|
|
|
|
2022-01-18 01:17:52 +00:00
|
|
|
function sq_norm2d(v::SVector{2,Real})
|
|
|
|
return v[1]^2 + v[2]^2
|
|
|
|
end
|
|
|
|
|
|
|
|
function norm2d(v::SVector{2,Real})
|
|
|
|
return sqrt(sq_norm2d(v))
|
|
|
|
end
|
2022-01-11 17:39:38 +00:00
|
|
|
|
2021-12-16 12:50:38 +00:00
|
|
|
end # module
|