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