Class OffsetLinearScale
- All Implemented Interfaces:
Serializable,Scale
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-2025 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
ConstructorsConstructorDescriptionOffsetLinearScale(double conversionFactorToStandardUnit, double offsetToStandardUnit) Construct a Scale for linear transformations with an offset, e.g. for Temperature. -
Method Summary
Modifier and TypeMethodDescriptionbooleanfinal doublefromStandardUnit(double value) Convert a value from an SI value to a value in the unit that uses this scale.final doubleRetrieve the offset from the standard unit.inthashCode()booleanReturn whether a scale is a 'standard' scale that would belong to an SI unit.final doubletoStandardUnit(double value) Convert a value to an SI value using this scale.toString()Methods inherited from class org.djunits.unit.scale.LinearScale
getConversionFactorToStandardUnit
-
Constructor Details
-
OffsetLinearScale
public OffsetLinearScale(double conversionFactorToStandardUnit, double offsetToStandardUnit) Construct a Scale for linear transformations with an offset, e.g. for Temperature.- Parameters:
conversionFactorToStandardUnit- the conversion factor by which this number has to be multiplied to convert it to the standard (e.g., SI) unit.offsetToStandardUnit- when converting to a standard unit, the offset is applied first.
-
-
Method Details
-
toStandardUnit
public final double toStandardUnit(double value) Description copied from interface:ScaleConvert a value to an SI value using this scale.- Specified by:
toStandardUnitin interfaceScale- Overrides:
toStandardUnitin classLinearScale- Parameters:
value- the value to convert- Returns:
- the corresponding SI value
-
fromStandardUnit
public final double fromStandardUnit(double value) Description copied from interface:ScaleConvert a value from an SI value to a value in the unit that uses this scale.- Specified by:
fromStandardUnitin interfaceScale- Overrides:
fromStandardUnitin classLinearScale- Parameters:
value- 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:
- the offset from the standard unit
-
isBaseSIScale
public boolean isBaseSIScale()Description copied from interface:ScaleReturn 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:
isBaseSIScalein interfaceScale- Overrides:
isBaseSIScalein classLinearScale- Returns:
- whether the scale is a 'standard' scale that would belong to an SI unit.
-
hashCode
public int hashCode()- Overrides:
hashCodein classLinearScale
-
equals
- Overrides:
equalsin classLinearScale
-
toString
- Overrides:
toStringin classLinearScale
-