GithubHelp home page GithubHelp logo

waldyrious / angles.jl Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 9 KB

An angle type that wraps your degrees,radians, proportions so that you don't need to worry about it.

License: Other

Julia 100.00%
julia radians angles units mirrored-repository

angles.jl's Introduction

Angles

Build Status Build status

Coverage Status codecov.io

Is it a radian? Is it a degree? Who cares!

Angles.jl introduces an Angle type that wraps your angles as Degree, Radian, or Proportion (i.e. the angle's proportion of π: for example, 90° is proportion 0.5), making sure all the trigonometric functions work as expected. You'll never need to worry about using sin or sind.

Here's an example:

julia> α = Degree(30)
Angles.Degree{Int64}(30)

julia> sin(α)
0.5

julia> β = Radian(π)
Angles.Radian{Irrational{:π}}(π = 3.1415926535897...)

julia> cos(β)
-1.0

julia> θ = Proportion(.5)
Angles.Proportion{Float64}(0.5)

julia> sin(θ)
1.0

The approach Angles.jl takes is adding appropriate methods to sin, sinc, cos, cosc, tan, sec, csc, and cot so that they accept Degree, Radian, and Proportion. We excluded the d versions of these functions (e.g. sind) to keep things simple (and to avoid overriding any intended behavior by the user).

In order to get inverse functions (acos, acot, acsc, asec, asin, atan, and atan2) to return a subtype of Angle, specify the desired subtype as the first argument:

julia> asin(Degree, 0.5)
Angles.Degree{Float64}(30.000000000000004)

Because all the trigonometric functions work correctly regardless of the type of their argument (i.e. Degree, Radian, Proportion), there is no need to convert between the units. However, to specifically convert one unit to the other, use the type instances:

julia> β = Radian(π/2)
Angles.Radian{Float64}(1.5707963267948966)

julia> α = Degree(β)
Angles.Degree{Float64}(90.0)

julia> p = Proportion(α)
Angles.Proportion{Float64}(0.5)

julia> Radian(p)
Angles.Radian{Float64}(1.5707963267948966)

The computational cost for this functionality should be negligible. To keep it that way, many arguably relevant functionalities were excluded. Some of the excluded functionalities are: directionality (i.e. clockwise versus counterclockwise), auto-wrapping, and fixed-point arithmetic for additional accuracy.

The major disadvantage of this package (in its current, 2017-07, state) is the fact that there are no additional functions defined for subtypes of Angle (e.g. +, *, ). This needs to be fixed.

angles.jl's People

Contributors

yakir12 avatar

Watchers

 avatar  avatar  avatar

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.