Skip to content

Commit

Permalink
Update AngleBetweenVectors.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreySarnoff committed Jul 18, 2020
1 parent 72671c9 commit ccde298
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/AngleBetweenVectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@ function arc(point1::NTuple{2,T}, point2::NTuple{2,T}) where {T<:Real}
return atan(point1[2], point1[1]) - atan(point2[2], point2[1])
end

function arc(pt1::NTuple{3,T}, pt2::NTuple{3,T}) where {T<:Real}
n1 = ab_minus_cd(pt1[2],pt2[3],pt1[3],pt2[2])
n2 = ab_minus_cd(pt1[3],pt2[1],pt1[1],pt2[3])
n3 = ab_minus_cd(pt1[1],pt2[2],pt1[2],pt2[1])
h = hypot(n1,n2,n3)
n1 = n1 / h; n2 = n2 / h; n3 = n3 / h
h = hypot(n1,n2,n3)
return atan(h)
end


# from Kahan
function ad_minus_bc(a,b,c,d)
w = b*c
e = fma(-b, c, w)
f = fma(a, d, -w)
return f+e
end


function area_lo2hi(a,b,c)
p = (c + (b + a))*(a - (c - b))*(a + (c - b))*(c + (b - a))
return sqrt(p)/4
end

function tantheta(pt1::NTuple{3,T}, pt2::NTuple{3,T}) where {T<:Real}
h1, h2 = minmax(hypot(pt1...), hypot(pt2...))
h3 = hypot((pt2 .- pt1)...)
a = 2*area_lo2hi(h1, h2, h3)
return a/dot(p1,p2)
end

"""
angle(point1::T, point2::T) where {T}
Expand Down

0 comments on commit ccde298

Please sign in to comment.