1 package org.opentrafficsim.road.network.lane.object;
2
3 import org.djunits.value.vdouble.scalar.Length;
4 import org.djutils.draw.line.PolyLine2d;
5 import org.djutils.draw.point.OrientedPoint2d;
6 import org.djutils.draw.point.Point2d;
7 import org.djutils.exceptions.Throw;
8 import org.opentrafficsim.core.object.LocatedObject;
9 import org.opentrafficsim.road.network.lane.Lane;
10
11
12
13
14
15
16
17
18
19
20
21 public interface LaneBasedObject extends LocatedObject
22 {
23
24
25 Lane getLane();
26
27
28 Length getLongitudinalPosition();
29
30
31
32
33
34 default Length getLength()
35 {
36 return Length.ZERO;
37 }
38
39
40 @Override
41 OrientedPoint2d getLocation();
42
43
44
45
46
47
48
49 static PolyLine2d makeGeometry(final Lane lane, final Length longitudinalPosition)
50 {
51 return makeGeometry(lane, longitudinalPosition, 0.9);
52 }
53
54
55
56
57
58
59
60
61 static PolyLine2d makeGeometry(final Lane lane, final Length longitudinalPosition, final double relativeWidth)
62 {
63 Throw.whenNull(lane, "lane is null");
64 Throw.whenNull(longitudinalPosition, "position is null");
65 Throw.whenNull(relativeWidth, "relatve width is null");
66 double w50 = lane.getWidth(longitudinalPosition).si * 0.5 * relativeWidth;
67 OrientedPoint2d c = lane.getCenterLine().getLocationExtended(longitudinalPosition);
68 double a = c.getDirZ();
69 Point2d p1 = new Point2d(c.x + w50 * Math.cos(a + Math.PI / 2), c.y - w50 * Math.sin(a + Math.PI / 2));
70 Point2d p2 = new Point2d(c.x - w50 * Math.cos(a + Math.PI / 2), c.y + w50 * Math.sin(a + Math.PI / 2));
71 return new PolyLine2d(p1, p2);
72 }
73
74 }