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