Pregunta

I am trying to draw a closed polygon from 5 points , I am trying with the following code :

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();

I have tried to give the points in ccw order , However I am not getting the polygon as expected .Expected What i get is like : Found

What can i do to generate a polygon as i expected ? How to give the points as input ? ccw or cw order or arbitrary order ?

¿Fue útil?

Solución

You actually incorrectly define the variable points. It should be filled like this:

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

The points can be specified in either clockwise or counterclockwise order.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top