1 package org.djunits.quantity;
2
3 import org.djunits.quantity.def.Quantity;
4 import org.djunits.unit.AbstractUnit;
5 import org.djunits.unit.UnitInterface;
6 import org.djunits.unit.UnitRuntimeException;
7 import org.djunits.unit.Unitless;
8 import org.djunits.unit.scale.LinearScale;
9 import org.djunits.unit.scale.Scale;
10 import org.djunits.unit.si.SIPrefix;
11 import org.djunits.unit.si.SIUnit;
12 import org.djunits.unit.system.UnitSystem;
13
14 /**
15 * Torque is a measure of rotational force about an axis, measured in newton meters (Nm).
16 * <p>
17 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
18 * for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
19 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
20 * @author Alexander Verbraeck
21 */
22 public class Torque extends Quantity<Torque>
23 {
24 /** Constant with value zero. */
25 public static final Torque ZERO = ofSi(0.0);
26
27 /** Constant with value one. */
28 public static final Torque ONE = ofSi(1.0);
29
30 /** Constant with value NaN. */
31 @SuppressWarnings("checkstyle:constantname")
32 public static final Torque NaN = ofSi(Double.NaN);
33
34 /** Constant with value POSITIVE_INFINITY. */
35 public static final Torque POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
36
37 /** Constant with value NEGATIVE_INFINITY. */
38 public static final Torque NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
39
40 /** Constant with value MAX_VALUE. */
41 public static final Torque POS_MAXVALUE = ofSi(Double.MAX_VALUE);
42
43 /** Constant with value -MAX_VALUE. */
44 public static final Torque NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
45
46 /** */
47 private static final long serialVersionUID = 600L;
48
49 /**
50 * Instantiate a Torque quantity with an SI or base value and a display unit.
51 * @param value the quantity value expressed in the SI or base unit
52 * @param displayUnit the display unit to use
53 * @param useSi use SI value when true, use value in unit when false
54 */
55 public Torque(final double value, final Torque.Unit displayUnit, final boolean useSi)
56 {
57 super(value, displayUnit, useSi);
58 }
59
60 /**
61 * Instantiate a Torque quantity expressed in the given unit.
62 * @param valueInUnit the quantity value expressed in the given unit
63 * @param unit the unit of the value, also acts as the display unit
64 */
65 public Torque(final double valueInUnit, final Torque.Unit unit)
66 {
67 this(valueInUnit, unit, false);
68 }
69
70 /**
71 * Return a Torque instance based on an SI value.
72 * @param si the si value
73 * @return the Torque instance based on an SI value
74 */
75 public static Torque ofSi(final double si)
76 {
77 return new Torque(si, Torque.Unit.SI, true);
78 }
79
80 /**
81 * Instantiate a Torque quantity with an SI or base value and a display unit.
82 * @param siValue the quantity value expressed in the SI or base unit
83 * @param displayUnit the display unit to use
84 * @return the Torque instance based on an SI value with the given display unit
85 */
86 public static Torque ofSi(final double siValue, final Torque.Unit displayUnit)
87 {
88 return new Torque(siValue, displayUnit, true);
89 }
90
91 @Override
92 public Torque instantiateSi(final double siValue, final UnitInterface<Torque> displayUnit)
93 {
94 return new Torque(siValue, (Torque.Unit) displayUnit, true);
95 }
96
97 /**
98 * Returns a Torque representation of a textual representation of a value with a unit. The String representation that can be
99 * parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are allowed,
100 * but not required, between the value and the unit.
101 * @param text the textual representation to parse into a Torque
102 * @return the Scalar representation of the value in its unit
103 * @throws IllegalArgumentException when the text cannot be parsed
104 * @throws NullPointerException when the text argument is null
105 */
106 public static Torque valueOf(final String text)
107 {
108 return Quantity.valueOf(text, ZERO);
109 }
110
111 /**
112 * Returns a Torque based on a value expressed in the unit.
113 * @param valueInUnit the value, expressed in the given unit
114 * @param unit the unit of the value, also acts as the display unit
115 * @return ab Torque representation of the value in its unit
116 */
117 public static Torque of(final double valueInUnit, final Torque.Unit unit)
118 {
119 return new Torque(valueInUnit, unit);
120 }
121
122 /**
123 * Returns a Torque based on a value and the textual representation of the unit, which can be localized.
124 * @param valueInUnit the value, expressed in the unit as given by unitString
125 * @param unitString the textual representation of the unit
126 * @return the Scalar representation of the value in its unit
127 * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
128 * @throws NullPointerException when the unitString argument is null
129 */
130 public static Torque of(final double valueInUnit, final String unitString)
131 {
132 return Quantity.of(valueInUnit, unitString, ZERO);
133 }
134
135 @Override
136 public Torque.Unit getDisplayUnit()
137 {
138 return (Torque.Unit) super.getDisplayUnit();
139 }
140
141 /**
142 * Calculate the division of Torque and Torque, which results in a Dimensionless quantity.
143 * @param v quantity
144 * @return quantity as a division of Torque and Torque
145 */
146 public Dimensionless divide(final Torque v)
147 {
148 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
149 }
150
151 /**
152 * Calculate the division of Torque and Force, which results in a Length scalar.
153 * @param v scalar
154 * @return scalar as a division of Torque and Force
155 */
156 public Length divide(final Force v)
157 {
158 return new Length(this.si() / v.si(), Length.Unit.SI);
159 }
160
161 /**
162 * Calculate the division of Torque and Length, which results in a Force scalar.
163 * @param v scalar
164 * @return scalar as a division of Torque and Length
165 */
166 public Force divide(final Length v)
167 {
168 return new Force(this.si() / v.si(), Force.Unit.SI);
169 }
170
171 /**
172 * Calculate the multiplication of Torque and LinearObjectDensity, which results in a Force scalar.
173 * @param v scalar
174 * @return scalar as a multiplication of Torque and LinearObjectDensity
175 */
176 public Force multiply(final LinearObjectDensity v)
177 {
178 return new Force(this.si() * v.si(), Force.Unit.SI);
179 }
180
181 /**
182 * Calculate the division of Torque and Duration, which results in a Power scalar.
183 * @param v scalar
184 * @return scalar as a division of Torque and Duration
185 */
186 public Power divide(final Duration v)
187 {
188 return new Power(this.si() / v.si(), Power.Unit.SI);
189 }
190
191 /**
192 * Calculate the division of Torque and Power, which results in a Duration scalar.
193 * @param v scalar
194 * @return scalar as a division of Torque and Power
195 */
196 public Duration divide(final Power v)
197 {
198 return new Duration(this.si() / v.si(), Duration.Unit.SI);
199 }
200
201 /**
202 * Calculate the multiplication of Torque and Frequency, which results in a Power scalar.
203 * @param v scalar
204 * @return scalar as a multiplication of Torque and Frequency
205 */
206 public Power multiply(final Frequency v)
207 {
208 return new Power(this.si() * v.si(), Power.Unit.SI);
209 }
210
211 /**
212 * Calculate the division of Torque and Volume, which results in a Pressure scalar.
213 * @param v scalar
214 * @return scalar as a division of Torque and Volume
215 */
216 public Pressure divide(final Volume v)
217 {
218 return new Pressure(this.si() / v.si(), Pressure.Unit.SI);
219 }
220
221 /**
222 * Calculate the division of Torque and Pressure, which results in a Volume scalar.
223 * @param v scalar
224 * @return scalar as a division of Torque and Pressure
225 */
226 public Volume divide(final Pressure v)
227 {
228 return new Volume(this.si() / v.si(), Volume.Unit.SI);
229 }
230
231 /******************************************************************************************************/
232 /********************************************** UNIT CLASS ********************************************/
233 /******************************************************************************************************/
234
235 /**
236 * Torque.Unit encodes the units of rotational force about an axis, measured in newton meters (Nm).
237 * <p>
238 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
239 * See for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
240 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
241 * @author Alexander Verbraeck
242 */
243 @SuppressWarnings("checkstyle:constantname")
244 public static class Unit extends AbstractUnit<Torque>
245 {
246 /** The dimensions of torque: kgm2/s2. */
247 public static final SIUnit SI_UNIT = SIUnit.of("kgm2/s2");
248
249 /** Newton meter. */
250 public static final Torque.Unit Nm = new Torque.Unit("Nm", "newton meter", 1.0, UnitSystem.SI_DERIVED);
251
252 /** The SI or BASE unit. */
253 public static final Torque.Unit SI = Nm;
254
255 /** meter kilogram-force. */
256 public static final Torque.Unit m_kgf =
257 SI.deriveUnit("m.kgf", "meter kilogram-force", Acceleration.Unit.CONST_GRAVITY, UnitSystem.OTHER);
258
259 /** Pound foot. */
260 public static final Torque.Unit lbf_ft = SI.deriveUnit("lbf.ft", "pound-force foot",
261 Length.Unit.CONST_FT * Mass.Unit.CONST_LB * Acceleration.Unit.CONST_GRAVITY, UnitSystem.IMPERIAL);
262
263 /** Pound inch. */
264 public static final Torque.Unit lbf_in = SI.deriveUnit("lbf.in", "pound-force inch",
265 Length.Unit.CONST_IN * Mass.Unit.CONST_LB * Acceleration.Unit.CONST_GRAVITY, UnitSystem.IMPERIAL);
266
267 /**
268 * Create a new Torque unit.
269 * @param id the id or main abbreviation of the unit
270 * @param name the full name of the unit
271 * @param scaleFactorToBaseUnit the scale factor of the unit to convert it TO the base (SI) unit
272 * @param unitSystem the unit system such as SI or IMPERIAL
273 */
274 public Unit(final String id, final String name, final double scaleFactorToBaseUnit, final UnitSystem unitSystem)
275 {
276 super(id, name, scaleFactorToBaseUnit, unitSystem);
277 }
278
279 /**
280 * Return a derived unit for this unit, with textual abbreviation(s) and a display abbreviation.
281 * @param textualAbbreviation the textual abbreviation of the unit, which doubles as the id
282 * @param displayAbbreviation the display abbreviation of the unit
283 * @param name the full name of the unit
284 * @param scale the scale to use to convert from this unit to the standard (e.g., SI, BASE) unit
285 * @param unitSystem unit system, e.g. SI or Imperial
286 * @param siPrefix the SI Prefix of this unit
287 */
288 public Unit(final String textualAbbreviation, final String displayAbbreviation, final String name, final Scale scale,
289 final UnitSystem unitSystem, final SIPrefix siPrefix)
290 {
291 super(textualAbbreviation, displayAbbreviation, name, scale, unitSystem, siPrefix);
292 }
293
294 @Override
295 public SIUnit siUnit()
296 {
297 return SI_UNIT;
298 }
299
300 @Override
301 public Unit getBaseUnit()
302 {
303 return SI;
304 }
305
306 @Override
307 public Torque ofSi(final double si, final UnitInterface<Torque> displayUnit)
308 {
309 return new Torque(si, (Unit) displayUnit, true);
310 }
311
312 @Override
313 public Torque.Unit deriveUnit(final String textualAbbreviation, final String displayAbbreviation, final String name,
314 final double scaleFactor, final UnitSystem unitSystem, final SIPrefix siPrefix)
315 {
316 if (getScale() instanceof LinearScale ls)
317 {
318 return new Torque.Unit(textualAbbreviation, displayAbbreviation, name,
319 new LinearScale(ls.getScaleFactorToBaseUnit() * scaleFactor), unitSystem, siPrefix);
320 }
321 throw new UnitRuntimeException("Only possible to derive a unit from a unit with a linear scale");
322 }
323
324 @Override
325 public Torque.Unit deriveUnit(final String abbreviation, final String name, final double scaleFactor,
326 final UnitSystem unitSystem)
327 {
328 return (Unit) super.deriveUnit(abbreviation, name, scaleFactor, unitSystem);
329 }
330
331 }
332
333 }