Question

Traverse matrix in a direction specified by azimuth.

So I have a 2D matrix and an azimuth. What I want to do is traverse the matrix in that direction. From that azimuth I can derive a line equation.

Now I want to traverse the matrix in that direction of line. So in this case the 1st block I want to read info from is market as 1 then 2 and so on. (the values in the matrix right now are just to represent the order in which they are accessed)

http://i.stack.imgur.com/DPI9v.png

Let’s say if the line derived from azimuth goes as shown in the figure below then the matrix should be traverse from left to right.

http://i.stack.imgur.com/0D63q.png

If the problem is not clear please ask any question and I will explain further. Thanks for your time.

Was it helpful?

Solution

Label cell in row i column j by i * sin(a) + j * cos(a). Then traverse in ascending order of these labels. Assuming in your first example a = 45° and in the second a = 0°.

So for your first example, sin(a) = cos(a) = sqrt(0.5). The calculated labels are the values in your figure multiplied by sqrt(2).

For your second example, sin(a) = 0; cos(a) = 1 and you get the same values as in your figure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top