1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-12-21 00:51:21 +00:00
ReCo.jl/src/Geometry.jl
2022-03-19 23:11:03 +01:00

29 lines
588 B
Julia

module Geometry
export angle2, norm2d, sq_norm2d
using StaticArrays: SVector
"""
angle2(a::SVector{2,R}, b::SVector{2,R}) where {R<:Real}
Return the angle `φ` from vector `a` to `b` while `φ` ∈ [-π, π].
"""
function angle2(a::SVector{2,R}, b::SVector{2,R}) where {R<:Real}
θ_a = atan(a[2], a[1])
θ_b = atan(b[2], b[1])
θ = θ_b - θ_a
return rem2pi(θ, RoundNearest)
end
function sq_norm2d(v::SVector{2,R}) where {R<:Real}
return v[1]^2 + v[2]^2
end
function norm2d(v::SVector{2,R}) where {R<:Real}
return sqrt(sq_norm2d(v))
end
end # module