View Javadoc

1   /*
2    * @(#)StraightTrack.java May 30, 2004
3    * 
4    * Copyright (c) 2003, 2004 Delft University of Technology Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  
11  package nl.tudelft.simulation.traffic.track;
12  
13  import java.rmi.RemoteException;
14  import javax.media.j3d.Bounds;
15  import javax.vecmath.Point3d;
16  import nl.tudelft.simulation.language.d3.BoundingBox;
17  import nl.tudelft.simulation.language.d3.DirectedPoint;
18  
19  /***
20   * A straight track from one link to another link. <br>
21   * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
22   * University of Technology </a>, the Netherlands. <br>
23   * See for project information <a href="http://www.simulation.tudelft.nl">
24   * www.simulation.tudelft.nl </a> <br>
25   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
26   * License (GPL) </a>, no warranty <br>
27   * 
28   * @version May 30, 2004 <br>
29   * @author <a
30   * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
31   * Verbraeck </a> <br>
32   * 
33   * Original authors: J.H. Kwakkel and H.W.G. Phaff
34   */
35  public class StraightTrack extends Track
36  {
37      /*** the angle of the straight track */
38      private double theta = 0.0;
39  
40      /*** the length of the track */
41      private double length;
42  
43      /***
44       * @param name
45       * @param startLink
46       * @param endLink
47       */
48      public StraightTrack(final String name, TrackLinkInterface startLink,
49              TrackLinkInterface endLink)
50      {
51          super(name, startLink, endLink);
52          try
53          {
54              this.length = this.startLink.getLocation().distance(
55                      this.endLink.getLocation());
56          } catch (RemoteException exception)
57          {
58              exception.printStackTrace();
59          }
60          this.theta = Math.atan2(super.getdy(), super.getdx());
61      }
62  
63      /***
64       * @see nl.tudelft.simulation.traffic.track.TrackInterface#getLocationOfProgression(double)
65       */
66      public DirectedPoint getLocationOfProgression(final double progression)
67      {
68          double delta = progression / this.length;
69          Point3d startPoint = this.startLink.getPosition();
70          Point3d endPoint = this.endLink.getPosition();
71          double x = startPoint.x + delta * (endPoint.x - startPoint.x);
72          double y = startPoint.y + delta * (endPoint.y - startPoint.y);
73          double z = startPoint.z + delta * (endPoint.z - startPoint.z);
74          return new DirectedPoint(x, y, z, 0.0, 0.0, this.theta);
75      }
76  
77      /***
78       * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getBounds()
79       */
80      public Bounds getBounds()
81      {
82          Point3d p = this.startLink.getPosition();
83          Point3d q = this.endLink.getPosition();
84          return new BoundingBox(new Point3d(0, 0, 0), new Point3d(q.x - p.x, q.y
85                  - p.y, q.z - p.z));
86      }
87  
88      /***
89       * @see nl.tudelft.simulation.traffic.track.TrackInterface#getLength()
90       */
91      public double getLength()
92      {
93          return this.length;
94      }
95  }