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-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16 * </p>
17 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
18 * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
19 */
20 public class SpeedInfoCurvature implements Serializable
21 {
22
23 /** */
24 private static final long serialVersionUID = 20160501L;
25
26 /** Curvature radius. */
27 private final Length radius;
28
29 /**
30 * Constructor with curvature radius.
31 * @param radius Length; curvature radius
32 * @throws NullPointerException if radius is null
33 */
34 public SpeedInfoCurvature(final Length radius)
35 {
36 Throw.whenNull(radius, "Radius may not be null.");
37 this.radius = radius;
38 }
39
40 /**
41 * Returns the curvature radius.
42 * @return curvature radius
43 */
44 public final Length getRadius()
45 {
46 return this.radius;
47 }
48
49 /**
50 * Returns the speed for which the current lateral acceleration follows in the corner.
51 * @param acceleration Acceleration; acceleration to result from speed in corner
52 * @return speed for which the current lateral acceleration follows in the corner
53 * @throws NullPointerException if acceleration is null
54 */
55 public final Speed getSpeedForLateralAcceleration(final Acceleration acceleration)
56 {
57 Throw.whenNull(acceleration, "Acceleration may not be null.");
58 // a=v*v/r => v=sqrt(a*r)
59 return new Speed(Math.sqrt(acceleration.si * this.radius.si), SpeedUnit.SI);
60 }
61
62 /** {@inheritDoc} */
63 @Override
64 public final int hashCode()
65 {
66 return this.radius.hashCode();
67 }
68
69 /** {@inheritDoc} */
70 @Override
71 public final boolean equals(final Object obj)
72 {
73 if (this == obj)
74 {
75 return true;
76 }
77 if (obj == null)
78 {
79 return false;
80 }
81 if (getClass() != obj.getClass())
82 {
83 return false;
84 }
85 SpeedInfoCurvature other = (SpeedInfoCurvature) obj;
86 if (!this.radius.equals(other.radius))
87 {
88 return false;
89 }
90 return true;
91 }
92
93 /** {@inheritDoc} */
94 @Override
95 public final String toString()
96 {
97 return "SpeedInfoCurvature [radius=" + this.radius + "]";
98 }
99
100 }