I would really appreciate if someone could take a look and give some advice or help.
I got a 2D array and based on it I can figure out a value based only on those coordinates. What I am trying to do though is to use a y=mx+b equation to find the values in between the points. I am having lots of issues writing a code that would say, figure out the value of the two closest points (that surround the value).
if (x=1)
{a=0}
if (x=2)
{a=1}
if (x=4)
{a=2}
if (x =6)
{a=3}
b = y-3
cout << array[a][b];
But if I plug in, for example, x=4.7 and y = 6, how should I write a code that would figure out that 4.7 is between x=4 and x=6 or between a =2 and a=3 and then take the coordinates at x=4 or 6 or a=2 or 3 and plug it into an y=mx+b equation?
Thank you for taking your time to help me with this!
I do see a 2D table of values.
I do see a 1D table that maps "x" into "row".
I do see a 1D table that maps "y" into "column".
I do see that when input is a (x,y) pair, the 1D tables are used to retreive an element from the 2D table.
That is more like a 3D data point. (x,y,z) where z is the value in the 2D table.
You seem to ask how to interpolate. That can use up to four elements from the 2D table. For example, with input (2.8,4.1) should get a value that is an interpolation from
If x = 4.7 then use (int)(4.7) to calculate nearest integer coordinate below the value in question.
So if x(4), x(6) are the known x values then the interpolation is:
x(4.7) = 0.7/2 * ( x(6) - x(4) ) + x(4)
You don't need to / shouldn't use the standard equation for a line in most cases, in general, when programming, as it fails, and or loses acuracy when the slope gets very large as it approaches infinity.