LaneBasedObject.java

  1. package org.opentrafficsim.road.network.lane.object;



  2. import org.djunits.value.vdouble.scalar.Length;
  3. import org.djutils.exceptions.Throw;
  4. import org.opentrafficsim.core.geometry.Bounds;
  5. import org.opentrafficsim.core.geometry.DirectedPoint;
  6. import org.opentrafficsim.core.geometry.OTSGeometryException;
  7. import org.opentrafficsim.core.geometry.OTSLine3D;
  8. import org.opentrafficsim.core.geometry.OTSPoint3D;
  9. import org.opentrafficsim.core.network.LongitudinalDirectionality;
  10. import org.opentrafficsim.core.object.ObjectInterface;
  11. import org.opentrafficsim.road.network.lane.Lane;

  12. /**
  13.  * Objects that can be encountered on a Lane like conflict areas, GTUs, traffic lights, stop lines, etc.
  14.  * <p>
  15.  * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  16.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  17.  * </p>
  18.  * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  19.  * initial version Sep 9, 2016 <br>
  20.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  21.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  22.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  23.  */
  24. public interface LaneBasedObject extends ObjectInterface
  25. {
  26.     /** @return The lane for which this is a sensor. */
  27.     Lane getLane();

  28.     /** @return Longitudinal direction. */
  29.     LongitudinalDirectionality getDirection();

  30.     /** @return the position (between 0.0 and the length of the Lane) of the sensor on the design line of the lane. */
  31.     Length getLongitudinalPosition();

  32.     /**
  33.      * Return the location without throwing a RemoteException.
  34.      * @return DirectedPoint; the location
  35.      */
  36.     @Override
  37.     DirectedPoint getLocation();

  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.      * Make a geometry perpendicular to the center line of the lane at the given position.
  46.      * @param lane Lane; the lane where the sensor resides
  47.      * @param position Length; The length of the object in the longitudinal direction, on the center line of the lane
  48.      * @return a geometry perpendicular to the center line that describes the sensor
  49.      */
  50.     static OTSLine3D makeGeometry(final Lane lane, final Length position)
  51.     {
  52.         Throw.whenNull(lane, "lane is null");
  53.         Throw.whenNull(position, "position is null");
  54.         DirectedPoint sp = lane.getCenterLine().getLocationExtended(position);
  55.         double w45 = 0.45 * lane.getWidth(position).si;
  56.         double a = sp.getRotZ() + Math.PI / 2.0;
  57.         OTSPoint3D p1 = new OTSPoint3D(sp.x + w45 * Math.cos(a), sp.y - w45 * Math.sin(a), sp.z + 0.0001);
  58.         OTSPoint3D p2 = new OTSPoint3D(sp.x - w45 * Math.cos(a), sp.y + w45 * Math.sin(a), sp.z + 0.0001);
  59.         try
  60.         {
  61.             return new OTSLine3D(p1, p2);
  62.         }
  63.         catch (OTSGeometryException exception)
  64.         {
  65.             throw new RuntimeException(exception);
  66.         }
  67.     }

  68. }