Calculate distance between two indexes of a matrix?

Asked

Viewed 1,089 times

0

I want to enter two matrix indexes, and subtract that value.

For example I want to enter with index [0, 1] and [2, 10]. And then I want to subtract the value, to calculate the distance I’m 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 so, but it returns zero. Returns zero because it assumes the value for the indexes, not their position.

There’s a way I can do that?

I need to get the amount it represents to as many clues as I’m on [0, 1] I’ll be at the [2, 10]

  • It would be interesting to put what you’ve already done and say where you’re struggling.

  • 4

    The doubt is in C# or C?

  • Search by "distance Manhattan"

  • I think that i = 0; i < 1;i++ not going anywhere. I think.

1 answer

1

If the code was written correctly,

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

will fall in the first loop.

Will take over i = 0in the first iteration, fall in condition i<1 and return false . Doesn’t even 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 of the ordinates.

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.