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