View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
4   
5   import org.djunits.unit.unitsystem.UnitSystem;
6   
7   /**
8    * Standard absolute position units.
9    * <p>
10   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
12   * <p>
13   * $LastChangedDate: 2017-04-15 02:11:44 +0200 (Sat, 15 Apr 2017) $, @version $Revision: 239 $, by $Author: averbraeck $,
14   * initial version May 15, 2014 <br>
15   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   */
17  public class PositionUnit extends AbsoluteLinearUnit<PositionUnit, LengthUnit>
18  {
19      /** */
20      private static final long serialVersionUID = 20140607L;
21  
22      /** The BASE unit for position with an artificial zero-point. */
23      public static final PositionUnit BASE;
24  
25      /** Positions scaled to am. */
26      public static final PositionUnit ATTOMETER;
27  
28      /** Positions scaled to fm. */
29      public static final PositionUnit FEMTOMETER;
30  
31      /** Positions scaled to pm. */
32      public static final PositionUnit PICOMETER;
33  
34      /** Positions scaled to nm. */
35      public static final PositionUnit NANOMETER;
36  
37      /** Positions scaled to &#181;m. */
38      public static final PositionUnit MICROMETER;
39  
40      /** Positions scaled to mm. */
41      public static final PositionUnit MILLIMETER;
42  
43      /** Positions scaled to m. */
44      public static final PositionUnit METER;
45  
46      /** Positions scaled to cm. */
47      public static final PositionUnit CENTIMETER;
48  
49      /** Positions scaled to dm. */
50      public static final PositionUnit DECIMETER;
51  
52      /** Positions scaled to dam. */
53      public static final PositionUnit DEKAMETER;
54  
55      /** Positions scaled to hm. */
56      public static final PositionUnit HECTOMETER;
57  
58      /** Positions scaled to km. */
59      public static final PositionUnit KILOMETER;
60  
61      /** Positions scaled to Mm. */
62      public static final PositionUnit MEGAMETER;
63  
64      /** Positions scaled to inch (international) = 2.54 cm = 1/36 yd = 1/12 ft. */
65      public static final PositionUnit INCH;
66  
67      /** Positions scaled to foot (international) = 0.3048 m = 1/3 yd = 12 inches. */
68      public static final PositionUnit FOOT;
69  
70      /** Positions scaled to yard (international) = 0.9144 m = 3 ft = 36 in. */
71      public static final PositionUnit YARD;
72  
73      /** Positions scaled to mile (international) = 5280 ft = 1760 yd. */
74      public static final PositionUnit MILE;
75  
76      /** Positions scaled to nautical mile (international) = 1852 m. */
77      public static final PositionUnit NAUTICAL_MILE;
78  
79      /** Positions scaled to Astronomical Unit = 149,597,870,700 m. */
80      public static final PositionUnit ASTRONOMICAL_UNIT;
81  
82      /** Positions scaled to Lightyear = 9,460,730,472,580,800 m. */
83      public static final PositionUnit LIGHTYEAR;
84  
85      /** Positions scaled to Parsec = 648,000 / PI Pc. */
86      public static final PositionUnit PARSEC;
87  
88      /** Positions scaled to Angstrom = 10^-10 m. */
89      public static final PositionUnit ANGSTROM;
90  
91      static
92      {
93          METER = new PositionUnit("PositionUnit.m", OTHER, 1.0, 0.0, LengthUnit.METER);
94          BASE = METER;
95          ATTOMETER = new PositionUnit("PositionUnit.am", OTHER, 1.0E-18, 0.0, LengthUnit.ATTOMETER);
96          FEMTOMETER = new PositionUnit("PositionUnit.fm", OTHER, 1.0E-15, 0.0, LengthUnit.FEMTOMETER);
97          PICOMETER = new PositionUnit("PositionUnit.pm", OTHER, 1.0E-12, 0.0, LengthUnit.PICOMETER);
98          NANOMETER = new PositionUnit("PositionUnit.nm", OTHER, 1.0E-9, 0.0, LengthUnit.NANOMETER);
99          MICROMETER = new PositionUnit("PositionUnit.mum", OTHER, 1.0E-6, 0.0, LengthUnit.MICROMETER);
100         MILLIMETER = new PositionUnit("PositionUnit.mm", OTHER, 0.001, 0.0, LengthUnit.MILLIMETER);
101         CENTIMETER = new PositionUnit("PositionUnit.cm", OTHER, 0.01, 0.0, LengthUnit.CENTIMETER);
102         DECIMETER = new PositionUnit("PositionUnit.dm", OTHER, 0.1, 0.0, LengthUnit.DECIMETER);
103         DEKAMETER = new PositionUnit("PositionUnit.dam", OTHER, 10.0, 0.0, LengthUnit.DEKAMETER);
104         HECTOMETER = new PositionUnit("PositionUnit.hm", OTHER, 100.0, 0.0, LengthUnit.HECTOMETER);
105         KILOMETER = new PositionUnit("PositionUnit.km", OTHER, 1000.0, 0.0, LengthUnit.KILOMETER);
106         MEGAMETER = new PositionUnit("PositionUnit.Mm", OTHER, 1000000.0, 0.0, LengthUnit.MEGAMETER);
107         FOOT = new PositionUnit("PositionUnit.ft", OTHER, 0.3048, 0.0, LengthUnit.FOOT);
108         INCH = new PositionUnit("PositionUnit.in", OTHER, 0.3048 / 12.0, 0.0, LengthUnit.INCH);
109         MILE = new PositionUnit("PositionUnit.mi", OTHER, 0.3048 * 5280.0, 0.0, LengthUnit.MILE);
110         YARD = new PositionUnit("PositionUnit.yd", OTHER, 0.3048 * 3.0, 0.0, LengthUnit.YARD);
111         NAUTICAL_MILE = new PositionUnit("PositionUnit.NM", OTHER, 1852.0, 0.0, LengthUnit.NAUTICAL_MILE);
112         ASTRONOMICAL_UNIT = new PositionUnit("PositionUnit.AU", OTHER, 149597870700.0, 0.0, LengthUnit.ASTRONOMICAL_UNIT);
113         LIGHTYEAR = new PositionUnit("PositionUnit.ly", OTHER, 9460730472580800.0, 0.0, LengthUnit.LIGHTYEAR);
114         PARSEC = new PositionUnit("PositionUnit.pc", OTHER, 648000 / Math.PI, 0.0, LengthUnit.PARSEC);
115         ANGSTROM = new PositionUnit("PositionUnit.A", OTHER, 1E-10, 0.0, LengthUnit.ANGSTROM);
116     }
117 
118     /**
119      * Build a PositionUnit with a scale factor and offset to the base PositionUnit.
120      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
121      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
122      * @param scaleFactor double; multiply a value in this unit by the factor to convert to the given reference unit
123      * @param offset double; the offset to the reference unit to add to convert to the standard (e.g., BASE) unit
124      * @param relativeUnit LengthUnit; the corresponding relative unit belonging to this absolute unit
125      */
126     private PositionUnit(final String abbreviationKey, final UnitSystem unitSystem, final double scaleFactor,
127             final double offset, final LengthUnit relativeUnit)
128     {
129         super(abbreviationKey, unitSystem, scaleFactor, offset, relativeUnit);
130     }
131 
132     /**
133      * Build a user-defined PositionUnit with a scale factor and offset to the base PositionUnit.
134      * @param name String; the long name of the unit
135      * @param abbreviation String; the abbreviation of the unit
136      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
137      * @param scaleFactor double; multiply a value in this unit by the factor to convert to the given reference unit
138      * @param offset double; the offset to the reference unit to add to convert to the standard (e.g., BASE) unit
139      * @param relativeUnit LengthUnit; the corresponding relative unit belonging to this absolute unit
140      */
141     public PositionUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final double scaleFactor,
142             final double offset, final LengthUnit relativeUnit)
143     {
144         super(name, abbreviation, unitSystem, scaleFactor, offset, relativeUnit);
145     }
146 
147     /** {@inheritDoc} */
148     @Override
149     public final PositionUnit getStandardUnit()
150     {
151         return BASE;
152     }
153 
154     /** {@inheritDoc} */
155     @Override
156     public final String getSICoefficientsString()
157     {
158         return "m";
159     }
160 
161 }