1

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

Nicke
  • 133
  • 12
  • 3
    Search the web for "scan conversion". You'll find an immense number of tutorials and sample code. – Ted Hopp Jan 13 '12 at 04:27
  • You are essentially looking for a fill algorithm, of which there are many. – Iskar Jarak Jan 13 '12 at 04:35
  • Thank you very much, This really helped for big part of my problem. Do you know if these algorithms exist also for parametrized ellipses instead of polygons? – Nicke Jan 13 '12 at 05:07
  • 1
    Have a read of http://enchantia.com/graphapp/doc/tech/ellipses.html and see if it helps. – Iskar Jarak Jan 15 '12 at 21:52
  • Thank you Iskar, I found that paper as well. But I need it to be a more general ellipse than a axis-aligned one. /Nicke – Nicke Jan 16 '12 at 22:55

1 Answers1

2

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.

Pubby
  • 51,882
  • 13
  • 139
  • 180
  • Thank you Pubby, since the aim is to use the algorithm in a real-time implementation it is essential that it is fast and simple. Is this the best (computationally) way of finding the indicies that lies inside the poly (and in your example color them gray/blue)? – Nicke Jan 13 '12 at 04:41
  • 1
    @Nicke It is very fast, as it is primarily used in 3d graphics. – Pubby Jan 13 '12 at 04:50
  • Thank you very much, This really helped for big part of my problem. I will also ask you another related following question as I did above: Do you know if these algorithms exist also for parametrized ellipses instead of polygons? – Nicke Jan 13 '12 at 05:08