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