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 * Acceleration is the rate of change of velocity over time, measured in meters per second squared (m/s2).
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 Acceleration extends Quantity<Acceleration>
21 {
22 /** Constant with value zero. */
23 public static final Acceleration ZERO = ofSi(0.0);
24
25 /** Constant with value one. */
26 public static final Acceleration ONE = ofSi(1.0);
27
28 /** Constant with value NaN. */
29 @SuppressWarnings("checkstyle:constantname")
30 public static final Acceleration NaN = ofSi(Double.NaN);
31
32 /** Constant with value POSITIVE_INFINITY. */
33 public static final Acceleration POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
34
35 /** Constant with value NEGATIVE_INFINITY. */
36 public static final Acceleration NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
37
38 /** Constant with value MAX_VALUE. */
39 public static final Acceleration POS_MAXVALUE = ofSi(Double.MAX_VALUE);
40
41 /** Constant with value -MAX_VALUE. */
42 public static final Acceleration NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
43
44 /** */
45 private static final long serialVersionUID = 600L;
46
47 /**
48 * Instantiate a Acceleration 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 Acceleration(final double valueInUnit, final Acceleration.Unit unit)
53 {
54 super(valueInUnit, unit);
55 }
56
57 /**
58 * Return a Acceleration instance based on an SI value.
59 * @param si the si value
60 * @return the Acceleration instance based on an SI value
61 */
62 public static Acceleration ofSi(final double si)
63 {
64 return new Acceleration(si, Acceleration.Unit.SI);
65 }
66
67 @Override
68 public Acceleration instantiateSi(final double si)
69 {
70 return ofSi(si);
71 }
72
73 @Override
74 public SIUnit siUnit()
75 {
76 return Acceleration.Unit.SI_UNIT;
77 }
78
79 /**
80 * Returns a Acceleration representation of a textual representation of a value with a unit. The String representation that
81 * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
82 * allowed, but not required, between the value and the unit.
83 * @param text the textual representation to parse into a Acceleration
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 Acceleration valueOf(final String text)
89 {
90 return Quantity.valueOf(text, ZERO);
91 }
92
93 /**
94 * Returns a Acceleration 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 Acceleration of(final double valueInUnit, final String unitString)
102 {
103 return Quantity.of(valueInUnit, unitString, ZERO);
104 }
105
106 @Override
107 public Acceleration.Unit getDisplayUnit()
108 {
109 return (Acceleration.Unit) super.getDisplayUnit();
110 }
111
112 /**
113 * Calculate the division of Acceleration and Acceleration, which results in a Dimensionless scalar.
114 * @param v scalar
115 * @return scalar as a division of Acceleration and Acceleration
116 */
117 public final Dimensionless divide(final Acceleration v)
118 {
119 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
120 }
121
122 /**
123 * Calculate the multiplication of Acceleration and Mass, which results in a Force scalar.
124 * @param v scalar
125 * @return scalar as a multiplication of Acceleration and Mass
126 */
127 public final Force multiply(final Mass v)
128 {
129 return new Force(this.si() * v.si(), Force.Unit.SI);
130 }
131
132 /**
133 * Calculate the multiplication of Acceleration and Duration, which results in a Speed scalar.
134 * @param v scalar
135 * @return scalar as a multiplication of Acceleration and Duration
136 */
137 public final Speed multiply(final Duration v)
138 {
139 return new Speed(this.si() * v.si(), Speed.Unit.SI);
140 }
141
142 /**
143 * Calculate the division of Acceleration and Frequency, which results in a Speed scalar.
144 * @param v scalar
145 * @return scalar as a division of Acceleration and Frequency
146 */
147 public final Speed divide(final Frequency v)
148 {
149 return new Speed(this.si() / v.si(), Speed.Unit.SI);
150 }
151
152 /**
153 * Calculate the division of Acceleration and Speed, which results in a Frequency scalar.
154 * @param v scalar
155 * @return scalar as a division of Acceleration and Speed
156 */
157 public final Frequency divide(final Speed v)
158 {
159 return new Frequency(this.si() / v.si(), Frequency.Unit.SI);
160 }
161
162 /**
163 * Calculate the multiplication of Acceleration and Momentum, which results in a Power scalar.
164 * @param v scalar
165 * @return scalar as a multiplication of Acceleration and Momentum
166 */
167 public final Power multiply(final Momentum v)
168 {
169 return new Power(this.si() * v.si(), Power.Unit.SI);
170 }
171
172 /******************************************************************************************************/
173 /********************************************** UNIT CLASS ********************************************/
174 /******************************************************************************************************/
175
176 /**
177 * Acceleration.Unit encodes the units of acceleration.
178 * <p>
179 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
180 * See for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
181 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
182 * @author Alexander Verbraeck
183 */
184 @SuppressWarnings("checkstyle:constantname")
185 public static class Unit extends AbstractUnit<Acceleration.Unit, Acceleration>
186 {
187 /** Constant for standard gravity. */
188 public static final double CONST_GRAVITY = 9.80665;
189
190 /** The dimensions of Acceleration: m/s2. */
191 public static final SIUnit SI_UNIT = SIUnit.of("m/s2");
192
193 /** m/s2. */
194 public static final Acceleration.Unit m_s2 =
195 new Acceleration.Unit("m/s2", "meter per second squared", 1.0, UnitSystem.SI_DERIVED);
196
197 /** The SI or BASE unit. */
198 public static final Acceleration.Unit SI = m_s2;
199
200 /** km/h2. */
201 public static final Acceleration.Unit km_h2 = new Acceleration.Unit("km/h2", "kilometer per hour squared",
202 1000.0 / (3600.0 * 3600.0), UnitSystem.SI_ACCEPTED);
203
204 /** ft/s2. */
205 public static final Acceleration.Unit ft_s2 =
206 new Acceleration.Unit("ft/s2", "foot per second squared", Length.Unit.CONST_FT, UnitSystem.IMPERIAL);
207
208 /** in/s2. */
209 public static final Acceleration.Unit in_s2 =
210 new Acceleration.Unit("in/s2", "inch per second squared", Length.Unit.CONST_IN, UnitSystem.IMPERIAL);
211
212 /** mi/h2. */
213 public static final Acceleration.Unit mi_h2 = new Acceleration.Unit("mi/h2", "mile per hour squared",
214 Length.Unit.CONST_MI / (3600.0 * 3600.0), UnitSystem.IMPERIAL);
215
216 /** mi/s2. */
217 public static final Acceleration.Unit mi_s2 =
218 new Acceleration.Unit("mi/s2", "mile per second squared", Length.Unit.CONST_MI, UnitSystem.IMPERIAL);
219
220 /** kt/s = Nautical Mile / h / s. */
221 public static final Acceleration.Unit kt_s =
222 new Acceleration.Unit("kt/s", "knot per second", Length.Unit.CONST_NM / 3600.0, UnitSystem.OTHER);
223
224 /** mi/h/s. */
225 public static final Acceleration.Unit mi_h_s =
226 new Acceleration.Unit("mi/h/s", "mile per hour per second", Length.Unit.CONST_MI / 3600.0, UnitSystem.IMPERIAL);
227
228 /** The standard gravity. */
229 public static final Acceleration.Unit g =
230 new Acceleration.Unit("g", "standard gravity", CONST_GRAVITY, UnitSystem.OTHER);
231
232 /** Gal or cm/s. */
233 public static final Acceleration.Unit Gal = new Acceleration.Unit("Gal", "gal", 0.01, UnitSystem.CGS);
234
235 /**
236 * Create a new Acceleration unit.
237 * @param id the id or main abbreviation of the unit
238 * @param name the full name of the unit
239 * @param scaleFactorToBaseUnit the scale factor of the unit to convert it TO the base (SI) unit
240 * @param unitSystem the unit system such as SI or IMPERIAL
241 */
242 public Unit(final String id, final String name, final double scaleFactorToBaseUnit, final UnitSystem unitSystem)
243 {
244 super(id, name, new LinearScale(scaleFactorToBaseUnit), unitSystem);
245 }
246
247 /**
248 * Return a derived unit for this unit, with textual abbreviation(s) and a display abbreviation.
249 * @param textualAbbreviation the textual abbreviation of the unit, which doubles as the id
250 * @param displayAbbreviation the display abbreviation of the unit
251 * @param name the full name of the unit
252 * @param scale the scale to use to convert between this unit and the standard (e.g., SI, BASE) unit
253 * @param unitSystem unit system, e.g. SI or Imperial
254 */
255 public Unit(final String textualAbbreviation, final String displayAbbreviation, final String name, final Scale scale,
256 final UnitSystem unitSystem)
257 {
258 super(textualAbbreviation, displayAbbreviation, name, scale, unitSystem);
259 }
260
261 @Override
262 public SIUnit siUnit()
263 {
264 return SI_UNIT;
265 }
266
267 @Override
268 public Unit getBaseUnit()
269 {
270 return SI;
271 }
272
273 @Override
274 public Acceleration ofSi(final double si)
275 {
276 return Acceleration.ofSi(si);
277 }
278
279 @Override
280 public Unit deriveUnit(final String textualAbbreviation, final String displayAbbreviation, final String name,
281 final double scaleFactor, final UnitSystem unitSystem)
282 {
283 if (getScale() instanceof LinearScale ls)
284 {
285 return new Acceleration.Unit(textualAbbreviation, displayAbbreviation, name,
286 new LinearScale(ls.getScaleFactorToBaseUnit() * scaleFactor), unitSystem);
287 }
288 throw new UnitRuntimeException("Only possible to derive a unit from a unit with a linear scale");
289 }
290
291 }
292 }