You can use the shorter names by adding an
open Microsoft.FSharp.Data.UnitSystems.SI.UnitNames
to your file.
As for the error, it's not clear why you are converting the result of the sin
call to a measure type, since velocity * t
has the same measure type (meter) as abc
. The following appears to be what you want:
open System
open Microsoft.FSharp.Data.UnitSystems.SI
open Microsoft.FSharp.Data.UnitSystems.SI.UnitNames
module GeneralBallisticTrajectory =
[<Measure>] type radian
let gravitationalAcceleration : float<metre/second^2> = 9.80665<metre/second^2>
let getPosition (angle: float<radian>) (velocity: float<metre/second>) (t: float<second>) =
let x = velocity * t * (cos (float angle) |> LanguagePrimitives.FloatWithMeasure<metre/second>)
let abc = (0.5 * gravitationalAcceleration) * t * t // returns float<UnitNames.metre>
let y = (velocity * t * (sin (float angle))) - abc
(x, y)