/** Triangle-Triangle Intersection Dave Bollinger http://www.davebollinger.com move primary triangle with mouse right click to generate new secondary triangle */ Triangle2D sec; void setup() { size(400,400,JAVA2D); smooth(); build(); } void build() { sec = new Triangle2D( random(width), random(height), random(width), random(height), random(width), random(height) ); } void draw() { background(255); stroke(0); // build up some arbitrary irregular triangle around the mouse Triangle2D pri = new Triangle2D( mouseX-50, mouseY+20, mouseX+30, mouseY-40, mouseX+40, mouseY+40 ); // set the fill color based on overlap status if (pri.overlaps(sec)) fill(255,0,0); else fill(0,255,0); // draw the triangles sec.draw(); pri.draw(); } void mousePressed() { if (mouseButton==RIGHT) build(); }