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 length units. Several conversion factors have been taken from
10   * <a href="https://en.wikipedia.org/wiki/Conversion_of_units">https://en.wikipedia.org/wiki/Conversion_of_units</a>.
11   * <p>
12   * Copyright (c) 2015-2020 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" target="_blank">Alexander Verbraeck</a>
16   */
17  public class LengthUnit extends Unit<LengthUnit>
18  {
19      /** */
20      private static final long serialVersionUID = 20190818L;
21  
22      /** The base, with "m" as the SI signature. */
23      public static final Quantity<LengthUnit> BASE = new Quantity<>("Length", "m");
24  
25      /** The SI unit for length is meter. */
26      public static final LengthUnit SI =
27              new LengthUnit().build(new Unit.Builder<LengthUnit>().setQuantity(BASE).setId("m").setName("meter")
28                      .setUnitSystem(UnitSystem.SI_BASE).setSiPrefixes(SIPrefixes.UNIT, 1.0).setScale(IdentityScale.SCALE));
29  
30      /** meter. */
31      public static final LengthUnit METER = SI;
32  
33      /** nm. */
34      public static final LengthUnit NANOMETER = METER.deriveSI(SIPrefixes.getUnit("n"), 1.0);
35  
36      /** &#181;m. */
37      public static final LengthUnit MICROMETER = METER.deriveSI(SIPrefixes.getUnit("mu"), 1.0);
38  
39      /** mm. */
40      public static final LengthUnit MILLIMETER = METER.deriveSI(SIPrefixes.getUnit("m"), 1.0);
41  
42      /** cm. */
43      public static final LengthUnit CENTIMETER = METER.deriveSI(SIPrefixes.getUnit("c"), 1.0);
44  
45      /** dm. */
46      public static final LengthUnit DECIMETER = METER.deriveSI(SIPrefixes.getUnit("d"), 1.0);
47  
48      /** dam. */
49      public static final LengthUnit DECAMETER = METER.deriveSI(SIPrefixes.getUnit("da"), 1.0);
50  
51      /** hm. */
52      public static final LengthUnit HECTOMETER = METER.deriveSI(SIPrefixes.getUnit("h"), 1.0);
53  
54      /** km. */
55      public static final LengthUnit KILOMETER = METER.deriveSI(SIPrefixes.getUnit("k"), 1.0);
56  
57      /** foot (international) = 0.3048 m = 1/3 yd = 12 inches. */
58      public static final LengthUnit FOOT = METER.deriveLinear(0.3048, "ft", "foot", UnitSystem.IMPERIAL);
59  
60      /** inch (international) = 2.54 cm = 1/36 yd = 1/12 ft. */
61      public static final LengthUnit INCH = FOOT.deriveLinear(1.0 / 12.0, "in", "inch");
62  
63      /** yard (international) = 0.9144 m = 3 ft = 36 in. */
64      public static final LengthUnit YARD = FOOT.deriveLinear(3.0, "yd", "yard");
65  
66      /** mile (international) = 5280 ft = 1760 yd. */
67      public static final LengthUnit MILE = FOOT.deriveLinear(5280.0, "mi", "mile");
68  
69      /** nautical mile (international) = 1852 m. */
70      public static final LengthUnit NAUTICAL_MILE = METER.deriveLinear(1852.0, "NM", "nautical mile", UnitSystem.OTHER);
71  
72      /** Astronomical Unit = 149,597,870,700 m. */
73      public static final LengthUnit ASTRONOMICAL_UNIT =
74              METER.deriveLinear(149_597_870_700.0, "AU", "Astronomical Unit", UnitSystem.OTHER);
75  
76      /** Lightyear = 9,460,730,472,580,800 m. */
77      public static final LengthUnit LIGHTYEAR = METER.deriveLinear(9_460_730_472_580_800.0, "ly", "lightyear", UnitSystem.OTHER);
78  
79      /** Parsec = 648,000 / PI ly. */
80      public static final LengthUnit PARSEC = LIGHTYEAR.deriveLinear(648_000.0 / Math.PI, "Pc", "Parsec");
81  
82      /** Angstrom = 10^-10 m. */
83      public static final LengthUnit ANGSTROM = METER.deriveLinear(1.0E-10, "A", "Angstrom", UnitSystem.OTHER, "\u212B", "A");
84  
85  }