Click here to Skip to main content
12,999,010 members (52,615 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 3 Aug 2010

Bell Curve, Gaussian Function, or Normal Distribution

, 3 Aug 2010
Rate this:
Please Sign up or sign in to vote.
Simple calculation to determin a value at a percentage along a bell curve. Also with an offcenter curve intersection thing....
The reason i'm posting this little code snippet is because i couldn't find anything like this. only math termonology which i don't understand, i just understand functions B)

at first i was trying to get a non-linear function for a volumn control, then we needed a distribution function for estimating materials we were going to need at work. so i came up with this finally.
Private Function GetBellCurvePoint(ByVal Percentage As Double, ByVal Midpoint As Double) As Double
        If Percentage > Midpoint Then
            Percentage = 1 - Percentage
            Return 1 - ((Percentage - ((1 - Percentage) * Percentage)) * (1 / (1 - Midpoint)))
            Return (Percentage - ((1 - Percentage) * Percentage)) * (1 / Midpoint)
        End If
    End Function

private double GetBellCurvePoint(double Percentage, double Midpoint)
    if (Percentage > Midpoint) {
        Percentage = 1 - Percentage;
        return 1 - ((Percentage - ((1 - Percentage) * Percentage)) * (1 / (1 - Midpoint)));
    } else {
        return (Percentage - ((1 - Percentage) * Percentage)) * (1 / Midpoint);

just provide the percentage along the curve you want the value for and the midpoint (normally 0.5)

this next function just gives you an even distribution along the curve depending on the iterations count, and i'm calling it threshold instead of midpoint here cause it makes more sense in my application. the value part of the keyvaluepair is the difference from the previous point.
Public Function GetMatrix(ByVal Iterations As Integer, ByVal Threshold As Double) As KeyValuePair(Of Double, Double)()
        Dim MatrixList As New List(Of KeyValuePair(Of Double, Double))
        MatrixList.Add(New KeyValuePair(Of Double, Double)(0, 0))
        For i = 1 To Iterations
            Dim ThisPoint = GetBellCurvePoint(i / Iterations, Threshold)
            MatrixList.Add(New KeyValuePair(Of Double, Double)(ThisPoint, ThisPoint - MatrixList.Last.Key))
        Return MatrixList.ToArray
    End Function

public KeyValuePair<double, double>[] GetMatrix(int Iterations, double Threshold)
    List<KeyValuePair<double, double>> MatrixList = new List<KeyValuePair<double, double>>();
    MatrixList.Add(new KeyValuePair<double, double>(0, 0));
    for (i = 1; i <= Iterations; i++) {
        object ThisPoint = GetBellCurvePoint(i / Iterations, Threshold);
        MatrixList.Add(new KeyValuePair<double, double>(ThisPoint, ThisPoint - MatrixList.Last.Key));
    return MatrixList.ToArray();

i believe this can also be used to calculate a gaussian function.
hope this helps someone that neeeded something like this!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170622.1 | Last Updated 3 Aug 2010
Article Copyright 2010 by Tim-bot
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid