View Javadoc
1   package org.djunits.demo.website;
2   
3   import org.djunits.unit.DurationUnit;
4   import org.djunits.unit.LengthUnit;
5   import org.djunits.unit.Unit;
6   import org.djunits.unit.quantity.Quantity;
7   import org.djunits.unit.scale.IdentityScale;
8   import org.djunits.unit.si.SIPrefixes;
9   import org.djunits.unit.unitsystem.UnitSystem;
10  
11  /**
12   * Example from the website to test if the code on the website is correct
13   * <p>
14   * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
16   * </p>
17   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
19   */
20  public class JerkUnit extends Unit<JerkUnit>
21  {
22      /** */
23      private static final long serialVersionUID = 20191003L;
24  
25      /** The base quantity, with "m/s3" as the SI signature. */
26      public static final Quantity<JerkUnit> BASE = new Quantity<>("Jerk", "m/s3");
27  
28      /** The SI unit for jerk is m/s^3. */
29      public static final JerkUnit SI =
30              new JerkUnit().build(new Unit.Builder<JerkUnit>().setQuantity(BASE).setId("m/s3").setName("meter per second cubed")
31                      .setUnitSystem(UnitSystem.SI_DERIVED).setSiPrefixes(SIPrefixes.NONE, 1.0).setScale(IdentityScale.SCALE));
32  
33      /** m/s3. */
34      public static final JerkUnit M_PER_S3 = SI;
35  
36      /** cm/s3. */
37      public static final JerkUnit CM_PER_S3 = SI.deriveLinear(factorLD("cm", "s"), "cm/s3", "centimeter per second cubed");
38  
39      /** mm/s3. */
40      public static final JerkUnit MM_PER_S3 = SI.deriveLinear(factorLD("mm", "s"), "mm/s3", "millimeter per second cubed");
41  
42      /** ft/s3. */
43      public static final JerkUnit FT_PER_S3 = SI.deriveLinear(factorLD("ft", "s"), "ft/s3", "foot per second cubed");
44  
45      /** in/s3. */
46      public static final JerkUnit IN_PER_S3 = SI.deriveLinear(factorLD("in", "s"), "in/s3", "inch per second cubed");
47  
48      /**
49       * Determine the conversion factor to the base jerk unit, given a length unit and a duration unit.
50       * @param length String; a length unit, e.g. km
51       * @param duration String; a duration unit, e.g. h
52       * @return double; the conversion factor from the provided units (e.g. km/h3) to the standard unit (m/s3)
53       */
54      private static double factorLD(final String length, final String duration)
55      {
56          double l = LengthUnit.BASE.of(length).getScale().toStandardUnit(1.0);
57          double d = DurationUnit.BASE.of(duration).getScale().toStandardUnit(1.0);
58          return l / (d * d * d);
59      }
60  }