[ANN] AngleBetweenVectors


angle(point1, point2) determines the angle between point1 and point2. The smallest angle is returned and π obtains when the points are oppositely directed: [(1,0), (-1,0)].
So, 0 <= angle(p1, p2) <= pi. It does this with more accuracy than the usual way.

angle(p1, p2) expects p1, p2 to be points in a 2D, 3D … ManyD space, with Cartesian coordinates. To use any given point representation, define its Tuple constructor (unless one already exists). Vectors, NamedTuples, SVectors already have that.

This package is posted by request. The method is work of Professor Kahan (pg 15).


Thanks for posting this!

I will consider how well it fits in DynamicalBilliards.jl! We are doing this computation literally every step in the hottest loops.

1 Like

I am glad you said something!


[improved] Now there are two exports, angle and fastangle. Both are accurate. angle is more accurate; fastangle is more performant (I see it 30% faster). angle should always be used where the abs() of some coordinates may be outside of 2^±20. Tagged v0.2.0.

1 Like

My understanding of https://semver.org is that you start from version 0.1.0 and each new feature increments minor version, thus this package should already be at 0.2.0 version if you would like to follow semantic versioning.

Sure – see above.