Skip to content

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

License

Notifications You must be signed in to change notification settings

waldyrious/Angles.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages