View Javadoc
1   package org.opentrafficsim.road.network.lane.object;
2   
3   import org.djunits.value.vdouble.scalar.Length;
4   import org.djutils.exceptions.Throw;
5   import org.opentrafficsim.core.geometry.Bounds;
6   import org.opentrafficsim.core.geometry.DirectedPoint;
7   import org.opentrafficsim.core.geometry.OtsGeometryException;
8   import org.opentrafficsim.core.geometry.OtsLine3d;
9   import org.opentrafficsim.core.geometry.OtsPoint3d;
10  import org.opentrafficsim.core.object.LocatedObject;
11  import org.opentrafficsim.road.network.lane.Lane;
12  
13  /**
14   * Objects that can be encountered on a Lane like conflict areas, GTUs, traffic lights, stop lines, etc.
15   * <p>
16   * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
18   * </p>
19   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
21   * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
22   */
23  public interface LaneBasedObject extends LocatedObject
24  {
25      /** @return The lane for which this is a sensor. */
26      Lane getLane();
27  
28      /** @return the position (between 0.0 and the length of the Lane) of the sensor on the design line of the lane. */
29      Length getLongitudinalPosition();
30  
31      /**
32       * Return the location without throwing a RemoteException.
33       * @return DirectedPoint; the location
34       */
35      @Override
36      DirectedPoint getLocation();
37  
38      /**
39       * Return the bounds without throwing a RemoteException.
40       * @return Bounds; the (usually rectangular) bounds of the object
41       */
42      @Override
43      Bounds getBounds();
44  
45      /**
46       * Make a geometry perpendicular to the center line of the lane at the given position.
47       * @param lane Lane; the lane where the sensor resides
48       * @param position Length; The length of the object in the longitudinal direction, on the center line of the lane
49       * @return a geometry perpendicular to the center line that describes the sensor
50       */
51      static OtsLine3d makeGeometry(final Lane lane, final Length position)
52      {
53          Throw.whenNull(lane, "lane is null");
54          Throw.whenNull(position, "position is null");
55          DirectedPoint sp = lane.getCenterLine().getLocationExtended(position);
56          double w45 = 0.45 * lane.getWidth(position).si;
57          double a = sp.getRotZ() + Math.PI / 2.0;
58          OtsPoint3d p1 = new OtsPoint3d(sp.x + w45 * Math.cos(a), sp.y - w45 * Math.sin(a), sp.z + 0.0001);
59          OtsPoint3d p2 = new OtsPoint3d(sp.x - w45 * Math.cos(a), sp.y + w45 * Math.sin(a), sp.z + 0.0001);
60          try
61          {
62              return new OtsLine3d(p1, p2);
63          }
64          catch (OtsGeometryException exception)
65          {
66              throw new RuntimeException(exception);
67          }
68      }
69  
70  }