Hallo, CK hat gesagt: // CK wrote:
right I was about to whip one up but then I felt a bit stupid cloning an abstraction by reading c code of an external ;)
It's not difficult math, it's easy to understand if visualised. Please turn on a non-proportional font:
^ | y1.....+......+ | . / . | . / . | . / . | . / . | ./ . y0.....+......+ Figure 1. | . . | . . +-----x0-----x1--->
The slope "k" of the line connecting (x0,y0) and (x1,y1) is given as:
k = (y0-y1)/(x0-x1)
(In rrad.scale.pd this is a sender called "$0-k")
Now if x0 = y0 = 0 the formula to find y out of x would be very easy:
y = f(x) = k*x
Normally x0 and y0 are not 0. Assuming y0 not equals 0, but x0 = 0:
^ | y1......+ | / . | / . | / . | / . | / . y0......+ Figure 2. | . | . +------x1---> x0=0
You see, that now the curve simply is found by adding y0 to every value found by the simplest formula and thus shifting the line upwards (or downwards, if y0 < 0):
y = k*x + y0
To handle the x-shift similarily, lets look again at figure 1:
^ | y1.....+......+ | . / . | . / . | . / . | . / . | ./ . y0.....+......+ | . . | . . +-----x0-----x1--->
Compared with the previous figure, note that every x in the range from x0 to x1 actually results in the same y values from figure 2, only the x values are bigger by x0. We can counter this by first substracting x0 from our input x and basically transforming Figure 1 into Figure 2 on the way, so we can then use the formula from above again:
y = k*x + y0 using x -> x-x0 ==> y = k*(x-x0) + y0
Or in linear function lingo using:
k = m b = y0 - k*x0
it would be:
y = mx + b
Voila. [scale] done in math. Scaling exponential is a bit harder, but not much different. You can always look at scale.c ;)
Frank Barknecht _ ______footils.org__