View Javadoc
1   package org.djunits.unit;
2   
3   import org.djunits.unit.quantity.Quantity;
4   import org.djunits.unit.scale.IdentityScale;
5   import org.djunits.unit.si.SIPrefixes;
6   import org.djunits.unit.unitsystem.UnitSystem;
7   
8   /**
9    * According to <a href="http://en.wikipedia.org/wiki/Velocity">Wikipedia</a>: Speed describes only how fast an object is
10   * moving, whereas speed gives both how fast and in what direction the object is moving.
11   * <p>
12   * Copyright (c) 2015-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>
14   * </p>
15   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   */
17  public class SpeedUnit extends Unit<SpeedUnit>
18  {
19      /** */
20      private static final long serialVersionUID = 20140607L;
21  
22      /** The base, with "m/s" as the SI signature. */
23      public static final Quantity<SpeedUnit> BASE = new Quantity<>("Speed", "m/s");
24  
25      /** The SI unit for speed is m/s. */
26      public static final SpeedUnit SI = new SpeedUnit().build(new Unit.Builder<SpeedUnit>().setQuantity(BASE).setId("m/s")
27              .setName("meter per second").setUnitSystem(UnitSystem.SI_DERIVED).setSiPrefixes(SIPrefixes.NONE, 1.0)
28              .setScale(IdentityScale.SCALE).setAdditionalAbbreviations("m/sec"));
29  
30      /** m/s. */
31      public static final SpeedUnit METER_PER_SECOND = SI;
32  
33      /** m/h. */
34      public static final SpeedUnit METER_PER_HOUR = SI.deriveLinear(factorLD(LengthUnit.METER, DurationUnit.HOUR), "m/h",
35              "meter per hour", UnitSystem.SI_ACCEPTED, "m/h", "m/h", "m/hr", "m/hour");
36  
37      /** km/s. */
38      public static final SpeedUnit KM_PER_SECOND = SI.deriveLinear(factorLD(LengthUnit.KILOMETER, DurationUnit.SECOND), "km/s",
39              "kilometer per second", UnitSystem.SI_DERIVED, "km/s", "km/s", "km/sec");
40  
41      /** km/h. */
42      public static final SpeedUnit KM_PER_HOUR = SI.deriveLinear(factorLD(LengthUnit.KILOMETER, DurationUnit.HOUR), "km/h",
43              "kilometer per hour", UnitSystem.SI_ACCEPTED, "km/h", "km/h", "km/hr", "km/hour");
44  
45      /** in/s. */
46      public static final SpeedUnit INCH_PER_SECOND = SI.deriveLinear(factorLD(LengthUnit.INCH, DurationUnit.SECOND), "in/s",
47              "inch per second", UnitSystem.IMPERIAL, "in/s", "in/s", "in/sec");
48  
49      /** in/min. */
50      public static final SpeedUnit INCH_PER_MINUTE =
51              SI.deriveLinear(factorLD(LengthUnit.INCH, DurationUnit.MINUTE), "in/min", "inch per minute", UnitSystem.IMPERIAL);
52  
53      /** in/h. */
54      public static final SpeedUnit INCH_PER_HOUR = SI.deriveLinear(factorLD(LengthUnit.INCH, DurationUnit.HOUR), "in/h",
55              "inch per hour", UnitSystem.IMPERIAL, "in/h", "in/h", "in/hr", "in/hour");
56  
57      /** ft/s. */
58      public static final SpeedUnit FOOT_PER_SECOND = SI.deriveLinear(factorLD(LengthUnit.FOOT, DurationUnit.SECOND), "ft/s",
59              "foot per second", UnitSystem.IMPERIAL, "ft/s", "ft/s", "ft/sec");
60  
61      /** ft/min. */
62      public static final SpeedUnit FOOT_PER_MINUTE =
63              SI.deriveLinear(factorLD(LengthUnit.FOOT, DurationUnit.MINUTE), "ft/min", "inch per minute", UnitSystem.IMPERIAL);
64  
65      /** ft/h. */
66      public static final SpeedUnit FOOT_PER_HOUR = SI.deriveLinear(factorLD(LengthUnit.FOOT, DurationUnit.HOUR), "ft/h",
67              "foot per hour", UnitSystem.IMPERIAL, "ft/h", "ft/h", "ft/hr", "ft/hour");
68  
69      /** mile/s. */
70      public static final SpeedUnit MILE_PER_SECOND = SI.deriveLinear(factorLD(LengthUnit.MILE, DurationUnit.SECOND), "mi/s",
71              "mile per second", UnitSystem.IMPERIAL, "mi/s", "mi/s", "mi/sec");
72  
73      /** mile/min. */
74      public static final SpeedUnit MILE_PER_MINUTE =
75              SI.deriveLinear(factorLD(LengthUnit.MILE, DurationUnit.MINUTE), "mi/min", "mile per minute", UnitSystem.IMPERIAL);
76  
77      /** mile/h. */
78      public static final SpeedUnit MILE_PER_HOUR = SI.deriveLinear(factorLD(LengthUnit.MILE, DurationUnit.HOUR), "mi/h",
79              "mile per hour", UnitSystem.IMPERIAL, "mi/h", "mi/h", "mi/hr", "mi/hour");
80  
81      /** knot = Nautical Mile per hour. */
82      public static final SpeedUnit KNOT =
83              SI.deriveLinear(factorLD(LengthUnit.NAUTICAL_MILE, DurationUnit.HOUR), "kt", "knot", UnitSystem.OTHER);
84  
85      /**
86       * Determine the conversion factor to the base speed unit, given a length unit and a duration unit.
87       * @param length LengthUnit; the used length unit, e.g. km
88       * @param duration DurationUnit; the used duration unit, e.g. h
89       * @return double; the conversion factor from the provided units (e.g. km/h) to the standard unit (e.g., m/s)
90       */
91      private static double factorLD(final LengthUnit length, final DurationUnit duration)
92      {
93          return length.getScale().toStandardUnit(1.0) / duration.getScale().toStandardUnit(1.0);
94      }
95  
96  }