Midpoint and skew

ColinP
Posts: 953
Joined: Mon Aug 03, 2020 7:46 pm

Re: Midpoint and skew

Post by ColinP »

The wonderful Danny L from CA has kindly put me out of my misery. I was so close but not quite there on the skewed from center math.

Most developers will never need to know this level of detail. But for those who really do need it here's fully tested example code that translates position in the range [0,1] to outputValue...

LINEAR (or use midpoint == 0.5 or skewFactor == 1):

outputValue = min + range * position;

MIDPOINT:

outputValue = min + range * Math.pow( position, Math.log( ( midpoint - min ) / range ) / Math.log( 0.5 ) );

REGULAR SKEW:

outputValue = min + range * Math.pow( position, 1 / skewFactor );

SKEW FROM CENTER:

distFromMiddle = 2 * ( position - 0.5 );
outputValue = min + range * ( 1 + Math.pow( Math.abs( distFromMiddle ), 1 / skewFactor ) * ( distFromMiddle < 0 ? -1 : 1 ) ) / 2;
Centripidity
Posts: 140
Joined: Sun Jan 22, 2023 5:18 am
Location: Melbourne
Contact:

Re: Midpoint and skew

Post by Centripidity »

Excellent info. Thanks Colin (and Danny). I was wondering about this very topic myself recently but had neither the time nor patience to try and work it out. You don't really need to know this to use it but the more I understand about what's going on under the hood, the more I feel comfortable using it.

We all need black boxes to simplify the way but, for me at least, there is such a thing as a box that is just too black. :D
Post Reply

Return to “Module Designer”