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 direction unit. Several conversion factors have been taken from
9 * <a href="http://en.wikipedia.org/wiki/Conversion_of_units">http://en.wikipedia.org/wiki/Conversion_of_units</a>.
10 * <p>
11 * Note that the EAST and NORTH Directions are <b>counter</b>clockwise.
12 * <p>
13 * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14 * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
15 * <p>
16 * $LastChangedDate: 2017-01-30 14:23:11 +0100 (Mon, 30 Jan 2017) $, @version $Revision: 234 $, by $Author: averbraeck $,
17 * initial version May 15, 2014 <br>
18 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19 */
20 public class DirectionUnit extends AbsoluteLinearUnit<DirectionUnit, AngleUnit>
21 {
22 /** */
23 private static final long serialVersionUID = 20140607L;
24
25 /** The BASE unit for direction with an artificial origin. */
26 public static final DirectionUnit BASE;
27
28 /** The unit for direction with East as the origin and radians as the displacement. */
29 public static final DirectionUnit EAST_RADIAN;
30
31 /** The unit for direction with East as the origin and degrees as the displacement. */
32 public static final DirectionUnit EAST_DEGREE;
33
34 /** The unit for direction with North as the origin and radians as the displacement. */
35 public static final DirectionUnit NORTH_RADIAN;
36
37 /** The unit for direction with North as the origin and degrees as the displacement. */
38 public static final DirectionUnit NORTH_DEGREE;
39
40 static
41 {
42 EAST_RADIAN = new DirectionUnit("DirectionUnit.East(rad)", OTHER, 1.0, 0.0, AngleUnit.RADIAN);
43 BASE = EAST_RADIAN;
44 EAST_DEGREE = new DirectionUnit("DirectionUnit.East(deg)", OTHER, Math.PI / 180.0, 0.0, AngleUnit.DEGREE);
45 NORTH_RADIAN = new DirectionUnit("DirectionUnit.North(rad)", OTHER, 1.0, Math.PI / 2.0, AngleUnit.RADIAN);
46 NORTH_DEGREE = new DirectionUnit("DirectionUnit.North(deg)", OTHER, Math.PI / 180.0, 90.0, AngleUnit.DEGREE);
47 }
48
49 /**
50 * Build a DirectionUnit with a scale factor and offset to the base DirectionUnit.
51 * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
52 * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
53 * @param scaleFactor double; multiply a value in this unit by the factor to convert to the given reference unit
54 * @param offset double; the offset to the reference unit to add to convert to the standard (e.g., BASE) unit
55 * @param relativeUnit AngleUnit; the corresponding relative unit belonging to this absolute unit
56 */
57 private DirectionUnit(final String abbreviationKey, final UnitSystem unitSystem, final double scaleFactor,
58 final double offset, final AngleUnit relativeUnit)
59 {
60 super(abbreviationKey, unitSystem, scaleFactor, offset, relativeUnit);
61 }
62
63 /**
64 * Build a user-defined DirectionUnit with a scale factor and offset to the base DirectionUnit.
65 * @param name String; the long name of the unit
66 * @param abbreviation String; the abbreviation of the unit
67 * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
68 * @param scaleFactor double; multiply a value in this unit by the factor to convert to the given reference unit
69 * @param offset double; the offset to the reference unit to add to convert to the standard (e.g., BASE) unit
70 * @param relativeUnit AngleUnit; the corresponding relative unit belonging to this absolute unit
71 */
72 public DirectionUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final double scaleFactor,
73 final double offset, final AngleUnit relativeUnit)
74 {
75 super(name, abbreviation, unitSystem, scaleFactor, offset, relativeUnit);
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 public final DirectionUnit getStandardUnit()
81 {
82 return BASE;
83 }
84
85 /** {@inheritDoc} */
86 @Override
87 public final String getSICoefficientsString()
88 {
89 return "1";
90 }
91
92 }