1 package org.djunits.value.vdouble.scalar;
2
3 import org.djunits.unit.DimensionlessUnit;
4 import org.djunits.unit.DurationUnit;
5 import org.djunits.unit.ForceUnit;
6 import org.djunits.unit.LengthUnit;
7 import org.djunits.unit.PowerUnit;
8 import org.djunits.unit.PressureUnit;
9 import org.djunits.unit.TorqueUnit;
10 import org.djunits.unit.VolumeUnit;
11
12 /**
13 * Easy access methods for the Torque DoubleScalar, which is relative by definition. Instead of:
14 *
15 * <pre>
16 * DoubleScalar.Rel<TorqueUnit> value = new DoubleScalar.Rel<TorqueUnit>(100.0, TorqueUnit.SI);
17 * </pre>
18 *
19 * we can now write:
20 *
21 * <pre>
22 * Torque value = new Torque(100.0, TorqueUnit.SI);
23 * </pre>
24 *
25 * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit
26 * used are compatible.
27 * <p>
28 * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
29 * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
30 * <p>
31 * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
32 * initial version Sep 5, 2015 <br>
33 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
34 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
35 */
36 public class Torque extends AbstractDoubleScalarRel<TorqueUnit, Torque>
37 {
38 /** */
39 private static final long serialVersionUID = 20150905L;
40
41 /** constant with value zero. */
42 public static final Torque ZERO = new Torque(0.0, TorqueUnit.SI);
43
44 /** constant with value NaN. */
45 @SuppressWarnings("checkstyle:constantname")
46 public static final Torque NaN = new Torque(Double.NaN, TorqueUnit.SI);
47
48 /** constant with value POSITIVE_INFINITY. */
49 public static final Torque POSITIVE_INFINITY = new Torque(Double.POSITIVE_INFINITY, TorqueUnit.SI);
50
51 /** constant with value NEGATIVE_INFINITY. */
52 public static final Torque NEGATIVE_INFINITY = new Torque(Double.NEGATIVE_INFINITY, TorqueUnit.SI);
53
54 /** constant with value MAX_VALUE. */
55 public static final Torque POS_MAXVALUE = new Torque(Double.MAX_VALUE, TorqueUnit.SI);
56
57 /** constant with value -MAX_VALUE. */
58 public static final Torque NEG_MAXVALUE = new Torque(-Double.MAX_VALUE, TorqueUnit.SI);
59
60 /**
61 * Construct Torque scalar.
62 * @param value double value
63 * @param unit unit for the double value
64 */
65 public Torque(final double value, final TorqueUnit unit)
66 {
67 super(value, unit);
68 }
69
70 /**
71 * Construct Torque scalar.
72 * @param value Scalar from which to construct this instance
73 */
74 public Torque(final Torque value)
75 {
76 super(value);
77 }
78
79 /** {@inheritDoc} */
80 @Override
81 public final Torque instantiateRel(final double value, final TorqueUnit unit)
82 {
83 return new Torque(value, unit);
84 }
85
86 /**
87 * Construct Torque scalar.
88 * @param value double value in SI units
89 * @return the new scalar with the SI value
90 */
91 public static final Torque createSI(final double value)
92 {
93 return new Torque(value, TorqueUnit.SI);
94 }
95
96 /**
97 * Interpolate between two values.
98 * @param zero the low value
99 * @param one the high value
100 * @param ratio the ratio between 0 and 1, inclusive
101 * @return a Scalar at the ratio between
102 */
103 public static Torque interpolate(final Torque zero, final Torque one, final double ratio)
104 {
105 return new Torque(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
106 }
107
108 /**
109 * Return the maximum value of two relative scalars.
110 * @param r1 the first scalar
111 * @param r2 the second scalar
112 * @return the maximum value of two relative scalars
113 */
114 public static Torque max(final Torque r1, final Torque r2)
115 {
116 return (r1.gt(r2)) ? r1 : r2;
117 }
118
119 /**
120 * Return the maximum value of more than two relative scalars.
121 * @param r1 the first scalar
122 * @param r2 the second scalar
123 * @param rn the other scalars
124 * @return the maximum value of more than two relative scalars
125 */
126 public static Torque max(final Torque r1, final Torque r2, final Torque... rn)
127 {
128 Torque maxr = (r1.gt(r2)) ? r1 : r2;
129 for (Torque r : rn)
130 {
131 if (r.gt(maxr))
132 {
133 maxr = r;
134 }
135 }
136 return maxr;
137 }
138
139 /**
140 * Return the minimum value of two relative scalars.
141 * @param r1 the first scalar
142 * @param r2 the second scalar
143 * @return the minimum value of two relative scalars
144 */
145 public static Torque min(final Torque r1, final Torque r2)
146 {
147 return (r1.lt(r2)) ? r1 : r2;
148 }
149
150 /**
151 * Return the minimum value of more than two relative scalars.
152 * @param r1 the first scalar
153 * @param r2 the second scalar
154 * @param rn the other scalars
155 * @return the minimum value of more than two relative scalars
156 */
157 public static Torque min(final Torque r1, final Torque r2, final Torque... rn)
158 {
159 Torque minr = (r1.lt(r2)) ? r1 : r2;
160 for (Torque r : rn)
161 {
162 if (r.lt(minr))
163 {
164 minr = r;
165 }
166 }
167 return minr;
168 }
169
170 /**
171 * Calculate the division of Torque and Torque, which results in a Dimensionless scalar.
172 * @param v Torque scalar
173 * @return Dimensionless scalar as a division of Torque and Torque
174 */
175 public final Dimensionless divideBy(final Torque v)
176 {
177 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
178 }
179
180 /**
181 * Calculate the division of Torque and Force, which results in a Length scalar.
182 * @param v Torque scalar
183 * @return Length scalar as a division of Torque and Force
184 */
185 public final Length divideBy(final Force v)
186 {
187 return new Length(this.si / v.si, LengthUnit.SI);
188 }
189
190 /**
191 * Calculate the division of Torque and Length, which results in a Force scalar.
192 * @param v Torque scalar
193 * @return Force scalar as a division of Torque and Length
194 */
195 public final Force divideBy(final Length v)
196 {
197 return new Force(this.si / v.si, ForceUnit.SI);
198 }
199
200 /**
201 * Calculate the multiplication of Torque and LinearDensity, which results in a Force scalar.
202 * @param v Torque scalar
203 * @return Force scalar as a multiplication of Torque and LinearDensity
204 */
205 public final Force multiplyBy(final LinearDensity v)
206 {
207 return new Force(this.si * v.si, ForceUnit.SI);
208 }
209
210 /**
211 * Calculate the division of Torque and Duration, which results in a Power scalar.
212 * @param v Torque scalar
213 * @return Power scalar as a division of Torque and Duration
214 */
215 public final Power divideBy(final Duration v)
216 {
217 return new Power(this.si / v.si, PowerUnit.SI);
218 }
219
220 /**
221 * Calculate the division of Torque and Power, which results in a Duration scalar.
222 * @param v Torque scalar
223 * @return Duration scalar as a division of Torque and Power
224 */
225 public final Duration divideBy(final Power v)
226 {
227 return new Duration(this.si / v.si, DurationUnit.SI);
228 }
229
230 /**
231 * Calculate the multiplication of Torque and Frequency, which results in a Power scalar.
232 * @param v Torque scalar
233 * @return Power scalar as a multiplication of Torque and Frequency
234 */
235 public final Power multiplyBy(final Frequency v)
236 {
237 return new Power(this.si * v.si, PowerUnit.SI);
238 }
239
240 /**
241 * Calculate the division of Torque and Volume, which results in a Pressure scalar.
242 * @param v Torque scalar
243 * @return Pressure scalar as a division of Torque and Volume
244 */
245 public final Pressure divideBy(final Volume v)
246 {
247 return new Pressure(this.si / v.si, PressureUnit.SI);
248 }
249
250 /**
251 * Calculate the division of Torque and Pressure, which results in a Volume scalar.
252 * @param v Torque scalar
253 * @return Volume scalar as a division of Torque and Pressure
254 */
255 public final Volume divideBy(final Pressure v)
256 {
257 return new Volume(this.si / v.si, VolumeUnit.SI);
258 }
259
260 }