math behind scale?
Can someone give me some details about the math behind the scale object?
I don’t have access to the scale source code, but I can make a guess.
The linear part is easy:
- Subtract the low input value from the number, then divide the result by the difference between high input value and low input value. This gives you a number between 0 and 1.
- Then multiply this again with the difference between low output and high output value, and finally add the low output value.
As an expression, this would look like this:
expr "(($f1-$f2)/($f3-$f2)) * ($f5-$f4) + $f4"
$f1 being your number input, $f1 the low input value, $f2 the high input value, $f3 the low output value, $f4 the high output value.
This still ignores the exponential part, but I don’t think this should be too hard to figure out as well.
eh, I’m silly. Should have looked into the documentation of [scale] first where the formula is written down. So that’s what you should do as well!
here’s the formula from the docs:
y = b*e^(-a*log(c)) * e^(x*log(c))
it says "a,b and c are the three typed-in arguments".
So c is the exponential factor and e is the base of the natural logarithm.
But what’s a and b ??
Woops, I didn’t now that the formula is inside the docs.
Thanks a lot guys!
I think that what is written in the docs is for exponential mode calculations. I was interested as well to use a jit.expr expression that simulates the scale object.
I managed to do something similar to [scale 0 255 -1. 1.] with the following expresion
but I don’t have a clue how to do [scale 0 255 1. -1.]
Does anyone know? I’m not good at maths either
Please, if anyone knows how to reverse a scale in jit.expr. I am trying to reverse a short matrix with 2d xy coordinates for a 640×480 pixels to have 3d xy coordinates which are -1. 1. for both x and y (with the center as 0.).
I did the first part for the x coordinate where 0 becomes -1. and 640 becomes 1. But for the y value, 0 is 1. and 480 is -1.
So I would need an expresion for jit.expr to turn a (-1. 1) matrix the other way around (1. -1.)
----------begin_max5_patcher---------- 528.3ocwV9saaBCEF+Z3ovxWsMQQ1l+TXWs8bTEU4BtotBrQfiFaU8ce1GBK YILRYohdii3bL1mue93OxK9d3Gz8hNL5qn6Pddu364AgbA71+rGtl2WTw6fo gKz00BkAGLjyH5MPbk1f1p0kiIZ3lhmjps22JJLCaPFMNjDfnI4teRRciLRH AsY+67nVY5j+R3lNkYSODVsqVppDFn.n6CJKgsU+vy2PYw3iVAEuFVA72ak7 J7gEQuyLtJDWvW88cCAWoxunpAgRycBBEG89o5n0P0JwOr61YhtqfWIPjPTb lc3FZHhFNCDtkDczQOkjeFEFJSyOaDCuA9wJM291KgRoSQI1RoD88iROKMgh 9lVz2fwOIU2Q1D1XG9hU6jHJK4yN18mDzgDwzzTWhwErRpDE5cJXUi92XNMG .aDk.XNB57hylCy1R79ZtoU1iCP3kwa1D7lr3tR1+AuqEcc7shy.dTbdXhsw hDlLa2HbWj4HS.51AWoYozUyk7O51vgyXDCA2qhXHJhNKhn.hxFfCK4xWXul NoI72xhWiFo2j8FEb3lkVwG4wuh1aQoevsUMsxCeRbFGobv+ONc0aitJ6HXy A22S9ORfRcw+ap0o20VLJjwlXzAwVJ5LRE2H0pilD3YdzrdRVVJfILJxZYYi 1B58UAZyjGhu0h5z8a5pZcqIm+3EKoSn4xpI6Cu5+aPQ0fnU -----------end_max5_patcher-----------
Could you just multiply by -1. after the scale?
[jit.op @op * @val -1.]
I guess it’s mid school mathematics! I’m loosing my mind!!
Thank you so much, Jesse!!
Forums > MaxMSP