Package org.djunits.unit.si
Class SIDimensions
java.lang.Object
org.djunits.unit.si.SIDimensions
- All Implemented Interfaces:
Serializable
SIDimensions stores the dimensionality of a unit using the SI standards. Angle (rad) and solid angle (sr) have been added to
be able to specify often used units regarding rotation.
Copyright (c) 2019-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
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SIDimensionsthe dimensionless SIDimensions.static final intThe (currently) 9 dimensions we take into account: rad, sr, kg, m, s, A, K, mol, cd. -
Constructor Summary
ConstructorsModifierConstructorDescriptionSIDimensions(byte[] dimensions) Create an immutable SIDimensions instance based on a safe copy of a given dimensions specification.protectedSIDimensions(byte[] numerator, byte[] denominator) Create an immutable fractional SIDimensions instance based on a safe copy of a given specification, separated in a numerator and a denominator.SIDimensions(int angle, int solidAngle, int mass, int length, int time, int current, int temperature, int amountOfSubstance, int luminousIntensity) Create an immutable SIDimensions instance based on a safe copy of a given dimensions specification. -
Method Summary
Modifier and TypeMethodDescriptionstatic SIDimensionsadd(SIDimensions dim1, SIDimensions dim2) Add two SIDimensions and return the new SIDimensions.booleaninthashCode()invert()Invert a set of SI dimensions; instead of m/s we get s/m.booleanIndicate whether this SIDImensions contains one or more fractional dimensions.minus(SIDimensions other) Subtract a set of SI dimensions from this SIDimensions.static SIDimensionsParse a string representing SI dimensions to an SIDimensions object.plus(SIDimensions other) Add a set of SI dimensions to this SIDimensions.String[]Returns a safe copy of the SI abbreviations (a public static final String[] is mutable).double[]Return the (fractional) SI dimensions in the order rad, sr, kg, m, s, A, K, mol, cd.static SIDimensionssubtract(SIDimensions dim1, SIDimensions dim2) Subtract an SIDimensions (dim2) from another SIDimensions (dim1) and return the new SIDimensions.toHTMLString(boolean divided, boolean separator) Return a string such as "kgm/s2" or or "kg.m.s-2" from this SIDimensions.toString()toString(boolean divided, boolean separator) Return a string such as "kgm/s2" or "kg.m/s2" or "kg.m.s-2" from this SIDimensions.toString(boolean divided, boolean separator, boolean power) Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIDimensions.Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIDimensions.
-
Field Details
-
NUMBER_DIMENSIONS
public static final int NUMBER_DIMENSIONSThe (currently) 9 dimensions we take into account: rad, sr, kg, m, s, A, K, mol, cd.- See Also:
-
DIMLESS
the dimensionless SIDimensions.
-
-
Constructor Details
-
SIDimensions
public SIDimensions(byte[] dimensions) Create an immutable SIDimensions instance based on a safe copy of a given dimensions specification. As an example, speed is indicated as length = 1; time = -1 with the other dimensions equal to zero.- Parameters:
dimensions- The (currently) 9 dimensions of the SI unit we distinguish: 0: angle (rad), 1: solid angle (sr), 2: mass (kg), 3: length (m), 4: time (s), 5: current (A), 6: temperature (K), 7: amount of substance (mol), 8: luminous intensity (cd).
-
SIDimensions
protected SIDimensions(byte[] numerator, byte[] denominator) Create an immutable fractional SIDimensions instance based on a safe copy of a given specification, separated in a numerator and a denominator.- Parameters:
numerator- The (currently) 9 dimensions of the SI unit we distinguish: 0: angle (rad), 1: solid angle (sr), 2: mass (kg), 3: length (m), 4: time (s), 5: current (A), 6: temperature (K), 7: amount of substance (mol), 8: luminous intensity (cd).denominator- The (currently) 9 dimensions of the SI unit we distinguish: 0: angle (rad), 1: solid angle (sr), 2: mass (kg), 3: length (m), 4: time (s), 5: current (A), 6: temperature (K), 7: amount of substance (mol), 8: luminous intensity (cd).
-
SIDimensions
public SIDimensions(int angle, int solidAngle, int mass, int length, int time, int current, int temperature, int amountOfSubstance, int luminousIntensity) Create an immutable SIDimensions instance based on a safe copy of a given dimensions specification.- Parameters:
angle- dimension of the angle (rad)solidAngle- dimension of the solidAngle (sr)mass- dimension of the mass (kg)length- dimension of the length (m)time- dimension of the time (s)current- dimension of the current (A)temperature- dimension of the temperature (K)amountOfSubstance- dimension of the amount of substance (mol)luminousIntensity- dimension of the luminous intensity (cd)
-
-
Method Details
-
of
Parse a string representing SI dimensions to an SIDimensions object. Example: SIDimensions.of("kgm/s2") and SIDimensions.of("kgms-2") will both be translated to a dimensions object with vector {0,0,1,1,-2,0,0,0,0}. It is allowed to use 0 or 1 for the dimensions. Having the same unit in the numerator and the denominator is not seen as a problem: the values are subtracted from each other, so m/m will have a length dimensionality of 0. Dimensions between -9 and 9 are allowed. Spaces, periods and ^ are taken out, but other characters are not allowed and will lead to a UnitException. The order of allowed units is arbitrary, so "kg/ms2" is accepted as well as "kg/s^2.m".- Parameters:
siString- the string to parse- Returns:
- the corresponding SI dimensions
- Throws:
UnitException- when the string could not be parsed into dimensions
-
siAbbreviations
Returns a safe copy of the SI abbreviations (a public static final String[] is mutable).- Returns:
- a safe copy of the SI abbreviations
-
siDimensions
public double[] siDimensions()Return the (fractional) SI dimensions in the order rad, sr, kg, m, s, A, K, mol, cd.- Returns:
- the (fractional) SI dimensions in the order rad, sr, kg, m, s, A, K, mol, cd
-
plus
Add a set of SI dimensions to this SIDimensions. Note: as dimensions are considered to be immutable, a new dimension is returned. The original dimension (this) remains unaltered.- Parameters:
other- the dimensions to add (usually as a result of multiplication of scalars)- Returns:
- the new dimensions with the dimensions of this object plus the dimensions in the parameter
-
minus
Subtract a set of SI dimensions from this SIDimensions. Note: as dimensions are considered to be immutable, a new dimension is returned. The original dimension (this) remains unaltered.- Parameters:
other- the dimensions to subtract (usually as a result of division of scalars)- Returns:
- the new dimensions with the dimensions of this object minus the dimensions in the parameter
-
invert
Invert a set of SI dimensions; instead of m/s we get s/m. Note: as dimensions are considered to be immutable, a new dimension is returned. The original dimension (this) remains unaltered.- Returns:
- the new dimensions that are the inverse of the dimensions in this object
-
add
Add two SIDimensions and return the new SIDimensions. Usually, dimensions are added as a result of multiplication of scalars.- Parameters:
dim1- the first set of dimensionsdim2- the second set of dimensions- Returns:
- the new dimensions with the sum of the dimensions in the parameters
-
subtract
Subtract an SIDimensions (dim2) from another SIDimensions (dim1) and return the new SIDimensions. Usually, dimensions are added as a result of division of scalars.- Parameters:
dim1- the first set of dimensionsdim2- the second set of dimensions that will be subtracted from dim1- Returns:
- the new dimensions with the difference of the dimensions in the parameters
-
isFractional
public boolean isFractional()Indicate whether this SIDImensions contains one or more fractional dimensions.- Returns:
- whether this SIDImensions contains one or more fractional dimensions
-
hashCode
public int hashCode() -
equals
-
toString
Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIDimensions.- Parameters:
divided- if true, return m/s2 for acceleration; if false return ms-2separator- add this string between successive units, e.g. kg.m.s-2 instead of kgms-2powerPrefix- the prefix for the power, e.g., "^" or "<sup>"powerPostfix- the postfix for the power, e.g., "</sup>"- Returns:
- a formatted string for this SIDimensions
-
toString
Return a string such as "kgm/s2" or "kg.m/s2" or "kg.m.s-2" from this SIDimensions.- Parameters:
divided- if true, return m/s2 for acceleration; if false return ms-2separator- if true, add a period between successive units, e.g. kg.m.s-2 instead of kgms-2- Returns:
- a formatted string describing this SIDimensions
-
toString
Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIDimensions.- Parameters:
divided- if true, return m/s2 for acceleration; if false return ms-2separator- if true, add a period between successive units, e.g. kg.m.s-2 instead of kgms-2power- if true, add a ^ sign before the power, e.g., "kg.m^2/s^3" instead of "kg.m2/s3"- Returns:
- a formatted string describing this SIDimensions
-
toHTMLString
Return a string such as "kgm/s2" or or "kg.m.s-2" from this SIDimensions.- Parameters:
divided- if true, return "m/s2" for acceleration; if false return "ms-2"separator- if true, add a period between successive units, e.g. kg.m.s-2- Returns:
- a formatted string describing this SIDimensions
-
toString
-