1 package org.opentrafficsim.road.gtu.lane.object;
2
3 import nl.tudelft.simulation.language.d3.DirectedPoint;
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.StaticObject;
10 import org.opentrafficsim.road.network.lane.CrossSectionElement;
11
12
13
14
15
16
17
18
19
20
21
22 public abstract class AbstractCSEObject extends StaticObject
23 {
24
25
26
27
28 public AbstractCSEObject(final OTSLine3D geometry, final Length.Rel height)
29 {
30 super(geometry, height);
31 }
32
33
34
35
36
37
38
39
40
41
42
43 protected static OTSLine3D createRectangleOnCSE(final CrossSectionElement cse, final Length.Rel position,
44 final Length.Rel length, final Length.Rel width, final Length.Rel height) throws OTSGeometryException
45 {
46
47 double fraction = position.si / cse.getParentLink().getLength().si;
48 double w2 = width.si / 2.0;
49 double l2 = length.si / 2.0;
50 DirectedPoint cp = cse.getCenterLine().getLocationFraction(fraction);
51 double a = cp.getRotZ();
52 double l2ca = l2 * Math.cos(a);
53 double l2sa = l2 * Math.sin(a);
54 double w2ca = w2 * Math.cos(a + Math.PI / 2.0);
55 double w2sa = w2 * Math.sin(a + Math.PI / 2.0);
56 OTSPoint3D p1 = new OTSPoint3D(cp.x - l2ca - w2ca, cp.y - l2sa - w2sa, cp.z + height.si);
57 OTSPoint3D p3 = new OTSPoint3D(cp.x + l2ca + w2ca, cp.y + l2sa + w2sa, cp.z + height.si);
58 OTSPoint3D p2 = new OTSPoint3D(cp.x + l2ca - w2ca, cp.y + l2sa - w2sa, cp.z + height.si);
59 OTSPoint3D p4 = new OTSPoint3D(cp.x - l2ca + w2ca, cp.y - l2sa + w2sa, cp.z + height.si);
60 return new OTSLine3D(p1, p2, p3, p4, p1);
61 }
62
63
64
65
66
67
68
69
70
71
72
73
74 protected static OTSLine3D createRectangleNextToCSE(final CrossSectionElement cse, final Length.Rel position,
75 final Length.Rel length, final Length.Rel width, final Length.Rel height, final Length.Rel distance)
76 throws OTSGeometryException
77 {
78 double fraction = position.si / cse.getParentLink().getLength().si;
79 double w2 = width.si / 2.0;
80 double l2 = length.si / 2.0;
81 double d = distance.si;
82 DirectedPoint cp = cse.getCenterLine().getLocationFraction(fraction);
83 double a = cp.getRotZ();
84 cp =
85 new DirectedPoint(cp.x + d * Math.cos(a + Math.PI / 2.0), cp.y + d * Math.sin(a + Math.PI / 2.0), cp.z,
86 cp.getRotX(), cp.getRotY(), cp.getRotZ());
87 double l2ca = l2 * Math.cos(a);
88 double l2sa = l2 * Math.sin(a);
89 double w2ca = w2 * Math.cos(a + Math.PI / 2.0);
90 double w2sa = w2 * Math.sin(a + Math.PI / 2.0);
91 OTSPoint3D p1 = new OTSPoint3D(cp.x - l2ca - w2ca, cp.y - l2sa - w2sa, cp.z + height.si);
92 OTSPoint3D p3 = new OTSPoint3D(cp.x + l2ca + w2ca, cp.y + l2sa + w2sa, cp.z + height.si);
93 OTSPoint3D p2 = new OTSPoint3D(cp.x + l2ca - w2ca, cp.y + l2sa - w2sa, cp.z + height.si);
94 OTSPoint3D p4 = new OTSPoint3D(cp.x - l2ca + w2ca, cp.y - l2sa + w2sa, cp.z + height.si);
95 return new OTSLine3D(p1, p2, p3, p4, p1);
96 }
97
98 }