I draw a simple intersection between two rectangles but the result is not accurate.
The simple code is:
import geomerative.*;
void setup()
{
size(600, 400);
smooth();
background(255);
noFill();
RG.init(this);
strokeWeight(4);
RShape R = RShape.createRectangle(100, 50, 100, 100);
RShape S = RShape.createRectangle(130, 70, 100, 100);
RShape T = S.intersection(R);
S=S.diff(T);
stroke(0,255,0);
S.draw();
stroke(255,0,0);
R.draw();
}
void draw() {
}
The result is this:
Why??
I’m not sure why, depending on your requirements you might want to try toxiclibs:-
import toxi.geom.*;
import toxi.processing.*;
import java.util.List;
ToxiclibsSupport gfx;
void setup() {
size(600, 400);
smooth();
background(255);
noFill();
strokeWeight(4);
gfx = new ToxiclibsSupport(this);
BooleanShapeBuilder builder = new BooleanShapeBuilder(
BooleanShapeBuilder.Type.UNION);
stroke(255, 0, 0);
builder.addShape(new Rect(100, 50, 100, 100));
stroke(255, 255, 0);
builder.addShape(new Rect(130, 70, 100, 100));
List<Polygon2D> polies = builder.computeShapes();
for (Polygon2D p : polies) {
gfx.polygon2D(p);
}
}