Class LinearScale

java.lang.Object
org.djunits.unit.scale.LinearScale
All Implemented Interfaces:
Serializable, Scale
Direct Known Subclasses:
IdentityScale

public class LinearScale extends Object implements Scale
A Scale for linear transformations not involving a zero-offset, e.g. for Length, Time, Area.
A linear scale is a scale that is linearly relates a unit to the underlying SI standard unit. E.g. Mile is linearly related to meter (the SI unit for length) and the conversion is zero-based (0 miles equals 0 meter). Unlike temperature in degrees Celsius which is not linearly related to the Kelvin (the SI unit for temperature) because the conversion is not zero-based (0°C is 273.15K).

Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.

Author:
Alexander Verbraeck, Peter Knoppers
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    LinearScale(double scaleFactorToBaseUnit)
    Construct a Scale for linear transformations.
    LinearScale(double numerator, double denominator)
    Construct a Scale for linear transformations, with a numerator and denominator.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    double
    fromBaseValue(double value)
    Convert a value from a base (SI) value to a value in the unit that uses this scale.
    final double
    Retrieve the factor for conversion to the standard unit.
    int
     
    boolean
    Return whether a scale is a 'standard' scale.
    double
    toBaseValue(double value)
    Convert a value expressed in this unit to its base (SI) value.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • LinearScale

      public LinearScale(double scaleFactorToBaseUnit)
      Construct a Scale for linear transformations. To transform, e.g., a minute to a second, a scale factor of 60 is used.
      Parameters:
      scaleFactorToBaseUnit - the conversion factor by which this number has to be multiplied to convert it to the base (e.g., SI) unit.
    • LinearScale

      public LinearScale(double numerator, double denominator)
      Construct a Scale for linear transformations, with a numerator and denominator. To transform, e.g., m/s to km/h, a numerator of 1000 (a km is 1000 m) and a denominator of 3600 (an hour is 3600 seconds) is used.
      Parameters:
      numerator - the factor by which this number has to be multiplied to convert it to the base (e.g., SI) unit.
      denominator - the factor by which this number has to be divided to convert it to the base (e.g., SI) unit.
  • Method Details

    • toBaseValue

      public double toBaseValue(double value)
      Description copied from interface: Scale
      Convert a value expressed in this unit to its base (SI) value.
      Specified by:
      toBaseValue in interface Scale
      Parameters:
      value - the value expressed in this unit
      Returns:
      the value converted to its SI value
    • fromBaseValue

      public double fromBaseValue(double value)
      Description copied from interface: Scale
      Convert a value from a base (SI) value to a value in the unit that uses this scale.
      Specified by:
      fromBaseValue in interface Scale
      Parameters:
      value - the value to convert
      Returns:
      the corresponding value in the given unit
    • getScaleFactorToBaseUnit

      public final double getScaleFactorToBaseUnit()
      Retrieve the factor for conversion to the standard unit.
      Returns:
      the factor for conversion to the standard unit
    • isBaseScale

      public boolean isBaseScale()
      Description copied from interface: Scale
      Return whether a scale is a 'standard' scale. For a linear scale, any scale with conversion factor 1 would be considered standard. For an offset scale, it would be considered standard if the offset is 0 and the conversion factor is 1.
      Specified by:
      isBaseScale in interface Scale
      Returns:
      whether the scale is a 'standard' scale
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object