Re: two dimensional arrays:




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

.



Relevant Pages

  • two dimensional arrays:
    ... I'm trying to use an C API which is for geometry calculations. ... requires an argument for an array of polygons: ... coordpt **polygons ...
    (comp.lang.c)
  • Re: Saving PointF data in MSAccess
    ... How about using a binarywriter to write the values to a memorystream, get the byte array from the stream and use the Convert.ToBase64String method to turn it into a string? ... If I store the Points array for each GraphicsPath I can then reproduce filled polygons at run time. ... The only way I can think of doing this is by saving the points as a string in a Memo field; looping through all the points in the Array and using GetValue to add the points to the string e.g.: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Saving PointF data in MSAccess
    ... I can see how the image data is converted into the Byte Array ... this case) filled polygons at run time. ... The only way I can think of doing this is by saving the points as a string ... in a Memo field; looping through all the points in the Array and using ...
    (microsoft.public.dotnet.languages.vb)
  • object.to_yaml works but [ object ].to_yaml fails
    ... Area Description: Deltana, Tanana Flats ... Polygons: ... However when I put the object in an array I get the following error ...
    (comp.lang.ruby)
  • Re: Polygon Rendering Speed
    ... but the polygons are not necessarily regular. ... indeed filling the RGB array of a DIB section is faster, ... 2x2 pixels in size. ...
    (microsoft.public.vb.winapi.graphics)