Re: two dimensional arrays:
- From: "Axter" <temp@xxxxxxxxx>
- Date: 30 Apr 2005 04:02:54 -0700
Hamish wrote:
> 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?
Check out the following code for building a 2 dimensional array:
http://code.axter.com/allocate2darray.h
http://code.axter.com/allocate2darray.c
Using above code, you can create a 2 dimensional array via following
method:
int x = 4;
int y = 6;
coordpt **My_coordpt = ALLOCATE2DARRAY(coordpt, x, y);
.
- Follow-Ups:
- Re: two dimensional arrays:
- From: Emmanuel Delahaye
- Re: two dimensional arrays:
- From: Barry Schwarz
- Re: two dimensional arrays:
- References:
- two dimensional arrays:
- From: Hamish
- two dimensional arrays:
- Prev by Date: Re: what do c developers do without the stl?
- Next by Date: Re: How to get file size?
- Previous by thread: Re: two dimensional arrays:
- Next by thread: Re: two dimensional arrays:
- Index(es):
Relevant Pages
|