View Javadoc
1   package org.opentrafficsim.demo.geometry;
2   
3   import java.awt.Color;
4   import java.rmi.RemoteException;
5   
6   import javax.naming.NamingException;
7   
8   import org.djunits.unit.util.UNITS;
9   import org.djunits.value.vdouble.scalar.Direction;
10  import org.djunits.value.vdouble.scalar.Length;
11  import org.djunits.value.vdouble.scalar.Speed;
12  import org.opentrafficsim.core.dsol.AbstractOTSModel;
13  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
14  import org.opentrafficsim.core.geometry.OTSGeometryException;
15  import org.opentrafficsim.core.geometry.OTSLine3D;
16  import org.opentrafficsim.core.geometry.OTSPoint3D;
17  import org.opentrafficsim.core.network.LinkType;
18  import org.opentrafficsim.core.network.NetworkException;
19  import org.opentrafficsim.draw.road.LaneAnimation;
20  import org.opentrafficsim.draw.road.ShoulderAnimation;
21  import org.opentrafficsim.road.network.OTSRoadNetwork;
22  import org.opentrafficsim.road.network.lane.CrossSectionLink;
23  import org.opentrafficsim.road.network.lane.Lane;
24  import org.opentrafficsim.road.network.lane.NoTrafficLane;
25  import org.opentrafficsim.road.network.lane.OTSRoadNode;
26  import org.opentrafficsim.road.network.lane.Shoulder;
27  import org.opentrafficsim.road.network.lane.changing.LaneKeepingPolicy;
28  
29  import nl.tudelft.simulation.dsol.SimRuntimeException;
30  
31  /**
32   * <p>
33   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
34   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
35   * <p>
36   * $LastChangedDate: 2019-11-14 14:36:06 +0100 (Thu, 14 Nov 2019) $, @version $Revision: 5717 $, by $Author: averbraeck $,
37   * initial version ct 17, 2014 <br>
38   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
39   */
40  /** */
41  public class TestModel extends AbstractOTSModel implements UNITS
42  {
43      /**
44       * @param simulator OTSSimulatorInterface; the simulator
45       */
46      public TestModel(final OTSSimulatorInterface simulator)
47      {
48          super(simulator);
49      }
50  
51      /** */
52      private static final long serialVersionUID = 1L;
53  
54      /** the network. */
55      private OTSRoadNetwork network = new OTSRoadNetwork("geometry test network", true);
56  
57      /** {@inheritDoc} */
58      @Override
59      public final void constructModel() throws SimRuntimeException
60      {
61          // create a small graph and a road around it.
62  
63          try
64          {
65              OTSRoadNode n0 = new OTSRoadNode(this.network, "N0", new OTSPoint3D(-25.0, 0.0), Direction.ZERO);
66              OTSRoadNode n1 = new OTSRoadNode(this.network, "N1", new OTSPoint3D(0.0, 0.0), Direction.ZERO);
67              CrossSectionLink l01 =
68                      new CrossSectionLink(this.network, "L01", n0, n1, network.getLinkType(LinkType.DEFAULTS.ROAD),
69                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(-25.0, 0.0), new OTSPoint3D(0.0, 0.0)}),
70                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
71  
72              OTSRoadNode n2 = new OTSRoadNode(this.network, "N2", new OTSPoint3D(25.0, 20.0), Direction.ZERO);
73              CrossSectionLink l12 =
74                      new CrossSectionLink(this.network, "L12", n1, n2, network.getLinkType(LinkType.DEFAULTS.ROAD),
75                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(0.0, 0.0), new OTSPoint3D(25.0, 20.0)}),
76                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
77  
78              OTSRoadNode n3 = new OTSRoadNode(this.network, "N3", new OTSPoint3D(50.0, 0.0), Direction.ZERO);
79              CrossSectionLink l23 =
80                      new CrossSectionLink(this.network, "L23", n2, n3, network.getLinkType(LinkType.DEFAULTS.ROAD),
81                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(25.0, 20.0), new OTSPoint3D(50.0, 0.0)}),
82                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
83  
84              OTSRoadNode n4 = new OTSRoadNode(this.network, "N4", new OTSPoint3D(75.0, -20.0), Direction.ZERO);
85              CrossSectionLink l34 =
86                      new CrossSectionLink(this.network, "L34", n3, n4, network.getLinkType(LinkType.DEFAULTS.ROAD),
87                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(50.0, 0.0), new OTSPoint3D(75.0, -20.0)}),
88                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
89  
90              OTSRoadNode n5 = new OTSRoadNode(this.network, "N5", new OTSPoint3D(100.0, 0.0), Direction.ZERO);
91              CrossSectionLink l45 =
92                      new CrossSectionLink(this.network, "L45", n4, n5, network.getLinkType(LinkType.DEFAULTS.ROAD),
93                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(75.0, -20.0), new OTSPoint3D(100.0, 0.0)}),
94                              this.simulator, LaneKeepingPolicy.KEEPRIGHT);
95  
96              OTSRoadNode n6 = new OTSRoadNode(this.network, "N6", new OTSPoint3D(125.0, 0.0), Direction.ZERO);
97              CrossSectionLink l56 =
98                      new CrossSectionLink(this.network, "L56", n5, n6, network.getLinkType(LinkType.DEFAULTS.ROAD),
99                              new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(100.0, 0.0), new OTSPoint3D(125.0, 0.0)}),
100                             this.simulator, LaneKeepingPolicy.KEEPRIGHT);
101 
102             OTSRoadNode n7 = new OTSRoadNode(this.network, "N7", new OTSPoint3D(300.0, 0.0), Direction.ZERO);
103             CrossSectionLink l67 =
104                     new CrossSectionLink(this.network, "L67", n6, n7, network.getLinkType(LinkType.DEFAULTS.ROAD),
105                             new OTSLine3D(new OTSPoint3D[] {new OTSPoint3D(125.0, 0.0), new OTSPoint3D(150.0, 0.0),
106                                     new OTSPoint3D(175.0, 20.0), new OTSPoint3D(200.0, 0.0), new OTSPoint3D(225.0, -20.0),
107                                     new OTSPoint3D(250.0, 0.0), new OTSPoint3D(300.0, 0.0)}),
108                             this.simulator, LaneKeepingPolicy.KEEPRIGHT);
109 
110             add2x2Lanes(l01);
111             add2x2Lanes(l12);
112             add2x2Lanes(l23);
113             add2x2Lanes(l34);
114             add2x2Lanes(l45);
115             add2x2Lanes(l56);
116             add2x2Lanes(l67);
117         }
118         catch (NetworkException | OTSGeometryException exception)
119         {
120             exception.printStackTrace();
121         }
122     }
123 
124     /**
125      * The road is as follows; The design line goes from left to right.
126      * 
127      * <pre>
128      * ----------------------- +9.50
129      * SSSSS Shoulder SL SSSSS +9.00 (width = 1.0)
130      * ----------------------- +8.50
131      * EEEEE Emergency ELL EEE +8.25 (width = 0.5)
132      * ----------------------- +8.00
133      * LLLLL Lane L1 LLLLLLLLL +6.25 (width = 3.5)
134      * ----------------------- +4.50
135      * LLLLL Lane L2 LLLLLLLLL +2.75 (width = 3.5)
136      * ----------------------- +1.00
137      * EEEEE Emergency ELM EEE +0.75 (width = 0.5)
138      * ----------------------- +0.50
139      * SSSSS Shoulder SM SSSSS +0.00 (width = 1.0)
140      * ----------------------- -0.50
141      * EEEEE Emergency ERM EEE -0.75 (width = 0.5)
142      * ----------------------- -1.00
143      * LLLLL Lane R2 LLLLLLLLL -2.75 (width = 3.5)
144      * ----------------------- -4.50
145      * LLLLL Lane R1 LLLLLLLLL -6.25 (width = 3.5)
146      * ----------------------- -8.00
147      * EEEEE Emergency ERR EEE -8.25 (width = 0.5)
148      * ----------------------- -8.50
149      * SSSSS Shoulder SR SSSSS -9.00 (width = 1.0)
150      * ----------------------- -9.50
151      * </pre>
152      *
153      * <br>
154      * @param link CrossSectionLink; link.
155      * @throws NetworkException on network inconsistency
156      * @throws OTSGeometryException on network inconsistency
157      */
158     private void add2x2Lanes(final CrossSectionLink link) throws NetworkException, OTSGeometryException
159     {
160         // four lanes, grass underneath, lines between lane1-2 and lane 2-3, barrier between lane 2-3
161         // lane is 3.5 meters wide. gap between 3-4 is one meter. outside 0.5 meters on both sides
162         Length m05 = new Length(0.5, METER);
163         Length m10 = new Length(1.0, METER);
164         Length m35 = new Length(3.5, METER);
165         Speed speedLimit = new Speed(100, KM_PER_HOUR);
166 
167         Shoulder sL = new Shoulder(link, "sL", new Length(9.0, METER), m10);
168 
169         Lane laneELL = new NoTrafficLane(link, "ELL", new Length(8.25, METER), new Length(8.25, METER), m05, m05);
170         Lane laneL1 = new Lane(link, "L1", new Length(6.25, METER), new Length(6.25, METER), m35, m35, null, speedLimit);
171         Lane laneL2 = new Lane(link, "L2", new Length(2.75, METER), new Length(2.75, METER), m35, m35, null, speedLimit);
172         Lane laneELM = new NoTrafficLane(link, "ELM", new Length(0.75, METER), new Length(0.75, METER), m05, m05);
173 
174         Shoulder sM = new Shoulder(link, "sM", new Length(0.0, METER), m10);
175 
176         Lane laneERM = new NoTrafficLane(link, "ERM", new Length(-0.75, METER), new Length(-0.75, METER), m05, m05);
177         Lane laneR2 = new Lane(link, "R2", new Length(-2.75, METER), new Length(-2.75, METER), m35, m35, null, speedLimit);
178         Lane laneR1 = new Lane(link, "R1", new Length(-6.25, METER), new Length(-6.25, METER), m35, m35, null, speedLimit);
179         Lane laneERR = new NoTrafficLane(link, "ERR", new Length(-8.25, METER), new Length(-8.25, METER), m05, m05);
180 
181         Shoulder sR = new Shoulder(link, "sR", new Length(-9.0, METER), m10);
182 
183         try
184         {
185             new LaneAnimation(laneELL, this.simulator, Color.GRAY);
186             new LaneAnimation(laneL1, this.simulator, Color.GRAY);
187             new LaneAnimation(laneL2, this.simulator, Color.GRAY);
188             new LaneAnimation(laneELM, this.simulator, Color.GRAY);
189             new LaneAnimation(laneERM, this.simulator, Color.GRAY);
190             new LaneAnimation(laneR2, this.simulator, Color.GRAY);
191             new LaneAnimation(laneR1, this.simulator, Color.GRAY);
192             new LaneAnimation(laneERR, this.simulator, Color.GRAY);
193 
194             new ShoulderAnimation(sL, this.simulator, Color.GREEN);
195             new ShoulderAnimation(sM, this.simulator, Color.GREEN);
196             new ShoulderAnimation(sR, this.simulator, Color.GREEN);
197         }
198         catch (NamingException | RemoteException ne)
199         {
200             //
201         }
202     }
203 
204     /** {@inheritDoc} */
205     @Override
206     public final OTSRoadNetwork getNetwork()
207     {
208         return this.network;
209     }
210 
211 }