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

30 lines
588 B
Julia
Raw Normal View History

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:33:11 +00:00
angle2(a::SVector{2,R}, b::SVector{2,R}) where {R<:Real}
2021-12-16 13:54:52 +00:00
Return the angle `φ` from vector `a` to `b` while `φ` [-π, π].
2021-12-16 13:54:52 +00:00
"""
2022-01-18 01:33:11 +00:00
function angle2(a::SVector{2,R}, b::SVector{2,R}) where {R<: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:33:11 +00:00
function sq_norm2d(v::SVector{2,R}) where {R<:Real}
2022-01-18 01:17:52 +00:00
return v[1]^2 + v[2]^2
end
2022-01-18 01:33:11 +00:00
function norm2d(v::SVector{2,R}) where {R<:Real}
2022-01-18 01:17:52 +00:00
return sqrt(sq_norm2d(v))
end
2022-01-11 17:39:38 +00:00
2022-03-19 22:11:03 +00:00
end # module