it.unibo.alchemist.util.math.BidimensionalGaussian.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alchemist-implementationbase Show documentation
Show all versions of alchemist-implementationbase Show documentation
Abstract, incarnation independent implementations of the Alchemist's interfaces. Provides support for those who want to write incarnations.
/*
* Copyright (C) 2010-2019, Danilo Pianini and contributors listed in the main project's alchemist/build.gradle file.
*
* This file is part of Alchemist, and is distributed under the terms of the
* GNU General Public License, with a linking exception,
* as described in the file LICENSE in the Alchemist distribution's top directory.
*/
package it.unibo.alchemist.util.math
import org.apache.commons.math3.analysis.BivariateFunction
import org.apache.commons.math3.util.FastMath.exp
import java.io.Serializable
/**
* A 2D gaussian function.
*/
class BidimensionalGaussian(
private val amplitude: Double,
private val x0: Double,
private val y0: Double,
private val sigmaX: Double,
private val sigmaY: Double,
) : BivariateFunction, Serializable {
override fun value(x: Double, y: Double): Double {
val dx = x - x0
val dy = y - y0
val sigmaXsq = 2 * sigmaX * sigmaX
val sigmaYsq = 2 * sigmaY * sigmaY
return amplitude * exp(-(dx * dx / sigmaXsq + dy * dy / sigmaYsq))
}
/**
* The integral of the function.
*
* @return The computed value of the integral.
*/
fun integral() = 2 * Math.PI * amplitude * sigmaX * sigmaY
private companion object {
private const val serialVersionUID = 1L
}
}