1 package org.opentrafficsim.draw.egtf;
2
3 /**
4 * Gaussian implementation of a shape.
5 * <p>
6 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
7 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
8 * </p>
9 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
10 * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
11 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
12 */
13 public class GaussKernelShape implements KernelShape
14 {
15
16 /** Twice the spatial size of the kernel to the power of 2. */
17 private final double sigma2;
18
19 /** Twice the temporal size of the kernel to the power of 2. */
20 private final double tau2;
21
22 /**
23 * Constructor.
24 * @param sigma spatial size of the kernel
25 * @param tau temporal size of the kernel
26 */
27 GaussKernelShape(final double sigma, final double tau)
28 {
29 this.sigma2 = 2.0 * sigma * sigma;
30 this.tau2 = 2.0 * tau * tau;
31 }
32
33 @Override
34 public double weight(final double c, final double dx, final double dt)
35 {
36 double dtt = dt - dx / c;
37 return Math.exp(-(dx * dx) / this.sigma2 - dtt * dtt / this.tau2);
38 }
39
40 @Override
41 public String toString()
42 {
43 return "GaussKernelShape [sigma=" + Math.sqrt(this.sigma2 / 2.0) + ", tau=" + Math.sqrt(this.tau2 / 2.0) + "]";
44 }
45
46 }