Calculate distance between two indexes of an array?

0

I want to get two indexes of the array, and subtract that value.

For example, I want to enter index [0, 1] and [2, 10] . And here I want to subtract the value, to calculate the distance between these points.

for (int i = 0; i < 1; i++)
{
   for (int j = 0; j < 1; j++)
   {
     matriz = matriz1[i, j] - matriz2[i, j];
   }
}

I did this, but it returns zero. Returns zero because it assumes the value for the indexes, not their position.

How can I do this?

I need to get to the value that represents how many indices when I'm in [0, 1] I'll be [2, 10]     

asked by anonymous 28.09.2016 / 18:52

1 answer

1

If the code was spelled correctly,

for (int i = 0; i < 1; i++) 

will fall into the first loop.

It will assume i = 0 in the first iteration, fall in condition i<1 and return false . Nor does it enter the second iteration.

Other than that. If you want to calculate the distance between two points in a 2x2 matrix, the answer is that you need a mathematical formula.

1) Calculate the square of the distance between two points of one ordinate.

2) Calculate the square of the distance between two points of the other ordered.

3) Calculate the square root of the sum of 1) and 2).

    
29.09.2016 / 01:16