Coder Social home page Coder Social logo

jeffreysarnoff / anglebetweenvectors.jl Goto Github PK

View Code? Open in Web Editor NEW
28.0 28.0 4.0 123 KB

An accurate and stable calculation of the angle separating two vectors.

License: MIT License

Julia 100.00%
accurate angle floating-point julia n-dimensional vectors

anglebetweenvectors.jl's People

Contributors

jeffreysarnoff avatar juliatagbot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

anglebetweenvectors.jl's Issues

Strange behaviour for points near the origin

Hi, I noticed that angle does not actually do as claimed in the docstrings:

help?> angle
...
If one of the points is at the origin, the result is zero.
...

Specifically:

julia> angle((0.0, 0.0), (1.0, 1.0))
NaN

Also, there is some inconsistent behaviour near the origin:

julia> angle((0.0, 0.001), (1.0, 1.0))
0.7853981633974483

julia> angle((0.001, 0.001), (1.0, 1.0))
1.5700924586837754e-16

julia> angle((0.0001, 0.001), (1.0, 1.0))
0.6857295109062864

julia> angle((0.0001, 0.0001), (1.0, 1.0))
1.5700924586837754e-16

I would expect all of the above to be approximately 0.7853981633974483?

I am using [ec570357] AngleBetweenVectors v0.3.0.

replace unitize by scaling to same magnitude

Maybe I am totally wrong but could this code be even better without divisions:

     
    n1 = norm(point1)
    n2 = norm(point2)

    p1 = n2 * point1
    p2 = n1 * point2

    # p1 and p2 have now same magnitudes

    y = p1 .- p2
    x = p1 .+ p2

    a = 2 * atan(norm(y) , norm(x))  # use atan2(Y,X) result already in [0,pi]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.