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-2019 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   * @author <a href="https://www.transport.citg.tudelft.nl">Wouter Schakel</a>
20   */
21  public class JerkUnit extends Unit<JerkUnit>
22  {
23      /** */
24      private static final long serialVersionUID = 20191003L;
25  
26      /** The base, with "m/s3" as the SI signature. */
27      public static final Quantity<JerkUnit> BASE = new Quantity<>("Jerk", "m/s3");
28  
29      /** The SI unit for acceleration is m/s^3. */
30      public static final JerkUnit SI =
31              new JerkUnit().build(new Unit.Builder<JerkUnit>().setQuantity(BASE).setId("m/s3").setName("meter per second cubed")
32                      .setUnitSystem(UnitSystem.SI_DERIVED).setSiPrefixes(SIPrefixes.NONE, 1.0).setScale(IdentityScale.SCALE));
33  
34      /** m/s3. */
35      public static final JerkUnit M_PER_S3 = SI;
36  
37      /** cm/s3. */
38      public static final JerkUnit CM_PER_S3 = SI.deriveLinear(factorLD("cm", "s"), "cm/s3", "centimeter per second cubed");
39  
40      /** mm/s3. */
41      public static final JerkUnit MM_PER_S3 = SI.deriveLinear(factorLD("mm", "s"), "mm/s3", "millimeter per second cubed");
42  
43      /** ft/s3. */
44      public static final JerkUnit FT_PER_S3 = SI.deriveLinear(factorLD("ft", "s"), "ft/s3", "foot per second cubed");
45  
46      /** in/s3. */
47      public static final JerkUnit IN_PER_S3 = SI.deriveLinear(factorLD("in", "s"), "in/s3", "inch per second cubed");
48  
49      /**
50       * Determine the conversion factor to the base jerk unit, given a length unit and a duration unit.
51       * @param length String; a length unit, e.g. km
52       * @param duration String; a duration unit, e.g. h
53       * @return double; the conversion factor from the provided units (e.g. km/h3) to the standard unit (m/s3)
54       */
55      private static double factorLD(final String length, final String duration)
56      {
57          double l = LengthUnit.BASE.of(length).getScale().toStandardUnit(1.0);
58          double d = DurationUnit.BASE.of(duration).getScale().toStandardUnit(1.0);
59          return l / (d * d * d);
60      }
61  }