getting points inside a shape
in
Contributed Library Questions
•
1 year ago
Hey all,
i am starting with geomerative library, so i still have troubles with the basic. hope somebody could give me a suggestion.
I have a shape and an array of points.
I need to check if the points are inside the shape with the boolean contains, and storage the ones that returns true into an array. The problem is that i can not simply add them into an array list, because for my project i need always the same amount of elements in my storage.
Probably i will have to use somehow the getPoints() command but i simply can not figure it out.....
Would somebody please have a suggestion?
Thanks a lot!!
I made this basic sketch just to test on...
- import geomerative.*;
- RShape shp;
- RPoint [] pts= new RPoint [50];
- void setup() {
- size(1000, 1000);
- RG.init( this );
- }
- void draw () {
- background (255);
- stroke(0);
- strokeWeight(2);
- shp = new RShape();
- shp.addMoveTo(width/2-200,height/2-100);
- shp.addLineTo(width/2+200,height/2-100);
- shp.addLineTo(width/2+200,height/2+100);
- shp.addLineTo(width/2-200,height/2+100);
- shp.addClose();
- shp.draw();
- float a= shp.getArea();
- //println(a);
- strokeWeight(1);
- for (int i=0; i<pts.length; i++) {
- for (int j=0; j<pts.length;j=j+20) {
- pts[i]= new RPoint (j*i, j*i);
- ellipse (pts[i].x,pts[i].y,5,5);
- }
- }
- // RPoint [] valid pts = shp.contains();
- }
1