00001
00002
00003
00004
00005
00006 namespace NewGamePhysics.Mathematics
00007 {
00008 using System;
00009 using System.Collections.Generic;
00010 using System.Linq;
00011 using System.Text;
00012
00017 public static class Gaussian
00018 {
00022 private static double InverseRootTwoPi = 1.0 / Math.Sqrt(2.0 * Math.PI);
00023
00030 public static double DistributionValue(double deviation, double x)
00031 {
00032 return DistributionValue(0.0, deviation, x);
00033 }
00034
00042 public static double DistributionValue(double mean, double deviation, double x)
00043 {
00044 if (deviation <= 0.0)
00045 {
00046 throw new ArgumentException("deviation cannot be less or equals than zero", "deviation");
00047 }
00048
00049 double scale = InverseRootTwoPi / deviation;
00050 double negativeInverseTwoSigmaSquared = -1.0 / (2.0* deviation * deviation);
00051 double shiftedInput = x - mean;
00052 double shiftedInputSquared = shiftedInput * shiftedInput;
00053 return scale * Math.Exp(negativeInverseTwoSigmaSquared * shiftedInputSquared);
00054 }
00055 }
00056 }