# Compress the variance in a set of numbers?

I'm not sure if there's a better way to ask that, but I have a hovercraft which hovers by imparting force at each of four corners. I'd like to clamp the maximum variance between the thrusters so if one corner hovers over something higher altitude, the effect is less dramatic.

For example, if I had 4-6-8-10, I might want it to compress to 4-5-6-7.

I would actually recommend normalizing towards the mean (average) rather than the lowest value.

base_values = {4, 6, 8, 10};

double ave = average(base_values); // ave is equal to 7

for(int i = 0; i < base_values.len; i++)
{
base_values[i] = base_values[i] - (abs(ave - base_values[i]) / 2);
}


abs(...) is the absolute value function.

That will make going down jagged terrain look good, as well as going up.

From what you posted I see a pattern you could use. Here is some psudocode

values = {4,6,8,10}

lowest = 100 //or some other imposible high number
for each int in values {
if int < lowest then lowest = int
}

for each int in values {
value = value -((lowest-value)/2)
}