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.opentrafficsim.core.geometry.OTSGeometryException;
7 import org.opentrafficsim.core.geometry.OTSLine3D;
8 import org.opentrafficsim.core.geometry.OTSPoint3D;
9 import org.opentrafficsim.core.object.ObjectInterface;
10 import org.opentrafficsim.road.network.lane.Lane;
11
12 import nl.tudelft.simulation.language.Throw;
13 import nl.tudelft.simulation.language.d3.DirectedPoint;
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public interface LaneBasedObject extends ObjectInterface
28 {
29
30 Lane getLane();
31
32
33 Length getLongitudinalPosition();
34
35
36
37
38
39 @Override
40 DirectedPoint getLocation();
41
42
43
44
45
46 @Override
47 Bounds getBounds();
48
49
50
51
52
53
54
55 static OTSLine3D makeGeometry(final Lane lane, final Length position)
56 {
57 Throw.whenNull(lane, "lane is null");
58 Throw.whenNull(position, "position is null");
59 DirectedPoint sp = lane.getCenterLine().getLocationExtended(position);
60 double w45 = 0.45 * lane.getWidth(position).si;
61 double a = sp.getRotZ() + Math.PI / 2.0;
62 OTSPoint3D p1 = new OTSPoint3D(sp.x + w45 * Math.cos(a), sp.y - w45 * Math.sin(a), sp.z + 0.0001);
63 OTSPoint3D p2 = new OTSPoint3D(sp.x - w45 * Math.cos(a), sp.y + w45 * Math.sin(a), sp.z + 0.0001);
64 try
65 {
66 return new OTSLine3D(p1, p2);
67 }
68 catch (OTSGeometryException exception)
69 {
70 throw new RuntimeException(exception);
71 }
72 }
73
74 }