GaussKernelShape.java

  1. package org.opentrafficsim.core.egtf;

  2. /**
  3.  * Gaussian implementation of a shape.
  4.  * <p>
  5.  * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  6.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  7.  * <p>
  8.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 31 okt. 2018 <br>
  9.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  10.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  11.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  12.  */
  13. public class GaussKernelShape implements KernelShape
  14. {

  15.     /** Twice the spatial size of the kernel to the power of 2. */
  16.     private final double sigma2;

  17.     /** Twice the temporal size of the kernel to the power of 2. */
  18.     private final double tau2;

  19.     /**
  20.      * Constructor.
  21.      * @param sigma double; spatial size of the kernel
  22.      * @param tau double; temporal size of the kernel
  23.      */
  24.     GaussKernelShape(final double sigma, final double tau)
  25.     {
  26.         this.sigma2 = 2.0 * sigma * sigma;
  27.         this.tau2 = 2.0 * tau * tau;
  28.     }

  29.     /** {@inheritDoc} */
  30.     @Override
  31.     public double weight(final double c, final double dx, final double dt)
  32.     {
  33.         double dtt = dt - dx / c;
  34.         return Math.exp(-(dx * dx) / this.sigma2 - dtt * dtt / this.tau2);
  35.     }

  36.     /** {@inheritDoc} */
  37.     @Override
  38.     public String toString()
  39.     {
  40.         return "GaussKernelShape [sigma=" + Math.sqrt(this.sigma2 / 2.0) + ", tau=" + Math.sqrt(this.tau2 / 2.0) + "]";
  41.     }

  42. }