View Javadoc
1   package org.opentrafficsim.road.network.lane;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djutils.draw.point.DirectedPoint2d;
5   
6   /**
7    * Store one position and lane of a GTU.
8    * <p>
9    * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
10   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
11   * </p>
12   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
13   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
14   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
15   * @param lane the lane for the position
16   * @param position the position on the lane, relative to the cross section link (design line) line, or against it
17   */
18  public record LanePosition(Lane lane, Length position)
19  {
20  
21      /**
22       * Retrieve the location and direction of the GTU on the lane.
23       * @return the location and direction of the GTU on the lane
24       */
25      public DirectedPoint2d getLocation()
26      {
27          return this.lane.getCenterLine().getLocationExtended(this.position);
28      }
29  
30      /**
31       * Returns the fractional longitudinal position on the lane.
32       * @return fractional longitudinal position on the lane
33       */
34      public double getFraction()
35      {
36          return position().si / lane().getLength().si;
37      }
38  
39  }