Skip to content

yakir12/UnitfulAngles.jl

Repository files navigation

UnitfulAngles

Build status Build Status Coverage Status

A supplemental units package for Julia's Unitful.jl.

UnitfulAngles.jl introduces all the angular units found in Wikipedia's articles Angle § Units, Angular unit and Circular sector.

In addition to the Radian and Degree units already available in Unitful.jl, the following units are introduced: DoubleTurn, Turn, HalfTurn, Quadrant, Sextant, Octant, ClockPosition, HourAngle, CompassPoint, Hexacontade, BinaryRadian, DiameterPart, Gradian, Arcminute, and Arcsecond.

Because all the trigonometric functions work correctly regardless of the type of their argument, there is no need to convert between the units. However, to specifically convert one unit to the other, use Unitful.jl's uconvert function:

julia> using Unitful, UnitfulAngles

julia> uconvert(u"clockPosition", 128u"brad")
6//1 clockPosition

Special features

  • All the trigonometric functions (sin, sinc, cos, cosc, tan, sec, csc, and cot) work as expected:
    julia> using UnitfulAngles
    
    julia> import UnitfulAngles: °, rad, octant
    
    julia> sin(30°)
    0.5
    
    julia> cos*rad)
    -1.0
    
    julia> tan(1octant)
    1.0
  • In order to get inverse functions (acos, acot, acsc, asec, asin, atan, and atan2) to return a specific unit, specify the desired unit as the first argument:
    julia> import UnitfulAngles.turn
    
    julia> asin(turn, 1)
    0.25 τ
  • As a bonus, you can also convert between an angle and Dates.Time:
    julia> using Unitful, UnitfulAngles, Dates
    
    julia> convert(Dates.Time, 200u"grad")
    12:00:00
    
    julia> convert(u"sextant", Dates.Time(4,0,0))
    1.0 sextant