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    * Standard acceleration unit based on distance and time.
10   * <p>
11   * Copyright (c) 2015-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
13   * <p>
14   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   */
16  public class AccelerationUnit extends Unit<AccelerationUnit>
17  {
18      /** */
19      private static final long serialVersionUID = 20140607L;
20  
21      /** The base, with "m/s2" as the SI signature. */
22      public static final Quantity<AccelerationUnit> BASE = new Quantity<>("Acceleration", "m/s2");
23  
24      /** The SI unit for acceleration is m/s^2. */
25      public static final AccelerationUnit SI = new AccelerationUnit().build(new Unit.Builder<AccelerationUnit>()
26              .setQuantity(BASE).setId("m/s2").setName("meter per second squared").setUnitSystem(UnitSystem.SI_DERIVED)
27              .setSiPrefixes(SIPrefixes.NONE, 1.0).setScale(IdentityScale.SCALE).setAdditionalAbbreviations("m/sec^2"));
28  
29      /** m/s2. */
30      public static final AccelerationUnit METER_PER_SECOND_2 = SI;
31  
32      /** km/h2. */
33      public static final AccelerationUnit KM_PER_HOUR_2 = SI.deriveLinear(factorLD("km", "h"), "km/h2",
34              "kilometer per hour squared", UnitSystem.SI_ACCEPTED, "km/h2", "km/h2", "km/hr^2", "km/hour^2");
35  
36      /** ft/s2. */
37      public static final AccelerationUnit FOOT_PER_SECOND_2 = SI.deriveLinear(factorLD("ft", "s"), "ft/s2",
38              "foot per second squared", UnitSystem.IMPERIAL, "ft/s2", "ft/s2", "ft/sec^2");
39  
40      /** in/s2. */
41      public static final AccelerationUnit INCH_PER_SECOND_2 = SI.deriveLinear(factorLD("in", "s"), "in/s2",
42              "inch per second squared", UnitSystem.IMPERIAL, "in/s2", "in/s2", "in/sec^2");
43  
44      /** mi/h2. */
45      public static final AccelerationUnit MILE_PER_HOUR_2 = SI.deriveLinear(factorLD("mi", "h"), "mi/h2",
46              "mile per hour squared", UnitSystem.IMPERIAL, "mi/h2", "mi/h2", "mi/hr^2", "mi/hour^2");
47  
48      /** mi/s2. */
49      public static final AccelerationUnit MILE_PER_SECOND_2 = SI.deriveLinear(factorLD("mi", "s"), "mi/s2",
50              "mile per second squared", UnitSystem.IMPERIAL, "mi/s2", "mi/s2", "mi/sec^2");
51  
52      /** kt/s. */
53      public static final AccelerationUnit KNOT_PER_SECOND =
54              SI.deriveLinear(factorSD("kt", "s"), "kt/s", "knot per second", UnitSystem.OTHER, "kt/s", "kt/s", "kt/sec");
55  
56      /** mi/h/s. */
57      public static final AccelerationUnit MILE_PER_HOUR_PER_SECOND =
58              SI.deriveLinear(factorSD("mi/h", "s"), "mi/h/s", "mile per hour per second", UnitSystem.IMPERIAL, "mi/h/s",
59                      "mi/h/s", "mi/hr/s", "mi/hour/s", "mi/h/sec", "mi/hr/sec", "mi/hour/sec");
60  
61      /** The standard gravity. */
62      public static final AccelerationUnit STANDARD_GRAVITY = SI.deriveLinear(9.80665, "g", "standard gravity", UnitSystem.OTHER);
63  
64      /** cm/s. */
65      public static final AccelerationUnit GAL = SI.deriveLinear(factorLD("cm", "s"), "Gal", "gal", UnitSystem.CGS);
66  
67      /**
68       * Determine the conversion factor to the base acceleration unit, given a length unit and a duration unit.
69       * @param length String; a length unit, e.g. km
70       * @param duration String; a duration unit, e.g. h
71       * @return double; the conversion factor from the provided units (e.g. km/h2) to the standard unit (m/s2)
72       */
73      private static double factorLD(final String length, final String duration)
74      {
75          double l = LengthUnit.BASE.of(length).getScale().toStandardUnit(1.0);
76          double d = DurationUnit.BASE.of(duration).getScale().toStandardUnit(1.0);
77          return l / (d * d);
78      }
79  
80      /**
81       * Determine the conversion factor to the base acceleration unit, given a speed unit and a duration unit.
82       * @param speed String; a speed unit, e.g. km/h
83       * @param duration String; a duration unit, e.g. s
84       * @return the conversion factor from the provided units (e.g. km/h/s) to the standard unit (m/s2)
85       */
86      private static double factorSD(final String speed, final String duration)
87      {
88          return SpeedUnit.BASE.of(speed).getScale().toStandardUnit(1.0)
89                  / DurationUnit.BASE.of(duration).getScale().toStandardUnit(1.0);
90      }
91  
92  }