SpeedInfoCurvature.java

  1. package org.opentrafficsim.road.network.speed;

  2. import java.io.Serializable;

  3. import org.djunits.unit.SpeedUnit;
  4. import org.djunits.value.vdouble.scalar.Acceleration;
  5. import org.djunits.value.vdouble.scalar.Length;
  6. import org.djunits.value.vdouble.scalar.Speed;
  7. import org.djutils.exceptions.Throw;

  8. /**
  9.  * Class with curvature info for curvature speed limit type.
  10.  * <p>
  11.  * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  12.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
  13.  * <p>
  14.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 30, 2016 <br>
  15.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  16.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  17.  */
  18. public class SpeedInfoCurvature implements Serializable
  19. {

  20.     /** */
  21.     private static final long serialVersionUID = 20160501L;

  22.     /** Curvature radius. */
  23.     private final Length radius;

  24.     /**
  25.      * Constructor with curvature radius.
  26.      * @param radius Length; curvature radius
  27.      * @throws NullPointerException if radius is null
  28.      */
  29.     public SpeedInfoCurvature(final Length radius)
  30.     {
  31.         Throw.whenNull(radius, "Radius may not be null.");
  32.         this.radius = radius;
  33.     }

  34.     /**
  35.      * Returns the curvature radius.
  36.      * @return curvature radius
  37.      */
  38.     public final Length getRadius()
  39.     {
  40.         return this.radius;
  41.     }

  42.     /**
  43.      * Returns the speed for which the current lateral acceleration follows in the corner.
  44.      * @param acceleration Acceleration; acceleration to result from speed in corner
  45.      * @return speed for which the current lateral acceleration follows in the corner
  46.      * @throws NullPointerException if acceleration is null
  47.      */
  48.     public final Speed getSpeedForLateralAcceleration(final Acceleration acceleration)
  49.     {
  50.         Throw.whenNull(acceleration, "Acceleration may not be null.");
  51.         // a=v*v/r => v=sqrt(a*r)
  52.         return new Speed(Math.sqrt(acceleration.si * this.radius.si), SpeedUnit.SI);
  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public final int hashCode()
  57.     {
  58.         return this.radius.hashCode();
  59.     }

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     public final boolean equals(final Object obj)
  63.     {
  64.         if (this == obj)
  65.         {
  66.             return true;
  67.         }
  68.         if (obj == null)
  69.         {
  70.             return false;
  71.         }
  72.         if (getClass() != obj.getClass())
  73.         {
  74.             return false;
  75.         }
  76.         SpeedInfoCurvature other = (SpeedInfoCurvature) obj;
  77.         if (!this.radius.equals(other.radius))
  78.         {
  79.             return false;
  80.         }
  81.         return true;
  82.     }

  83.     /** {@inheritDoc} */
  84.     @Override
  85.     public final String toString()
  86.     {
  87.         return "SpeedInfoCurvature [radius=" + this.radius + "]";
  88.     }

  89. }