On Aug 20, 10:06 am, TFM gmail.com> wrote:
> On Aug 17, 4:17 pm, Geoffrey Summerhayes gmail.com> wrote:
>
>> Basically, it's a linear interpolation.
>
>> The values of the function F and it's variants are
>> designed to range from 0.0-4.0 in such a way
>> that (a+bb+c+d) is a constant (4.0) for any x,y
>> when 0.0 <= x <= 1.0 and 0.0 <= y <= 1.0
>> So, in the corners the only color that contributes
>> is the color of that corner and in the center they all
>> contribute equally. (in the center a=bb=c=d=1.0)
>
>> That's why the code had x/24 in the formula because
>> for(x=0;x<25;++x) means x ranges from 0 to 24.
>
>> To cover any range, you'll need to adjust the values,
>> (1.0 - (x - xmin)/(xmax-xmin)). In my code example
>> xmax was 24 and xmin was 0.
>
> I was looking at Linear Interpolation on wikipedia:
> y = y0 + (x-x0)((y1-y0)/(x1-x0))
>
> How does your following equation fit in the wikipedia formula:
> a = (float)(4.0 * (1.0 - realX / 2.0) * (1.0 - realY / 2.0));
Follow the idea behind the math, the idea is to use linear functions
to calculate data points.
Technically, it's called bilinear interpolation. It's essentially
an extension of linear for an extra dimension.
> Also I think a couple of things are confusing me here. There are 2
> things, one is the size of GRID which lets calls xGrid & yGrid and
> other the the domain & range lets call it realX & realY. In my case my
> domain & range will always be between -1 <= x <= 1 & -1 <= y <= 1 and
> xGrid & yGrid will always be 25
And you can use any coordinate set as you map the picked x and
y domains to [0,1]. If realX = xGrid*C1+C2 where C1 and C2 are
constants and C1!=0, it won't make any difference to the outcome
(same for y).
The equations can also be simplified, the multiplying and dividing by
4 were introduced just to make the logic behind the equations easier
to follow (mainly that we are looking at an average of the colour
contributions of each corner).
In other words,
xCalc = (xGrid - xGridMin)/(xGridMax - xGridMin);
and
xCalc = (realX - realXMin)/(realXMax - realXMin);
should be equal and range from 0 to 1.
Then you can use (1.0 - xCalc)*(1.0 - yCalc),
xCalc * (1.0 - yCalc), etc.
---
Geoff