Special polygonial for loop in two dimensional array

邮差的信 提交于 2019-12-24 11:09:31

问题


This is a bit tricky question for you computer scientists. Let's say that I have a two dimensional array/matrix of 100 by 100 entries, arr[i][j]. Where i and j goes from 0-99. This can be envisioned as a square of dots with each dot corresponding to a data value.

Now, If I define a 4 point polygon and know the indicies of the 4 points: Is it possible (is there an clever algorithm) to loop through only those entries in the matrix that lies inside of the 4-point polygon? That is, every value of i and j in the loop laps correspond to a value in arr[i][j] that is interesting (i and j is inside the 4-point poly).

Is this clear? I understand if it is difficult to understand.

Sincerely Yours


回答1:


Sounds similar to triangle rasterization.

There are a number of articles/tutorials you can find on it, such as this one:

http://joshbeam.com/articles/triangle_rasterization/

or this:

http://sol.gfxile.net/tri/index.html

With a 4-point poly just split it into 2 triangles.



来源:https://stackoverflow.com/questions/8845878/special-polygonial-for-loop-in-two-dimensional-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!