two dimensional arrays:



I'm trying to use an C API which is for geometry calculations. The function
requires an argument for an array of polygons:

coordpt **polygons
//[0..i..polygons_num-1][0..polygons_vertex_num[i]-1]

where coordpt is:

typedef struct
{ double x;
double y;
} coordpt;

polygons_num is the number of polygons in the calculation,
and polygons_vertex_num[i] is the number of vertices on polygon i.

Can someone give me an example of how to fill this with valid data. Say the
data below:

typedef struct
{ coordpt pts[4]; //each polygon up to 4 vertices
} coordpts;

typedef struct
{ coordpts ptsa[3]; // up to 3 polygons
} polys;

polys * Data;

Data->ptsa[0].pts[0].x = 0;
Data->ptsa[0].pts[0].y = 0;
Data->ptsa[0].pts[1].x = 1;
Data->ptsa[0].pts[1].x = 0;
Data->ptsa[0].pts[2].x = 0;
Data->ptsa[0].pts[2].x = 1; // a triangle

Data->ptsa[1].pts[0].x = 0;
Data->ptsa[1].pts[0].y = 0;
Data->ptsa[1].pts[1].x = 1;
Data->ptsa[1].pts[1].x = 0;
Data->ptsa[1].pts[2].x = 1;
Data->ptsa[1].pts[2].x = 1;
Data->ptsa[1].pts[3].x = 0;
Data->ptsa[1].pts[3].x = 1; //a square

Data->ptsa[2].pts[0].x = 0;
Data->ptsa[2].pts[0].y = 0;
Data->ptsa[2].pts[1].x = 2;
Data->ptsa[2].pts[1].x = 0;
Data->ptsa[2].pts[2].x = 2;
Data->ptsa[2].pts[2].x = 2;
Data->ptsa[2].pts[3].x = 0;
Data->ptsa[2].pts[3].x = 2; //a bigger square

polygons_num = 3;
int polygons_vertex_num[3]; //vertices for up to 3 polygons
polygons_vertex_num[0] = 3;
polygons_vertex_num[1] = 4;
polygons_vertex_num[2] = 4;

Right, so I've got this data (actually this will be in a different format,
with std:vector but that's not important). I want to chuck it into my
coordpt **polygons

How do I do this easily?


.