I couldn't resist this problem in spite of being massively behind in, well everything. My solution is not elegant nor terribly efficient, but the basic math seems to get the job done–at least for ellipses with the same diameter.
Hope this is sort of what you were looking for.
-ira
Code:
/* Dynamically calculate overlap shape &
average color between 2 intersecting
ellipses (of equal diameter) */
Circle c1, c2;
void setup(){
size(400, 400);
smooth();
c1 = new Circle(50, color(255, 0, 0));
c2 = new Circle(50, color(0, 0, 255));
}
void draw(){
background(225, 225, 20);
noStroke();
c1.createCircle(200, 200);
c2.createCircle(mouseX, mouseY);
float d = dist(c1.x, c1.y, c2.x, c2.y);
if (d < c1.r+c2.r){
// calculate vector between ellipse centers
float dragAng = atan2(c2.y-c1.y, c2.x-c1.x);
// calculate angle from ellipse
// center to overlap point(s)
float overlapAng = acos(d/2/c1.r);
// calculate overlap points
float px1 = c1.x+cos(dragAng+overlapAng)*c1.r;
float py1 = c1.y+sin(dragAng+overlapAng)*c1.r;
float px2 = c1.x+cos(dragAng-overlapAng)*c1.r;
float py2 = c1.y+sin(dragAng-overlapAng)*c1.r;
// create overlapping section
/* calculate average color for overlap
obviously bitwise ops would be faster */
float r = (red(c1.c)+red(c2.c))/2;
float g = (green(c1.c)+green(c2.c))/2;
float b = (blue(c1.c)+blue(c2.c))/2;
fill(r, g, b);
//plot overlap shape
noStroke();
int detail = 20;
float ang = degrees(dragAng-overlapAng);
float arcAng = 0;
float cx=0, cy=0;
beginShape();
// arc 1
// not efficient but it works
for (int i=0; i<detail; i++){
cx = c1.x+cos(radians(ang+arcAng))*c1.r;
cy = c1.y+sin(radians(ang+arcAng))*c1.r;
vertex(cx, cy);
arcAng+=degrees(((overlapAng)*2)/detail);
}
// arc 2
arcAng = 0;
for (int i=0; i<detail; i++){
cx = c2.x+cos(radians(-180+ang+arcAng))*c2.r;
cy = c2.y+sin(radians(-180+ang+arcAng))*c2.r;
vertex(cx, cy);
arcAng+=degrees(((overlapAng)*2)/detail);
}
endShape(CLOSE);
// draw drag vector
stroke(255);
line(c1.x, c1.y, c2.x, c2.y);
// draw overlap points with connecting line
noStroke();
fill(255);
ellipse(px1, py1, 5, 5);
ellipse(px2, py2, 5, 5);
stroke(200);
line(px1, py1, px2, py2);
/* draw overlap triangles -
illustrating trig relationships */
line(c1.x, c1.y, px1, py1);
line(c1.x, c1.y, px2, py2);
line(c2.x, c2.y, px1, py1);
line(c2.x, c2.y, px2, py2);
}
}
class Circle{
float x, y, r;
color c;
Circle(float r, color c){
this.r = r;
this.c = c;
}
void createCircle(float x, float y){
fill(c);
this.x = x;
this.y = y;
ellipse(x, y, r*2, r*2);
}
}