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