1 package org.opentrafficsim.road.network.lane.object;
2
3 import javax.media.j3d.Bounds;
4
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.djutils.exceptions.Throw;
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.network.LongitudinalDirectionality;
11 import org.opentrafficsim.core.object.ObjectInterface;
12 import org.opentrafficsim.road.network.lane.Lane;
13
14 import nl.tudelft.simulation.language.d3.DirectedPoint;
15
16 /**
17 * Objects that can be encountered on a Lane like conflict areas, GTUs, traffic lights, stop lines, etc.
18 * <p>
19 * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
21 * </p>
22 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
23 * initial version Sep 9, 2016 <br>
24 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
25 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
26 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
27 */
28 public interface LaneBasedObject extends ObjectInterface
29 {
30 /** @return The lane for which this is a sensor. */
31 Lane getLane();
32
33 /** @return Longitudinal direction. */
34 LongitudinalDirectionality getDirection();
35
36 /** @return the position (between 0.0 and the length of the Lane) of the sensor on the design line of the lane. */
37 Length getLongitudinalPosition();
38
39 /**
40 * Return the location without throwing a RemoteException.
41 * @return DirectedPoint; the location
42 */
43 @Override
44 DirectedPoint getLocation();
45
46 /**
47 * Return the bounds without throwing a RemoteException.
48 * @return Bounds; the (usually rectangular) bounds of the object
49 */
50 @Override
51 Bounds getBounds();
52
53 /**
54 * Make a geometry perpendicular to the center line of the lane at the given position.
55 * @param lane Lane; the lane where the sensor resides
56 * @param position Length; The length of the object in the longitudinal direction, on the center line of the lane
57 * @return a geometry perpendicular to the center line that describes the sensor
58 */
59 static OTSLine3D makeGeometry(final Lane lane, final Length position)
60 {
61 Throw.whenNull(lane, "lane is null");
62 Throw.whenNull(position, "position is null");
63 DirectedPoint sp = lane.getCenterLine().getLocationExtended(position);
64 double w45 = 0.45 * lane.getWidth(position).si;
65 double a = sp.getRotZ() + Math.PI / 2.0;
66 OTSPoint3D p1 = new OTSPoint3D(sp.x + w45 * Math.cos(a), sp.y - w45 * Math.sin(a), sp.z + 0.0001);
67 OTSPoint3D p2 = new OTSPoint3D(sp.x - w45 * Math.cos(a), sp.y + w45 * Math.sin(a), sp.z + 0.0001);
68 try
69 {
70 return new OTSLine3D(p1, p2);
71 }
72 catch (OTSGeometryException exception)
73 {
74 throw new RuntimeException(exception);
75 }
76 }
77
78 }