DimensionfulAngles.jl

📐 An extension of Unitful.jl to include angles as a dimension.

MIT License

Stars
9
Committers
7

DimensionfulAngles.jl

Extends Unitful.jl to include angle as a dimension and allow dispatching on angles.

using Pkg
Pkg.add("DimensionfulAngles")

or in the Pkg REPL (enter from the Julia REPL with ]):

pkg> add DimensionfulAngles

Basic Usage

Use DimensionfulAngles.jl for units containing angles and Unitful.jl for all other units. The units in DimensionfulAngles.jl are differentiated from their dimensionless counterparts with a superscript . Simply add this superscript to any angle units to make it dimensionful. In Julia environments this can be typed as \^a<tab>.

julia> using Unitful

julia> using DimensionfulAngles

julia> dimensionless_angle = 1u"rad"

1 rad

julia> dimensionful_angle = 1u"radᵃ"
1 rad

julia> typeof(dimensionless_angle)
Quantity{Int64, NoDims, Unitful.FreeUnits{(rad,), NoDims, nothing}}

julia> typeof(dimensionful_angle)
Quantity{Int64, 𝐀, Unitful.FreeUnits{(rad,), 𝐀, nothing}}

When defining quantities with units from DimensionfulAngles.jl you can use the ua string instead and omit the superscript . But when defining quantities with units from both it is more convenient to use the u string.

julia> dimensionful_angle = 1ua"rad"
1 rad

julia> typeof(dimensionful_angle)
Quantity{Int64, 𝐀, Unitful.FreeUnits{(rad,), 𝐀, nothing}}

julia> angular_velocity = 1.2u"radᵃ/s"
1.2 rad s⁻¹

julia> typeof(angular_velocity)
Quantity{Float64, 𝐀 𝐓⁻¹, Unitful.FreeUnits{(rad, s⁻¹), 𝐀 𝐓⁻¹, nothing}}

A third alternative is to directly import only the units you will be using and renaming those from DimensionfulAngles.jl to remove the superscript .

julia> using Unitful

julia> using Unitful: m, s, kg

julia> using DimensionfulAngles: radᵃ as rad, °ᵃ as °

julia> angular_velocity = 1.2rad / s
1.2 rad s⁻¹

Default Symbols

Another way of doing this is to import all default units, which includes SI base and derived units from Unitful.jl with angle units from DimensionfulAngles.jl. This is done as

julia> using DimensionfulAngles.DefaultSymbols

julia> angular_velocity = 1.2rad / s

Converting to/from Unitful.jl

To convert a quantity to or from Unitful.jl use the uconvert function with first argument either :Unitful or :DimensionfulAngles. For example:

julia> using Unitful, DimensionfulAngles

julia> ω = 3.2u"radᵃ/s"
3.2 rad s⁻¹

julia> ω̄ = uconvert(:Unitful, ω)
3.2 rad s⁻¹

julia> dimension(ω)
𝐀 𝐓⁻¹

julia> dimension(ω̄)
𝐓⁻¹

Contributing

Contributions are welcome! 🎊 Please see the contribution guidelines for ways to contribute to the project.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Acknowledgments

Some portions of this software are adapted from:

  • UnitfulAngles.jl: Copyright (c) 2017: Yakir Luc Gagnon.
  • UnitfulUS.jl: Copyright (c) 2017, California Institute of Technology. All rights reserved.