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