View Javadoc
1   package org.opentrafficsim.road.network.speed;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.unit.SpeedUnit;
6   import org.djunits.value.vdouble.scalar.Acceleration;
7   import org.djunits.value.vdouble.scalar.Length;
8   import org.djunits.value.vdouble.scalar.Speed;
9   import org.djutils.exceptions.Throw;
10  
11  /**
12   * Class with curvature info for curvature speed limit type.
13   * <p>
14   * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 30, 2016 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
20   */
21  public class SpeedInfoCurvature implements Serializable
22  {
23  
24      /** */
25      private static final long serialVersionUID = 20160501L;
26  
27      /** Curvature radius. */
28      private final Length radius;
29  
30      /**
31       * Constructor with curvature radius.
32       * @param radius Length; curvature radius
33       * @throws NullPointerException if radius is null
34       */
35      public SpeedInfoCurvature(final Length radius)
36      {
37          Throw.whenNull(radius, "Radius may not be null.");
38          this.radius = radius;
39      }
40  
41      /**
42       * Returns the curvature radius.
43       * @return curvature radius
44       */
45      public final Length getRadius()
46      {
47          return this.radius;
48      }
49  
50      /**
51       * Returns the speed for which the current lateral acceleration follows in the corner.
52       * @param acceleration Acceleration; acceleration to result from speed in corner
53       * @return speed for which the current lateral acceleration follows in the corner
54       * @throws NullPointerException if acceleration is null
55       */
56      public final Speed getSpeedForLateralAcceleration(final Acceleration acceleration)
57      {
58          Throw.whenNull(acceleration, "Acceleration may not be null.");
59          // a=v*v/r => v=sqrt(a*r)
60          return new Speed(Math.sqrt(acceleration.si * this.radius.si), SpeedUnit.SI);
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public final int hashCode()
66      {
67          return this.radius.hashCode();
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public final boolean equals(final Object obj)
73      {
74          if (this == obj)
75          {
76              return true;
77          }
78          if (obj == null)
79          {
80              return false;
81          }
82          if (getClass() != obj.getClass())
83          {
84              return false;
85          }
86          SpeedInfoCurvature other = (SpeedInfoCurvature) obj;
87          if (!this.radius.equals(other.radius))
88          {
89              return false;
90          }
91          return true;
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public final String toString()
97      {
98          return "SpeedInfoCurvature [radius=" + this.radius + "]";
99      }
100 
101 }