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 * Angular acceleration is the rate of change of angular velocity over time, measured in radians per second squared (rad/s2).
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 AngularAcceleration extends Quantity<AngularAcceleration>
23 {
24 /** Constant with value zero. */
25 public static final AngularAcceleration ZERO = ofSi(0.0);
26
27 /** Constant with value one. */
28 public static final AngularAcceleration ONE = ofSi(1.0);
29
30 /** Constant with value NaN. */
31 @SuppressWarnings("checkstyle:constantname")
32 public static final AngularAcceleration NaN = ofSi(Double.NaN);
33
34 /** Constant with value POSITIVE_INFINITY. */
35 public static final AngularAcceleration POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
36
37 /** Constant with value NEGATIVE_INFINITY. */
38 public static final AngularAcceleration NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
39
40 /** Constant with value MAX_VALUE. */
41 public static final AngularAcceleration POS_MAXVALUE = ofSi(Double.MAX_VALUE);
42
43 /** Constant with value -MAX_VALUE. */
44 public static final AngularAcceleration NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
45
46 /** */
47 private static final long serialVersionUID = 600L;
48
49 /**
50 * Instantiate a AngularAcceleration 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 AngularAcceleration(final double value, final AngularAcceleration.Unit displayUnit, final boolean useSi)
56 {
57 super(value, displayUnit, useSi);
58 }
59
60 /**
61 * Instantiate a AngularAcceleration 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 AngularAcceleration(final double valueInUnit, final AngularAcceleration.Unit unit)
66 {
67 this(valueInUnit, unit, false);
68 }
69
70 /**
71 * Return a AngularAcceleration instance based on an SI value.
72 * @param si the si value
73 * @return the AngularAcceleration instance based on an SI value
74 */
75 public static AngularAcceleration ofSi(final double si)
76 {
77 return new AngularAcceleration(si, AngularAcceleration.Unit.SI, true);
78 }
79
80 /**
81 * Instantiate a AngularAcceleration 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 AngularAcceleration instance based on an SI value with the given display unit
85 */
86 public static AngularAcceleration ofSi(final double siValue, final AngularAcceleration.Unit displayUnit)
87 {
88 return new AngularAcceleration(siValue, displayUnit, true);
89 }
90
91 @Override
92 public AngularAcceleration instantiateSi(final double siValue, final UnitInterface<AngularAcceleration> displayUnit)
93 {
94 return new AngularAcceleration(siValue, (AngularAcceleration.Unit) displayUnit, true);
95 }
96
97 /**
98 * Returns a AngularAcceleration representation of a textual representation of a value with a unit. The String
99 * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
100 * unit. Spaces are allowed, but not required, between the value and the unit.
101 * @param text the textual representation to parse into a AngularAcceleration
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 AngularAcceleration valueOf(final String text)
107 {
108 return Quantity.valueOf(text, ZERO);
109 }
110
111 /**
112 * Returns a AngularAcceleration 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 AngularAcceleration representation of the value in its unit
116 */
117 public static AngularAcceleration of(final double valueInUnit, final AngularAcceleration.Unit unit)
118 {
119 return new AngularAcceleration(valueInUnit, unit);
120 }
121
122 /**
123 * Returns a AngularAcceleration 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 AngularAcceleration of(final double valueInUnit, final String unitString)
131 {
132 return Quantity.of(valueInUnit, unitString, ZERO);
133 }
134
135 @Override
136 public AngularAcceleration.Unit getDisplayUnit()
137 {
138 return (AngularAcceleration.Unit) super.getDisplayUnit();
139 }
140
141 /**
142 * Calculate the division of AngularAcceleration and AngularAcceleration, which results in a Dimensionless scalar.
143 * @param v scalar
144 * @return scalar as a division of AngularAcceleration and AngularAcceleration
145 */
146 public Dimensionless divide(final AngularAcceleration v)
147 {
148 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
149 }
150
151 /**
152 * Calculate the multiplication of AngularAcceleration and Duration, which results in a AngularVelocity scalar.
153 * @param v scalar
154 * @return scalar as a multiplication of AngularAcceleration and Duration
155 */
156 public AngularVelocity multiply(final Duration v)
157 {
158 return new AngularVelocity(this.si() * v.si(), AngularVelocity.Unit.SI);
159 }
160
161 /**
162 * Calculate the division of AngularAcceleration and Frequency, which results in a AngularVelocity scalar.
163 * @param v scalar
164 * @return scalar as a division of AngularAcceleration and Frequency
165 */
166 public AngularVelocity divide(final Frequency v)
167 {
168 return new AngularVelocity(this.si() / v.si(), AngularVelocity.Unit.SI);
169 }
170
171 /**
172 * Calculate the division of AngularAcceleration and AngularVelocity, which results in a Frequency scalar.
173 * @param v scalar
174 * @return scalar as a division of AngularAcceleration and AngularVelocity
175 */
176 public Frequency divide(final AngularVelocity v)
177 {
178 return new Frequency(this.si() / v.si(), Frequency.Unit.SI);
179 }
180
181 /******************************************************************************************************/
182 /********************************************** UNIT CLASS ********************************************/
183 /******************************************************************************************************/
184
185 /**
186 * AngularAcceleration.Unit encodes the units of angle (radians or degrees per second squared).
187 * <p>
188 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
189 * See for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
190 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
191 * @author Alexander Verbraeck
192 */
193 @SuppressWarnings("checkstyle:constantname")
194 public static class Unit extends AbstractUnit<AngularAcceleration>
195 {
196 /** The dimensions of AngularAcceleration: rad/s2. */
197 public static final SIUnit SI_UNIT = SIUnit.of("rad/s2");
198
199 /** radian per second squared. */
200 public static final AngularAcceleration.Unit rad_s2 =
201 new AngularAcceleration.Unit("rad/s2", "radians per second squared", 1.0, UnitSystem.SI_DERIVED);
202
203 /** The SI or BASE unit. */
204 public static final AngularAcceleration.Unit SI = rad_s2;
205
206 /** degree per second squared. */
207 public static final AngularAcceleration.Unit deg_s2 = rad_s2.deriveUnit("deg/s2", "\u00b0/s2",
208 "degree per second squared", Math.PI / 180.0, UnitSystem.SI_ACCEPTED, null);
209
210 /** arcminute per second squared. */
211 public static final AngularAcceleration.Unit arcmin_s2 =
212 deg_s2.deriveUnit("arcmin/s2", "'/s2", "arcminute per second squared", 1.0 / 60.0, UnitSystem.OTHER, null);
213
214 /** arcsecond per second squared. */
215 public static final AngularAcceleration.Unit arcsec_s2 =
216 deg_s2.deriveUnit("arcsec/s2", "\"/s2", "arcsecond per second squared", 1.0 / 3600.0, UnitSystem.OTHER, null);
217
218 /** grad per second squared. */
219 public static final AngularAcceleration.Unit grad_s2 = rad_s2.deriveUnit("grad/s2", "grad/s2",
220 "gradian per second squared", 2.0 * Math.PI / 400.0, UnitSystem.OTHER, null);
221
222 /** centesimal arcminute per second squared. */
223 public static final AngularAcceleration.Unit cdm_s2 = grad_s2.deriveUnit("cdm/s2", "c'/s2",
224 "centesimal arcminute per second squared", 1.0 / 100.0, UnitSystem.OTHER, null);
225
226 /** centesimal arcsecond per second squared. */
227 public static final AngularAcceleration.Unit cds_s2 = grad_s2.deriveUnit("cds/s2", "c\"/s2",
228 "centesimal arcsecond per second squared", 1.0 / 10000.0, UnitSystem.OTHER, null);
229
230 /**
231 * Create a new AngularAcceleration unit.
232 * @param id the id or main abbreviation of the unit
233 * @param name the full name of the unit
234 * @param scaleFactorToBaseUnit the scale factor of the unit to convert it TO the base (SI) unit
235 * @param unitSystem the unit system such as SI or IMPERIAL
236 */
237 public Unit(final String id, final String name, final double scaleFactorToBaseUnit, final UnitSystem unitSystem)
238 {
239 super(id, name, scaleFactorToBaseUnit, unitSystem);
240 }
241
242 /**
243 * Return a derived unit for this unit, with textual abbreviation(s) and a display abbreviation.
244 * @param textualAbbreviation the textual abbreviation of the unit, which doubles as the id
245 * @param displayAbbreviation the display abbreviation of the unit
246 * @param name the full name of the unit
247 * @param scale the scale to use to convert from this unit to the standard (e.g., SI, BASE) unit
248 * @param unitSystem unit system, e.g. SI or Imperial
249 * @param siPrefix the SI Prefix of this unit
250 */
251 public Unit(final String textualAbbreviation, final String displayAbbreviation, final String name, final Scale scale,
252 final UnitSystem unitSystem, final SIPrefix siPrefix)
253 {
254 super(textualAbbreviation, displayAbbreviation, name, scale, unitSystem, siPrefix);
255 }
256
257 @Override
258 public SIUnit siUnit()
259 {
260 return SI_UNIT;
261 }
262
263 @Override
264 public Unit getBaseUnit()
265 {
266 return SI;
267 }
268
269 @Override
270 public AngularAcceleration ofSi(final double si, final UnitInterface<AngularAcceleration> displayUnit)
271 {
272 return new AngularAcceleration(si, (Unit) displayUnit, true);
273 }
274
275 @Override
276 public AngularAcceleration.Unit deriveUnit(final String textualAbbreviation, final String displayAbbreviation,
277 final String name, final double scaleFactor, final UnitSystem unitSystem, final SIPrefix siPrefix)
278 {
279 if (getScale() instanceof LinearScale ls)
280 {
281 return new AngularAcceleration.Unit(textualAbbreviation, displayAbbreviation, name,
282 new LinearScale(ls.getScaleFactorToBaseUnit() * scaleFactor), unitSystem, siPrefix);
283 }
284 throw new UnitRuntimeException("Only possible to derive a unit from a unit with a linear scale");
285 }
286
287 }
288
289 }