Deleting points from arrayList

Hi,

I have an issue with arrayLists.

What I want to do is delete vertices ("drawPolygon2DVertices(p, 5)") from inputPolys Arraylist, when intersectPolys ArrayList points have the same location coordinates and inputPolys ArrayList.

I know the script I am dealing with works with Hemesh library, but maybe there is specific function for arrayLists to achieve, this?

I have 1st arrayList:

ArrayList<WB_Polygon2D> inputPolys = new ArrayList<WB_Polygon2D>();

for (WB_Polygon2D p : inputPolys) {
    render.drawPolygon2DVertices(p, 5);
}

Then 2nd arrayList:

List<​WB_Polygon2D> intersectPolys = new ArrayList<​WB_Polygon2D>();

for (WB_Polygon2D p : intersectPolys){
      render.drawPolygon2DVertices(p, 5);      
    }//for

Thanks, Petras

Tagged:

Comments

  • See Processing reference on ArrayLists for a quick reference (they mention the remove() method), and Java's ArrayList for a more complete reference.

    Is that what you were looking for?

  • edited October 2013

    Dear PhiLho,

    Thank you for an answer.

    But, I could not find a solution I wanted, as I am working with Hemesh Library.

    What I want to do is even one step behind removing objects from ArrayList. I want to have acces to polygons points.

    I was working with Hemesh and I know by documentation that I can access polygons points, --> //points1.add(p.points);

    I work with eclipse, as a result, I see these functions but cannot make them work... The code is pretty much simple as I am working with basic hemesh functions.

    If you have some time, may you look at my code?

    package hemeshsubstractionintersection;
    
    import processing.core.PApplet;
    import wblut.math.*;
    import wblut.processing.*;
    import wblut.core.*;
    import wblut.hemesh.*;
    import wblut.geom.*;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class HemeshSubstractionIntersection extends PApplet {
    
        WB_Render render;
    
        public void setup() {
    
            size(1280, 720, OPENGL);
            smooth();
    
            render = new WB_Render(this);
    
    
        }// setup
    
        public void draw() {
    
            background(255);
            noStroke();
            noFill();
    
            int dim = 200;
    
            //ArrayList of inputpolys
            ArrayList<WB_Polygon2D> inputPolys = new ArrayList<WB_Polygon2D>();
            ArrayList<WB_Point2d> points = new ArrayList<WB_Point2d>();
    
            // Initialize inputPoly 1
            points.add(new WB_Point2d(width / 2, height / 3 - dim));
            points.add(new WB_Point2d(width / 2 + dim, height / 2 + dim / 2));
            points.add(new WB_Point2d(width / 2 - dim, height / 2 + dim / 2));
            inputPolys.add(new WB_Polygon2D(points));
            // clear points
            points.clear();
            // Initialize inputPoly 2
            points.add(new WB_Point2d(mouseX, mouseY - dim));
            points.add(new WB_Point2d(mouseX + dim, mouseY + dim / 2));
            points.add(new WB_Point2d(mouseX - dim, mouseY + dim / 2));
            inputPolys.add(new WB_Polygon2D(points));
            // clear points
            points.clear();
            // Initialize inputPoly 3
            points.add(new WB_Point2d(width / 4, height / 3 - dim));
            points.add(new WB_Point2d(width / 5 + dim, height / 5 + dim / 2));
            points.add(new WB_Point2d(width / 5 - dim, height / 5 + dim / 2));
            inputPolys.add(new WB_Polygon2D(points));
            // clear points
            points.clear();
            // Initialize inputPoly 4
            points.add(new WB_Point2d(width / 2, height / 3 + dim));
            points.add(new WB_Point2d(width - dim * 2, height / 8 + dim / 2));
            points.add(new WB_Point2d(width - dim, height / 2 + dim / 2));
            inputPolys.add(new WB_Polygon2D(points));
            // clear points
            points.clear();
    
    
            for (WB_Polygon2D p : inputPolys) {
                fill(0,10);
                //stroke(1);
                render.drawPolygon2D(p);
                  }
    
            //end of inputpolys
    
            // ArrayList of substractPolys
            List<WB_Polygon2D> substractPolys = new ArrayList<WB_Polygon2D>();
    
            for (int i = 0; i < inputPolys.size(); i++) {
                substractPolys.addAll(substractManyFromOne(inputPolys.get(i),
                        inputPolys));
            }// for
    
            stroke(0);
            fill(0, 50);
    
            for (WB_Polygon2D p : substractPolys) {
                //render.drawPolygon2D(p);
                //render.drawPolygon2DVertices(p, 5);
            }// for
                // end of substractPolys
    
            //ArrayList of intersectPolys
    
            List <WB_Polygon2D> intersectPolys = new ArrayList <WB_Polygon2D>();
            List <WB_Polygon2D> splitPolys = new ArrayList <WB_Polygon2D>();
            List<WB_Point2d> points1 = new ArrayList <WB_Point2d>();
    
            List<WB_Line2D> L = new ArrayList <WB_Line2D>();
            List <WB_Polygon2D> poly1 = new ArrayList <WB_Polygon2D>();
            List <WB_Polygon2D> frontPoly = new ArrayList <WB_Polygon2D>();
            List <WB_Polygon2D> backPoly = new ArrayList <WB_Polygon2D>();
    
            for(int i = 0; i < inputPolys.size(); i++){
                WB_Polygon2D a = inputPolys.get(i);
                for(int j = i + 1; j < inputPolys.size(); j++){
                    WB_Polygon2D b = inputPolys.get(j);
    
                    intersectPolys.addAll(WB_Polygon2D.intersection(a, b));
    
                }//for
            }//for
    
            for(WB_Polygon2D p : intersectPolys){
    
                //points1.add(p.points);
    
            }
    
    
            stroke(0);
            fill(0, 10);
    
    
    
            for(WB_Polygon2D p : intersectPolys){
                //if(p.points){
    
                render.drawPolygon2D(p);
            //  points1.addAll(WB_Polygon2D.p.points);
                render.drawPolygon2DVertices(p, 5); 
                //}//if
            }//for
                // end of intersectPolys
    
    
    
    
    
        }// draw
    
        // Function substractManyFromOne
        List<WB_Polygon2D> substractManyFromOne(WB_Polygon2D one, List<WB_Polygon2D> many) {
            // this will collect all the pieces that remain from "one" after subtracting "many"
            List<WB_Polygon2D> allFragments = new ArrayList<WB_Polygon2D>();
            //start with the source polygon "one"
            allFragments.add(one); 
    
            for(WB_Polygon2D other:many){
                if(other != one){
                    List <WB_Polygon2D> AllFragmentsMinusOther = new ArrayList <WB_Polygon2D> ();
                    for(WB_Polygon2D fragment : allFragments){
                        AllFragmentsMinusOther.addAll(WB_Polygon2D.subtract(fragment,other));
                    }//for
                    allFragments = AllFragmentsMinusOther;
                }//if
    
            }//for
            return allFragments;
        }// ArrayList substractManyFromOne
    
    }
    
Sign In or Register to comment.