當前位置: 首頁>>代碼示例>>Java>>正文


Java Math.exp方法代碼示例

本文整理匯總了Java中org.joml.Math.exp方法的典型用法代碼示例。如果您正苦於以下問題:Java Math.exp方法的具體用法?Java Math.exp怎麽用?Java Math.exp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joml.Math的用法示例。


在下文中一共展示了Math.exp方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: gaussianKernel

import org.joml.Math; //導入方法依賴的package包/類
/**
 * Generate a Gaussian convolution kernel with the given number of rows and columns, and store
 * the factors in row-major order in <code>dest</code>.
 *
 * @param rows
 *          the number of rows (must be an odd number)
 * @param cols
 *          the number of columns (must be an odd number)
 * @param sigma
 *          determines how big the factors are at the center of distribution
 * @param dest
 *          will hold the kernel factors in row-major order
 */
public static void gaussianKernel(int rows, int cols, float sigma, float[] dest) {
    if ((rows & 1) == 0) {
        throw new IllegalArgumentException("rows must be an odd number");
    }
    if ((cols & 1) == 0) {
        throw new IllegalArgumentException("cols must be an odd number");
    }
    if (dest == null) {
        throw new IllegalArgumentException("dest must not be null");
    }
    if (dest.length < rows * cols) {
        throw new IllegalArgumentException("dest must have at least " + (rows * cols) + " remaining values");
    }
    float sum = 0.0f;
    for (int i = 0, y = -(rows - 1) / 2; y <= (rows - 1) / 2; y++) {
        for (int x = -(cols - 1) / 2; x <= (cols - 1) / 2; x++, i++) {
            float k = (float) Math.exp(-(y * y + x * x) / (2.0 * sigma * sigma));
            dest[i] = k;
            sum += k;
        }
    }
    for (int i = 0; i < rows * cols; i++) {
        dest[i] = dest[i] / sum;
    }
}
 
開發者ID:JOML-CI,項目名稱:JOML,代碼行數:39,代碼來源:Convolution.java


注:本文中的org.joml.Math.exp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。