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 @Override
32 OrientedPoint2d getLocation();
33
34
35
36
37
38
39
40 static PolyLine2d makeGeometry(final Lane lane, final Length longitudinalPosition)
41 {
42 return makeGeometry(lane, longitudinalPosition, 0.9);
43 }
44
45
46
47
48
49
50
51
52 static PolyLine2d makeGeometry(final Lane lane, final Length longitudinalPosition, final double relativeWidth)
53 {
54 Throw.whenNull(lane, "lane is null");
55 Throw.whenNull(longitudinalPosition, "position is null");
56 Throw.whenNull(relativeWidth, "relatve width is null");
57 double w50 = lane.getWidth(longitudinalPosition).si * 0.5 * relativeWidth;
58 OrientedPoint2d c = lane.getCenterLine().getLocationExtended(longitudinalPosition);
59 double a = c.getDirZ();
60 Point2d p1 = new Point2d(c.x + w50 * Math.cos(a + Math.PI / 2), c.y - w50 * Math.sin(a + Math.PI / 2));
61 Point2d p2 = new Point2d(c.x - w50 * Math.cos(a + Math.PI / 2), c.y + w50 * Math.sin(a + Math.PI / 2));
62 return new PolyLine2d(p1, p2);
63 }
64
65 }