1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2025-01-20 17:01:31 +00:00
ReCo.jl/src/Geometry.jl

30 lines
588 B
Julia
Raw Normal View History

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