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