public double As(VelocityUnit unit) { if (this.unit == unit) { return(internalValue); } else { double f = Factor(this.unit) / Factor(unit); return(internalValue * f); } }
private decimal ConvertToMph(decimal velocity, VelocityUnit units) { switch (units) { case VelocityUnit.MetresPerSecond: return(Conversion.MetresPerSecondToMilesPerHour(velocity)); case VelocityUnit.KilometersPerHour: return(Conversion.KilometresPerHourToMilesPerHour(velocity)); default: return(velocity); } }
private static VelocitySystem GetSystem(VelocityUnit unit) { if (UNIT_IDX_METRIC_MIN <= unit && unit <= UNIT_IDX_METRIC_MAX) { return(VelocitySystem.Metric); } else if (UNIT_IDX_IMPERIAL_MIN <= unit && unit <= UNIT_IDX_IMPERIAL_MAX) { return(VelocitySystem.Imperial); } else { return(VelocitySystem.Astronomical); } }
/// <summary> /// Normalize by changing the unit. /// This method will only change to a unit in the same system and only to commonly used units. /// </summary> public void Normalize() { VelocityUnit min, max; switch (System) { case VelocitySystem.Metric: min = UNIT_IDX_METRIC_MIN; max = UNIT_IDX_METRIC_MAX_STD; break; case VelocitySystem.Imperial: min = UNIT_IDX_IMPERIAL_MIN; max = UNIT_IDX_IMPERIAL_MAX_STD; break; case VelocitySystem.Astronomical: min = UNIT_IDX_ASTRONIMICAL_MIN; max = UNIT_IDX_ASTRONIMICAL_MAX_STD; return; default: return; } if (internalValue != 0) { double log = Math.Log10(internalValue); double f = Factor(unit); for (VelocityUnit u = max; u >= min; u--) { double log_new = Math.Log10(f / Factor(u)); if (log + log_new >= 0) { Unit = u; break; } } } else if (IsMetric) { unit = SI; } }
Vector3 getVelocity(Vector3 velocity, VelocityUnit velocityUnit) { if (velocityUnit == VelocityUnit.kmh) { //V = string.Format("{0:N0}", v1.magnitude * 3.6f); velocity = Vector3.Scale(velocity, Vector3.one * 3.6f); } else if (velocityUnit == VelocityUnit.ms) { //V = string.Format("{0:N0}", v1.magnitude); //velocity = velocity; } else if (velocityUnit == VelocityUnit.mach) { //V = string.Format("{0:N2}", v1.magnitude / 340f); velocity = Vector3.Scale(velocity, Vector3.one / 340f); } return(velocity); }
/// <summary> /// Calculate the factor from the input unit to one meter per second. /// </summary> /// <param name="unit"></param> /// <returns></returns> private static double Factor(VelocityUnit unit) { switch (unit) { case VelocityUnit.MilliMeterPerHour: return(2.8e-7); // http://convert-to.com/conversion/speed/convert-mm-per-hour-to-m-per-second.html case VelocityUnit.MilliMeterPerMinute: return(1.66667e-5); case VelocityUnit.CentiMeterPerMinute: return(1.66667e-4); case VelocityUnit.MilliMeterPerSecond: return(1e-3); case VelocityUnit.CentiMeterPerSecond: return(1e-2); case VelocityUnit.MeterPerMinute: return(1.66667e-2); case VelocityUnit.KiloMeterPerHour: return(0.277778); case VelocityUnit.MeterPerSecond: return(1); case VelocityUnit.InchPerHour: return(7.1e-6); // http://convert-to.com/conversion/speed/convert-in-per-hour-to-m-per-second.html case VelocityUnit.FootPerHour: return(8.46667e-5); case VelocityUnit.FootPerMinute: return(5.08e-3); case VelocityUnit.InchPerSecond: return(2.54e-2); case VelocityUnit.FootPerSecond: return(0.3048); case VelocityUnit.MilePerHour: return(0.44704); case VelocityUnit.MilePerMinute: return(26.8224); case VelocityUnit.SpeedOfSound: return(3.432e2); case VelocityUnit.SpeedOfLight: return(2.99792e8); case VelocityUnit.Knot: return(0.514444); default: throw new NotImplementedException(); } }
public void KineticEnergy(double m, WeightUnit wu, double v, VelocityUnit vu, double e, EnergyUnit eu) { var r = MeasurementMath.KineticEnergy(new Measurement <WeightUnit>(m, wu), new Measurement <VelocityUnit>(v, vu)); r.In(eu).Should().BeApproximately(e, 1e-6); }
public static string GetUnitAsString(VelocityUnit unitType) { string unitString = ""; if (unitType == VelocityUnit.MillimeterPerSec) { unitString = "mm/s"; } else if (unitType == VelocityUnit.CentimeterPerSec) { unitString = "cm/s"; } else if (unitType == VelocityUnit.CentimeterPerMin) { unitString = "cm/min"; } else if (unitType == VelocityUnit.MeterPerSec) { unitString = "m/s"; } else if (unitType == VelocityUnit.MeterPerMin) { unitString = "m/min"; } else if (unitType == VelocityUnit.MeterPerHour) { unitString = "m/hr"; } else if (unitType == VelocityUnit.MeterPerDay) { unitString = "m/day"; } else if (unitType == VelocityUnit.KilometerPerSec) { unitString = "km/s"; } else if (unitType == VelocityUnit.KilometerPerMin) { unitString = "km/min"; } else if (unitType == VelocityUnit.KilometerPerHour) { unitString = "km/hr"; } else if (unitType == VelocityUnit.KilometerPerDay) { unitString = "km/day"; } else if (unitType == VelocityUnit.InchPerSec) { unitString = "in/s"; } else if (unitType == VelocityUnit.InchPerMin) { unitString = "in/min"; } else if (unitType == VelocityUnit.InchPerHour) { unitString = "in/hr"; } else if (unitType == VelocityUnit.FootPerSec) { unitString = "ft/s"; } else if (unitType == VelocityUnit.FootPerMin) { unitString = "ft/min"; } else if (unitType == VelocityUnit.FootPerHour) { unitString = "ft/hr"; } else if (unitType == VelocityUnit.FootPerDay) { unitString = "ft/day"; } else if (unitType == VelocityUnit.MilePerSec) { unitString = "mile/s"; } else if (unitType == VelocityUnit.KilometerPerMin) { unitString = "km/min"; } else if (unitType == VelocityUnit.MilePerHour) { unitString = "mile/hr"; } else if (unitType == VelocityUnit.MilePerDay) { unitString = "mile/day"; } else if (unitType == VelocityUnit.Knot) { unitString = "knot"; } return(unitString); }
public static double ConvertFromSIValue(VelocityUnit unitType, double meterPerSecValue) { double convertedValue = 0; if (unitType == VelocityUnit.MillimeterPerSec) { convertedValue = 1000 * meterPerSecValue; } else if (unitType == VelocityUnit.CentimeterPerSec) { convertedValue = 100 * meterPerSecValue; } else if (unitType == VelocityUnit.CentimeterPerMin) { convertedValue = 6000 * meterPerSecValue; } else if (unitType == VelocityUnit.MeterPerSec) { convertedValue = meterPerSecValue; } else if (unitType == VelocityUnit.MeterPerMin) { convertedValue = 60 * meterPerSecValue; } else if (unitType == VelocityUnit.MeterPerHour) { convertedValue = 3600 * meterPerSecValue; } else if (unitType == VelocityUnit.MeterPerDay) { convertedValue = 86400 * meterPerSecValue; } else if (unitType == VelocityUnit.KilometerPerSec) { convertedValue = meterPerSecValue / 1000; } else if (unitType == VelocityUnit.KilometerPerMin) { convertedValue = 0.06 * meterPerSecValue; } else if (unitType == VelocityUnit.KilometerPerHour) { convertedValue = 3.6 * meterPerSecValue; } else if (unitType == VelocityUnit.KilometerPerDay) { convertedValue = 86.4 * meterPerSecValue; } else if (unitType == VelocityUnit.InchPerSec) { convertedValue = meterPerSecValue / 0.0254; } else if (unitType == VelocityUnit.InchPerMin) { convertedValue = meterPerSecValue / 4.23333333e-4; } else if (unitType == VelocityUnit.InchPerHour) { convertedValue = meterPerSecValue / 7.05555556e-6; } else if (unitType == VelocityUnit.FootPerSec) { convertedValue = meterPerSecValue / 0.3048; } else if (unitType == VelocityUnit.FootPerMin) { convertedValue = meterPerSecValue / 0.00508; } else if (unitType == VelocityUnit.FootPerHour) { convertedValue = meterPerSecValue / 8.46666667E-5; } else if (unitType == VelocityUnit.FootPerDay) { convertedValue = meterPerSecValue / 3.52777778E-5; } else if (unitType == VelocityUnit.MilePerSec) { convertedValue = meterPerSecValue / 1609.344; } else if (unitType == VelocityUnit.KilometerPerMin) { convertedValue = meterPerSecValue / 26.8224; } else if (unitType == VelocityUnit.MilePerHour) { convertedValue = meterPerSecValue / 0.44704; } else if (unitType == VelocityUnit.MilePerDay) { convertedValue = meterPerSecValue / 0.0186266667; } else if (unitType == VelocityUnit.Knot) { convertedValue = meterPerSecValue / 0.514444444; } return(convertedValue); }
private Wind CreateWind(double?distance, DistanceUnit?distanceUnit, double direction, AngularUnit directionUnit, double velocity, VelocityUnit velocityUnit) { Wind w = new Wind(); if (distance == null || distanceUnit == null) { w.MaximumRange = null; } else { w.MaximumRange = new Measurement <DistanceUnit>(distance.Value, distanceUnit.Value); } w.Direction = new Measurement <AngularUnit>(direction, directionUnit); w.Velocity = new Measurement <VelocityUnit>(velocity, velocityUnit); return(w); }
public void GetValue(double?distance, DistanceUnit?distanceUnit, double direction, AngularUnit directionUnit, double velocity, VelocityUnit velocityUnit) { var w = CreateWind(distance, distanceUnit, direction, directionUnit, velocity, velocityUnit); using TestForm tf = new TestForm(); var control = tf.AddControl <WindControl>(5, 5, 100, 100); if (w.MaximumRange != null) { control.CheckBox("checkBoxDistance").Checked = true; control.MeasurementControl("measurementDistance").Value = w.MaximumRange; } control.MeasurementControl("measurementDirection").Value = w.Direction; control.MeasurementControl("measurementVelocity").Value = w.Velocity; var w1 = control.Wind; w1.MaximumRange.Should().Be(w.MaximumRange); w1.Direction.Should().Be(w.Direction); w1.Velocity.Should().Be(w.Velocity); }
public void SetValue(double?distance, DistanceUnit?distanceUnit, double direction, AngularUnit directionUnit, double velocity, VelocityUnit velocityUnit) { var w = CreateWind(distance, distanceUnit, direction, directionUnit, velocity, velocityUnit); using TestForm tf = new TestForm(); var control = tf.AddControl <WindControl>(5, 5, 100, 100); control.Wind = w; if (w.MaximumRange == null) { control.CheckBox("checkBoxDistance").Should().BeNotChecked(); control.MeasurementControl("measurementDistance") .Should().HaveExactValue(DistanceUnit.Meter.New(0)) .And.BeEnabled(false); } else { control.CheckBox("checkBoxDistance").Should().BeChecked(); control.MeasurementControl("measurementDistance") .Should().HaveExactValue(w.MaximumRange.Value) .And.BeEnabled(true); } control.MeasurementControl("measurementDirection") .Should().HaveExactValue(w.Direction); control.MeasurementControl("measurementVelocity") .Should().HaveExactValue(w.Velocity); var w1 = control.Wind; w1.Should().NotBeSameAs(w); w1.MaximumRange.Should().Be(w.MaximumRange); w1.Direction.Should().Be(w.Direction); w1.Velocity.Should().Be(w.Velocity); }
public void UpdateUnitSystem(UnitSystem unitSystem) { this.unitSystem = unitSystem; this.TextBox.Clear(); if (unitSystem != null) { this.textBoxUnitSystem.ScrollBars = System.Windows.Forms.ScrollBars.None; string temperature = "Temperature: \t\t" + TemperatureUnit.GetUnitAsString(unitSystem.TemperatureUnitType); string pressure = "Pressure: \t\t\t" + PressureUnit.GetUnitAsString(unitSystem.PressureUnitType); string massFlowRate = "Mass Flow Rate: \t\t" + MassFlowRateUnit.GetUnitAsString(unitSystem.MassFlowRateUnitType); string volumeFlowRate = "Volume Flow Rate: \t\t" + VolumeFlowRateUnit.GetUnitAsString(unitSystem.VolumeFlowRateUnitType); string moistureContent = "Moisture Content: \t\t" + MoistureContentUnit.GetUnitAsString(unitSystem.MoistureContentUnitType); string relativeHumidity = "Fraction: \t\t\t" + FractionUnit.GetUnitAsString(unitSystem.FractionUnitType); string enthalpy = "Specific Energy: \t\t" + SpecificEnergyUnit.GetUnitAsString(unitSystem.SpecificEnergyUnitType); string specificHeat = "Specific Heat: \t\t" + SpecificHeatUnit.GetUnitAsString(unitSystem.SpecificHeatUnitType); string energy = "Energy: \t\t\t" + EnergyUnit.GetUnitAsString(unitSystem.EnergyUnitType); string power = "Power: \t\t\t" + PowerUnit.GetUnitAsString(unitSystem.PowerUnitType); string density = "Density: \t\t\t" + DensityUnit.GetUnitAsString(unitSystem.DensityUnitType); string dynamicViscosity = "Dynamic Viscosity: \t\t" + DynamicViscosityUnit.GetUnitAsString(unitSystem.DynamicViscosityUnitType); string kinematicViscosity = "Kinematic Viscosity: \t" + KinematicViscosityUnit.GetUnitAsString(unitSystem.KinematicViscosityUnitType); string conductivity = "Thermal Conductivity: \t" + ThermalConductivityUnit.GetUnitAsString(unitSystem.ThermalConductivityUnitType); string diffusivity = "Diffusivity: \t\t" + DiffusivityUnit.GetUnitAsString(unitSystem.DiffusivityUnitType); string mass = "Mass: \t\t\t" + MassUnit.GetUnitAsString(unitSystem.MassUnitType); string length = "Length: \t\t\t" + LengthUnit.GetUnitAsString(unitSystem.LengthUnitType); string area = "Area: \t\t\t" + AreaUnit.GetUnitAsString(unitSystem.AreaUnitType); string volume = "Volume: \t\t\t" + VolumeUnit.GetUnitAsString(unitSystem.VolumeUnitType); string time = "Time: \t\t\t" + TimeUnit.GetUnitAsString(unitSystem.TimeUnitType); string smallLength = "Small Length: \t\t" + SmallLengthUnit.GetUnitAsString(unitSystem.SmallLengthUnitType); string microLength = "Micro Length: \t\t" + MicroLengthUnit.GetUnitAsString(unitSystem.MicroLengthUnitType); string liquidHead = "Liquid Head: \t\t" + LiquidHeadUnit.GetUnitAsString(unitSystem.LiquidHeadUnitType); string volumeRateFlowLiquids = "Volume Rate Flow Liquids: \t" + VolumeRateFlowLiquidsUnit.GetUnitAsString(unitSystem.VolumeRateFlowLiquidsUnitType); string volumeRateFlowGases = "Volume Rate Flow Gases: \t" + VolumeRateFlowGasesUnit.GetUnitAsString(unitSystem.VolumeRateFlowGasesUnitType); string heatTransferCoeff = "Heat Transfer Coeff.: \t" + HeatTransferCoefficientUnit.GetUnitAsString(unitSystem.HeatTransferCoefficientUnitType); string surfaceTension = "Surface Tension: \t\t" + SurfaceTensionUnit.GetUnitAsString(unitSystem.SurfaceTensionUnitType); string velocity = "Velocity: \t\t\t" + VelocityUnit.GetUnitAsString(unitSystem.VelocityUnitType); string foulingFactor = "Fouling Factor: \t\t" + FoulingFactorUnit.GetUnitAsString(unitSystem.FoulingFactorUnitType); string specificVolume = "Specific Volume: \t\t" + SpecificVolumeUnit.GetUnitAsString(unitSystem.SpecificVolumeUnitType); string massVolumeConcentration = "Mass Volume Concentration: \t" + MassVolumeConcentrationUnit.GetUnitAsString(unitSystem.MassVolumeConcentrationUnitType); string planeAngle = "Plane Angle: \t\t" + PlaneAngleUnit.GetUnitAsString(unitSystem.PlaneAngleUnitType); string volumeHeatTransferCoefficient = "Volume Heat Transfer Coeff.: \t" + VolumeHeatTransferCoefficientUnit.GetUnitAsString(unitSystem.VolumeHeatTransferCoefficientUnitType); this.TextBox.AppendText(temperature + "\r\n"); this.TextBox.AppendText(pressure + "\r\n"); this.TextBox.AppendText(massFlowRate + "\r\n"); this.TextBox.AppendText(volumeFlowRate + "\r\n"); this.TextBox.AppendText(moistureContent + "\r\n"); this.TextBox.AppendText(relativeHumidity + "\r\n"); this.TextBox.AppendText(enthalpy + "\r\n"); this.TextBox.AppendText(specificHeat + "\r\n"); this.TextBox.AppendText(energy + "\r\n"); this.TextBox.AppendText(power + "\r\n"); this.TextBox.AppendText(density + "\r\n"); this.TextBox.AppendText(dynamicViscosity + "\r\n"); this.TextBox.AppendText(kinematicViscosity + "\r\n"); this.TextBox.AppendText(conductivity + "\r\n"); this.TextBox.AppendText(diffusivity + "\r\n"); this.TextBox.AppendText(mass + "\r\n"); this.TextBox.AppendText(length + "\r\n"); this.TextBox.AppendText(area + "\r\n"); this.TextBox.AppendText(volume + "\r\n"); this.TextBox.AppendText(time + "\r\n"); this.TextBox.AppendText(smallLength + "\r\n"); this.TextBox.AppendText(microLength + "\r\n"); this.TextBox.AppendText(liquidHead + "\r\n"); this.TextBox.AppendText(volumeRateFlowLiquids + "\r\n"); this.TextBox.AppendText(volumeRateFlowGases + "\r\n"); this.TextBox.AppendText(heatTransferCoeff + "\r\n"); this.TextBox.AppendText(surfaceTension + "\r\n"); this.TextBox.AppendText(velocity + "\r\n"); this.TextBox.AppendText(foulingFactor + "\r\n"); this.TextBox.AppendText(specificVolume + "\r\n"); this.TextBox.AppendText(massVolumeConcentration + "\r\n"); this.TextBox.AppendText(planeAngle + "\r\n"); this.TextBox.AppendText(volumeHeatTransferCoefficient + "\r\n"); this.textBoxUnitSystem.ScrollBars = System.Windows.Forms.ScrollBars.Both; } }
public void SoundVelocity(double temperature, TemperatureUnit temperatureUnit, double pressure, PressureUnit pressureUnit, double humidity, double expected, VelocityUnit expectedUnit) { var atmosphere = new Atmosphere(new Measurement <DistanceUnit>(0, DistanceUnit.Foot), new Measurement <PressureUnit>(pressure, pressureUnit), true, new Measurement <TemperatureUnit>(temperature, temperatureUnit), humidity); atmosphere.SoundVelocity.In(expectedUnit).Should().BeApproximately(expected, 1); }
private static Vector <VelocityUnit> WindVector(ShotParameters shot, Wind wind, VelocityUnit units) { double sightCosine = shot.SightAngle.Cos(); double sightSine = shot.SightAngle.Sin(); double cantCosine = (shot.CantAngle ?? AngularUnit.Radian.New(0)).Cos(); double cantSine = (shot.CantAngle ?? AngularUnit.Radian.New(0)).Sin(); Measurement <VelocityUnit> rangeVelocity, crossComponent; if (wind != null) { rangeVelocity = (wind.Velocity * wind.Direction.Cos()).To(units); crossComponent = (wind.Velocity * wind.Direction.Sin()).To(units); } else { rangeVelocity = new Measurement <VelocityUnit>(0, units); crossComponent = new Measurement <VelocityUnit>(0, units); } Measurement <VelocityUnit> rangeFactor = -rangeVelocity * sightSine; return(new Vector <VelocityUnit>(rangeVelocity * sightCosine, rangeFactor * cantCosine + crossComponent * cantSine, crossComponent * cantCosine - rangeFactor * cantSine)); }
public Velocity(double value, VelocityUnit unit) { this.unit = unit; internalValue = value; }
void Awake() { isFirstFram = false; velocityUnit = VelocityUnit.kmh; }
public static double ConvertToSIValue(VelocityUnit unitType, double toBeConvertedValue) { double meterPerSecValue = 0; if (unitType == VelocityUnit.MillimeterPerSec) { meterPerSecValue = 1.0e-3 * toBeConvertedValue; } else if (unitType == VelocityUnit.CentimeterPerSec) { meterPerSecValue = 1.0e-2 * toBeConvertedValue; } else if (unitType == VelocityUnit.CentimeterPerMin) { meterPerSecValue = toBeConvertedValue / 6000; } else if (unitType == VelocityUnit.MeterPerSec) { meterPerSecValue = toBeConvertedValue; } else if (unitType == VelocityUnit.MeterPerMin) { meterPerSecValue = toBeConvertedValue / 60; } else if (unitType == VelocityUnit.MeterPerHour) { meterPerSecValue = toBeConvertedValue / 3600; } else if (unitType == VelocityUnit.MeterPerDay) { meterPerSecValue = toBeConvertedValue / 86400; } else if (unitType == VelocityUnit.KilometerPerSec) { meterPerSecValue = 1000 * toBeConvertedValue; } else if (unitType == VelocityUnit.KilometerPerMin) { meterPerSecValue = 1000 / 60 * toBeConvertedValue; } else if (unitType == VelocityUnit.KilometerPerHour) { meterPerSecValue = toBeConvertedValue / 3.6; } else if (unitType == VelocityUnit.KilometerPerDay) { meterPerSecValue = toBeConvertedValue / 86.4; } else if (unitType == VelocityUnit.InchPerSec) { meterPerSecValue = 0.0254 * toBeConvertedValue; } else if (unitType == VelocityUnit.InchPerMin) { meterPerSecValue = 4.23333333e-4 * toBeConvertedValue; } else if (unitType == VelocityUnit.InchPerHour) { meterPerSecValue = 7.05555556e-6 * toBeConvertedValue; } else if (unitType == VelocityUnit.FootPerSec) { meterPerSecValue = 0.3048 * toBeConvertedValue; } else if (unitType == VelocityUnit.FootPerMin) { meterPerSecValue = 0.00508 * toBeConvertedValue; } else if (unitType == VelocityUnit.FootPerHour) { meterPerSecValue = 8.46666667E-5 * toBeConvertedValue; } else if (unitType == VelocityUnit.FootPerDay) { meterPerSecValue = 3.52777778E-5 * toBeConvertedValue; } else if (unitType == VelocityUnit.MilePerSec) { meterPerSecValue = 1609.344 * toBeConvertedValue; } else if (unitType == VelocityUnit.KilometerPerMin) { meterPerSecValue = 26.8224 * toBeConvertedValue; } else if (unitType == VelocityUnit.MilePerHour) { meterPerSecValue = 0.44704 * toBeConvertedValue; } else if (unitType == VelocityUnit.MilePerDay) { meterPerSecValue = 0.0186266667 * toBeConvertedValue; } else if (unitType == VelocityUnit.Knot) { meterPerSecValue = 0.514444444 * toBeConvertedValue; } return(meterPerSecValue); }
public void Zero1(double ballisticCoefficient, DragTableId ballisticTable, double muzzleVelocity, VelocityUnit velocityUnit, double zeroDistance, DistanceUnit distanceUnit, double sightAngle, AngularUnit sightAngleUnit, double sightAngleAccuracy) { Ammunition ammunition = new Ammunition( weight: new Measurement <WeightUnit>(69, WeightUnit.Grain), muzzleVelocity: new Measurement <VelocityUnit>(muzzleVelocity, velocityUnit), ballisticCoefficient: new BallisticCoefficient(ballisticCoefficient, ballisticTable) ); Rifle rifle = new Rifle( sight: new Sight(sightHeight: new Measurement <DistanceUnit>(3.2, DistanceUnit.Inch), Measurement <AngularUnit> .ZERO, Measurement <AngularUnit> .ZERO), zero: new ZeroingParameters(distance: new Measurement <DistanceUnit>(zeroDistance, distanceUnit), ammunition: null, atmosphere: null)); Atmosphere atmosphere = new Atmosphere(); //default atmosphere var sightAngle1 = (new TrajectoryCalculator()).SightAngle(ammunition, rifle, atmosphere); sightAngle1.In(sightAngleUnit).Should().BeApproximately(sightAngle, sightAngleAccuracy); }
public static VelocityUnit GetUnitAsEnum(string unitString) { VelocityUnit unitType = VelocityUnit.MeterPerSec; if (unitString.Equals("mm/s")) { unitType = VelocityUnit.MillimeterPerSec; } else if (unitString.Equals("cm/s")) { unitType = VelocityUnit.CentimeterPerSec; } else if (unitString.Equals("cm/min")) { unitType = VelocityUnit.CentimeterPerMin; } else if (unitString.Equals("m/s")) { unitType = VelocityUnit.MeterPerSec; } else if (unitString.Equals("m/min")) { unitType = VelocityUnit.MeterPerMin; } else if (unitString.Equals("m/hr")) { unitType = VelocityUnit.MeterPerHour; } else if (unitString.Equals("m/day")) { unitType = VelocityUnit.MeterPerDay; } else if (unitString.Equals("km/s")) { unitType = VelocityUnit.KilometerPerSec; } else if (unitString.Equals("km/min")) { unitType = VelocityUnit.KilometerPerMin; } else if (unitString.Equals("km/hr")) { unitType = VelocityUnit.KilometerPerHour; } else if (unitString.Equals("km/day")) { unitType = VelocityUnit.KilometerPerDay; } else if (unitString.Equals("in/s")) { unitType = VelocityUnit.InchPerSec; } else if (unitString.Equals("in/min")) { unitType = VelocityUnit.InchPerMin; } else if (unitString.Equals("in/hr")) { unitType = VelocityUnit.InchPerHour; } else if (unitString.Equals("ft/s")) { unitType = VelocityUnit.FootPerSec; } else if (unitString.Equals("ft/min")) { unitType = VelocityUnit.FootPerMin; } else if (unitString.Equals("ft/hr")) { unitType = VelocityUnit.FootPerHour; } else if (unitString.Equals("ft/day")) { unitType = VelocityUnit.FootPerDay; } else if (unitString.Equals("mile/s")) { unitType = VelocityUnit.MilePerSec; } else if (unitString.Equals("km/min")) { unitType = VelocityUnit.KilometerPerMin; } else if (unitString.Equals("mile/hr")) { unitType = VelocityUnit.MilePerHour; } else if (unitString.Equals("mile/day")) { unitType = VelocityUnit.MilePerDay; } else if (unitString.Equals("knot")) { unitType = VelocityUnit.Knot; } return(unitType); }
public Velocity(Velocity other) { unit = other.unit; internalValue = other.internalValue; }
public void Velocity(double distance, DistanceUnit distanceUnit, double velocity, VelocityUnit velocityUnit, double time) { var distance1 = new Measurement <DistanceUnit>(distance, distanceUnit); var velocity1 = new Measurement <VelocityUnit>(velocity, velocityUnit); TimeSpan ts1 = TimeSpan.FromSeconds(time); TimeSpan ts2 = MeasurementMath.TravelTime(distance1, velocity1); ts2.TotalSeconds.Should().BeApproximately(time, 1e-5); var distance2 = MeasurementMath.DistanceTraveled(velocity1, ts1); distance2.In(distanceUnit).Should().BeApproximately(distance, 1e-5); var velocity2 = MeasurementMath.Velocity(distance1, ts1); velocity2.In(velocityUnit).Should().BeApproximately(velocity, 1e-5); }
public void Conversion(double value, VelocityUnit unit, double expected, VelocityUnit targetUnit, double accurracy = 1e-5) { var v = new Measurement <VelocityUnit>(value, unit); v.In(targetUnit).Should().BeApproximately(expected, accurracy); }