GaussKernelShape.java

  1. package org.opentrafficsim.draw.egtf;

  2. /**
  3.  * Gaussian implementation of a shape.
  4.  * <p>
  5.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  6.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  7.  * </p>
  8.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  9.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  10.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  11.  */
  12. public class GaussKernelShape implements KernelShape
  13. {

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

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

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

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

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

  41. }