2

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 ?

web2dev
  • 557
  • 10
  • 28

1 Answers1

2

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.

VLL
  • 9,634
  • 1
  • 29
  • 54
bvalabas
  • 301
  • 1
  • 1
  • Thank you so much , it worked , but are you sure that the Points can be of any order ? I tried inserting the point (40,40) in the middle , but the polygon is something different . I think the points should follow ccw/cw order . – web2dev Sep 24 '13 at 07:16