View Javadoc
1   package org.djunits.unit;
2   
3   import org.djunits.unit.quantity.Quantity;
4   import org.djunits.unit.scale.OffsetLinearScale;
5   import org.djunits.unit.si.SIPrefixes;
6   import org.djunits.unit.unitsystem.UnitSystem;
7   
8   /**
9    * Standard direction unit. Several conversion factors have been taken from
10   * <a href="http://en.wikipedia.org/wiki/Conversion_of_units">http://en.wikipedia.org/wiki/Conversion_of_units</a>.
11   * <p>
12   * Note that the EAST and NORTH Directions are <b>counter</b>clockwise.
13   * <p>
14   * Copyright (c) 2015-2023 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   */
19  public class DirectionUnit extends AbsoluteLinearUnit<DirectionUnit, AngleUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140607L;
23  
24      /** The base, with "rad" as the SI signature. */
25      public static final Quantity<DirectionUnit> BASE = new Quantity<>("Direction", "rad");
26  
27      /** The unit for direction with East as the origin and radians as the displacement. */
28      public static final DirectionUnit EAST_RADIAN =
29              new DirectionUnit().build(new AbsoluteLinearUnit.Builder<DirectionUnit, AngleUnit>().setQuantity(BASE)
30                      .setId("rad(E)").setName("radians (East)").setDefaultDisplayAbbreviation("rad(E)")
31                      .setDefaultTextualAbbreviation("rad(E)").setUnitSystem(UnitSystem.OTHER).setSiPrefixes(SIPrefixes.NONE, 1.0)
32                      .setScale(new OffsetLinearScale(1.0, 0.0)).setRelativeUnit(AngleUnit.RADIAN));
33  
34      /** The default unit for direction is East_Radian. */
35      public static final DirectionUnit DEFAULT = EAST_RADIAN;
36  
37      /** The unit for direction with East as the origin and degrees as the displacement. */
38      public static final DirectionUnit EAST_DEGREE =
39              new DirectionUnit().build(new AbsoluteLinearUnit.Builder<DirectionUnit, AngleUnit>().setQuantity(BASE)
40                      .setId("deg(E)").setName("degrees (East)").setDefaultDisplayAbbreviation("\u00b0(E)")
41                      .setDefaultTextualAbbreviation("deg(E)").setUnitSystem(UnitSystem.OTHER).setSiPrefixes(SIPrefixes.NONE, 1.0)
42                      .setScale(new OffsetLinearScale(Math.PI / 180.0, 0.0)).setRelativeUnit(AngleUnit.DEGREE));
43  
44      /** The unit for direction with North as the origin and radians as the displacement. */
45      public static final DirectionUnit NORTH_RADIAN =
46              new DirectionUnit().build(new AbsoluteLinearUnit.Builder<DirectionUnit, AngleUnit>().setQuantity(BASE)
47                      .setId("rad(N)").setName("radians (North)").setDefaultDisplayAbbreviation("rad(N)")
48                      .setDefaultTextualAbbreviation("rad(N)").setUnitSystem(UnitSystem.OTHER).setSiPrefixes(SIPrefixes.NONE, 1.0)
49                      .setScale(new OffsetLinearScale(1.0, Math.PI / 2.0)).setRelativeUnit(AngleUnit.RADIAN));
50  
51      /** The unit for direction with North as the origin and degrees as the displacement. */
52      public static final DirectionUnit NORTH_DEGREE =
53              new DirectionUnit().build(new AbsoluteLinearUnit.Builder<DirectionUnit, AngleUnit>().setQuantity(BASE)
54                      .setId("deg(N)").setName("degrees (North)").setDefaultDisplayAbbreviation("\u00b0(N)")
55                      .setDefaultTextualAbbreviation("deg(N)").setUnitSystem(UnitSystem.OTHER).setSiPrefixes(SIPrefixes.NONE, 1.0)
56                      .setScale(new OffsetLinearScale(Math.PI / 180.0, 90.0)).setRelativeUnit(AngleUnit.DEGREE));
57  
58  }