2

我正在尝试从 5 个点绘制一个封闭的多边形,我正在尝试使用以下代码:

CImg<float> img(800,800,1,3);
float red[] = {1.0f,0.0f,0.0f};
CImg<int> points(5,2);
int thePoints[] = {40,40,40,200,100,180,120,100,100,40};
int *iterator = thePoints;
cimg_forXY(points,x,y)
    points(x,y) = *iterator++;
img.draw_polygon(points,red).display();

我试图按 ccw 顺序给出点,但是我没有得到预期的多边形。预期的 我得到的是这样的:成立

我该怎么做才能按预期生成多边形?如何将积分作为输入?ccw 或 cw 顺序或任意顺序?

4

1 回答 1

2

您实际上错误地定义了变量points。应该这样填写:

cimg_forX(points,i) { points(i,0) = *(iterator++); points(i,1) = *(iterator++); }

可以按顺时针或逆时针顺序指定点。

于 2013-09-24T06:37:33.190 回答