@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
25 lines (21 loc) • 959 B
JavaScript
/**
* Generalized bell function, also known as "Cauchy membership function"
* @see "dbellmf" function from Matlab
* @see https://codecrucks.com/what-is-fuzzy-membership-function-complete-guide/
* @see https://researchhubs.com/post/maths/fundamentals/bell-shaped-function.html
* @param {number} v value to be filtered (have membership adjustment applied to)
* @param {number} a Controls window, larger value = larger window. Function will return exactly 0.5 at this distance away from center
* @param {number} b Slope, larger slope makes function's tails sharper, meaning that values fall off faster away from center
* @param {number} c Controls center of the bell curve
* @returns {number}
*/
export function bell_membership_function(v, a, b, c) {
if(a === 0){
// avoid division by 0
return 0;
}
const vc = v - c;
const N = vc / a;
const d = 1 + Math.pow(N, b * 2);
return 1 / d;
}