Class OffsetLinearScale

java.lang.Object
org.djunits.unit.scale.LinearScale
org.djunits.unit.scale.OffsetLinearScale
All Implemented Interfaces:
Serializable, Scale

public class OffsetLinearScale extends LinearScale
Scale with factor and zero point offset.

A Scale for linear transformations with an offset that has to be applied first when converting to the standard (SI) unit, before the scaling takes place, e.g. for Temperature. As an example, transform from Degrees Fahrenheit to Kelvin (SI). The conversion is K = (F + 459.67) × 5⁄9, and F = K × 9⁄5 − 459.67.

When we have an original scale with offset o1 and scalefactor f1, the calculation to the base unit is

 valueSI = (value1 + o1) * f1
 

So the offset is expressed in the "unit" of the value. As an example, when we transform degrees Fahrenheit to Kelvin, the factor is 5/9, and the offset is 459.67 (degrees Fahrenheit of 0 degrees Fahrenheit expressed in Kelvin). The formula becomes: K = (F + 459.67) * 5/9. So 0 F is 459.67 * 5/9 = 255.372 K. For Celcius to Kelvin, the scale factor is 1, and the offset 273.15. From Fahrenheit to Celcius, the offset is -32, and the factor is 5/9.

When we apply a second offset transformation on a scale, e.g. from Fahrenheit to Celcius to Kelvin, this works as follows: If we combine a second scale factor for a derived unit with offset o2 and scalefactor f2, we need to calculate the ultimate scale to the base (si) unit. The factor then becomes:

 value1  = (value2 + o2) * f2
 valueSI = (value1 + o1) * f1 = value2 * (f1 * f2) + (f1 * f2 * o2 + f1 * o1)
 

as an example for F --2--> C --1--> K: o1 = 273.15, f1 = 1, o2 = -32, f2 = 5/9:
110 F = 110*5/9 -32*5/9 + 273.15 = 316.483 K.

Copyright (c) 2013-2024 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 Details

    • OffsetLinearScale

      public OffsetLinearScale(double conversionFactorToStandardUnit, double offsetToStandardUnit)
      Construct a Scale for linear transformations with an offset, e.g. for Temperature.
      Parameters:
      conversionFactorToStandardUnit - double; the conversion factor by which this number has to be multiplied to convert it to the standard (e.g., SI) unit.
      offsetToStandardUnit - the offset that has to be taken into account for conversions; when converting to a standard unit, the offset is applied first.
  • Method Details

    • toStandardUnit

      public final double toStandardUnit(double value)
      Description copied from interface: Scale
      Convert a value to an SI value using this scale.
      Specified by:
      toStandardUnit in interface Scale
      Overrides:
      toStandardUnit in class LinearScale
      Parameters:
      value - double; the value to convert
      Returns:
      the corresponding SI value
    • fromStandardUnit

      public final double fromStandardUnit(double value)
      Description copied from interface: Scale
      Convert a value from an SI value to a value in the unit that uses this scale.
      Specified by:
      fromStandardUnit in interface Scale
      Overrides:
      fromStandardUnit in class LinearScale
      Parameters:
      value - double; the value to convert
      Returns:
      the corresponding value in the given unit
    • getOffsetToStandardUnit

      public final double getOffsetToStandardUnit()
      Retrieve the offset from the standard unit.
      Returns:
      double; the offset from the standard unit
    • isBaseSIScale

      public boolean isBaseSIScale()
      Description copied from interface: Scale
      Return whether a scale is a 'standard' scale that would belong to an SI unit. 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:
      isBaseSIScale in interface Scale
      Overrides:
      isBaseSIScale in class LinearScale
      Returns:
      boolean; whether the scale is a 'standard' scale that would belong to an SI unit.
    • hashCode

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

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

      public String toString()
      Overrides:
      toString in class LinearScale