javaawtpolygon

How to make polygon from > 100 000 points?


I'm trying to make Polygons from my file (x, y, z). I have a lot of lines so I don't know how many records should be in every Polygon. I think that I should do it when I'm loading file:

 while (file.hasNextDouble()) {
            a = br.nextDouble();
            b = br.nextInt();
            c = br.nextInt();
            vertices.add(new Vertice(a, b, c));
 }

Please, tell me how should I fix that loading code. Could you tell me how can I add e.g. every third record (a, b, c) to a new Polygon?


Solution

  • To make a polygon every 3 vertices. I didn't test it, but that's the idea:

        int i = 0;
    int polySize = 3;
    List<Polygon> polyList = new List<Polygon>();
    Polygon poly = new Polygon();
    
    while (file.hasNextDouble()) {
        a = br.nextDouble();
        b = br.nextInt();
        c = br.nextInt();
        vertice = new Vertice(a, b, c);
        poly.add(vertice);
    
        if (i == polySize-1)
        {
            polyList.add(poly);
            poly = new Polygon();
            i = 0;
        }
        i++;
    }