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 Direction is <b>counter</b>clockwise. 12 * <p> 13 * Copyright (c) 2015-2018 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 North as the origin and radians as the displacement. */ 29 public static final DirectionUnit NORTH_RADIAN; 30 31 /** The unit for direction with North as the origin and degrees as the displacement. */ 32 public static final DirectionUnit NORTH_DEGREE; 33 34 /** The unit for direction with East as the origin and radians as the displacement. */ 35 public static final DirectionUnit 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 40 static 41 { 42 BASE = new DirectionUnit("DirectionUnit.base", "DirectionUnit.base", OTHER, 1.0, 0.0, false, AngleUnit.RADIAN); 43 NORTH_RADIAN = new DirectionUnit("DirectionUnit.North(rad)", "DirectionUnit.North(radians)", OTHER, 1.0, 0.0, false, 44 AngleUnit.RADIAN); 45 NORTH_DEGREE = new DirectionUnit("DirectionUnit.North(deg)", "DirectionUnit.North(degrees)", OTHER, Math.PI / 180.0, 46 0.0, false, AngleUnit.RADIAN); 47 EAST_RADIAN = new DirectionUnit("DirectionUnit.East(rad)", "DirectionUnit.East(radians)", OTHER, 1.0, -Math.PI / 2.0, 48 false, AngleUnit.RADIAN); 49 EAST_DEGREE = new DirectionUnit("DirectionUnit.East(deg)", "DirectionUnit.East(degrees)", OTHER, Math.PI / 180.0, -90.0, 50 false, AngleUnit.RADIAN); 51 } 52 53 /** 54 * Build a DirectionUnit with a scale factor and offset to the base DirectionUnit. 55 * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself 56 * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit, 57 * otherwise the abbreviation itself 58 * @param unitSystem the unit system, e.g. SI or Imperial 59 * @param scaleFactor multiply a value in this unit by the factor to convert to the given reference unit 60 * @param offset the offset to the reference unit to add to convert to the standard (e.g., BASE) unit 61 * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit 62 * @param relativeUnit the corresponding relative unit belonging to this absolute unit 63 */ 64 private DirectionUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, 65 final double scaleFactor, final double offset, final boolean standardUnit, final AngleUnit relativeUnit) 66 { 67 super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, scaleFactor, offset, standardUnit, relativeUnit); 68 } 69 70 /** 71 * Build a user-defined DirectionUnit with a scale factor and offset to the base DirectionUnit. 72 * @param name the long name of the unit 73 * @param abbreviation the abbreviation of the unit 74 * @param unitSystem the unit system, e.g. SI or Imperial 75 * @param scaleFactor multiply a value in this unit by the factor to convert to the given reference unit 76 * @param offset the offset to the reference unit to add to convert to the standard (e.g., BASE) unit 77 * @param relativeUnit the corresponding relative unit belonging to this absolute unit 78 */ 79 public DirectionUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final double scaleFactor, 80 final double offset, final AngleUnit relativeUnit) 81 { 82 this(name, abbreviation, unitSystem, scaleFactor, offset, false, relativeUnit); 83 } 84 85 /** {@inheritDoc} */ 86 @Override 87 public final DirectionUnit getStandardUnit() 88 { 89 return BASE; 90 } 91 92 /** {@inheritDoc} */ 93 @Override 94 public final String getSICoefficientsString() 95 { 96 return "1"; 97 } 98 99 }