two dimensional arrays:
- From: "Hamish" <h.dean@xxxxxxxxxx>
- Date: Sat, 30 Apr 2005 00:18:08 +1200
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?
.
- Follow-Ups:
- Re: two dimensional arrays:
- From: Axter
- Re: two dimensional arrays:
- From: Barry Schwarz
- Re: two dimensional arrays:
- Prev by Date: Re: Caaling assembly routine in c
- Next by Date: Re: what do c developers do without the stl?
- Previous by thread: Caaling assembly routine in c
- Next by thread: Re: two dimensional arrays:
- Index(es):