rasterizing

Rasterizing a 2D polygon

本小妞迷上赌 提交于 2019-11-27 02:59:28
问题 I need to create a binary bitmap from a closed 2D polygon represented as a list of points. Could you please point me to efficient and sufficiently simple algorithms to do that, or, even better, some C++ code? Thanks a lot! PS: I would like to avoid adding a dependency to my project. However if you suggest an open-source library, I can always look at the code, so it can be useful too. 回答1: The magic google phrase you want is either "non-zero winding rule" or "even odd polygon fill". See the

Algorithm to fill triangle

為{幸葍}努か 提交于 2019-11-26 16:49:39
i'm thinking about rasterization triangle algorithm. ( triangle_rasterization_lesson ) I wtote the following code: void triangle(int xa, int ya, int xb, int yb, int xc, int yc, TGAImage &image, TGAColor color) { line(xa, ya, xb, yb, image, color); line(xa, ya, xc, yc, image, color); line(xb, yb, xc, yc, image, color); for (int x = xa; x<=xb; x++) { for (int y = ya; y<=yb; y++) { line(xc, yc, x, y, image, white); } } } With triangle(100, 100, 100, 400, 400, 100, image, red); it works properly. But if i swap X(xa, ya) and Z(xc, yc) coordinates to doesn't fill my square. With triangle(70, 50, 200