View Javadoc
1   package org.opentrafficsim.core.egtf;
2   
3   /**
4    * Gaussian implementation of a shape.
5    * <p>
6    * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
7    * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
8    * <p>
9    * @version $Revision$, $LastChangedDate$, by $Author$, initial version 31 okt. 2018 <br>
10   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
11   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
12   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
13   */
14  public class GaussKernelShape implements KernelShape
15  {
16  
17      /** Twice the spatial size of the kernel to the power of 2. */
18      private final double sigma2;
19  
20      /** Twice the temporal size of the kernel to the power of 2. */
21      private final double tau2;
22  
23      /**
24       * Constructor.
25       * @param sigma double; spatial size of the kernel
26       * @param tau double; temporal size of the kernel
27       */
28      GaussKernelShape(final double sigma, final double tau)
29      {
30          this.sigma2 = 2.0 * sigma * sigma;
31          this.tau2 = 2.0 * tau * tau;
32      }
33  
34      /** {@inheritDoc} */
35      @Override
36      public double weight(final double c, final double dx, final double dt)
37      {
38          double dtt = dt - dx / c;
39          return Math.exp(-(dx * dx) / this.sigma2 - dtt * dtt / this.tau2);
40      }
41  
42      /** {@inheritDoc} */
43      @Override
44      public String toString()
45      {
46          return "GaussKernelShape [sigma=" + Math.sqrt(this.sigma2 / 2.0) + ", tau=" + Math.sqrt(this.tau2 / 2.0) + "]";
47      }
48  
49  }