All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.unibo.alchemist.util.math.BidimensionalGaussian.kt Maven / Gradle / Ivy

Go to download

Abstract, incarnation independent implementations of the Alchemist's interfaces. Provides support for those who want to write incarnations.

There is a newer version: 35.0.1
Show newest version
/*
 * 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
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy