// two intersecting circles
float x0; float y0; float r0;
float x1; float y1; float r1;
float x2; float y2;
float x3; float y3;
float x4; float y4;
float a; float b;
float h; float d;
void setup() {
size(360, 240);
smooth();
stroke(0);
x0 = 120; y0 = 120; r0 = 80;
x1 = 240; y1 = 120; r1 = 80;
} //setup
void draw() {
background(207);
strokeWeight(3);
noFill();
ellipse(x0, y0, 2*r0, 2*r0);
ellipse(x1, y1, 2*r1, 2*r1);
d = dist(x0, y0, x1, y1);
a = (r0*r0 - r1*r1 + d*d)/(2*d);
x2 = x0 + a*(x1 - x0) / d;
x4 = x2;
h = sqrt(r0*r0 - a*a);
y2 = y0 + h;
y4 = y0 - h;
strokeWeight(1);
fill(255);
ellipse(x0, y0, 5, 5); // P1
ellipse(x1, y1, 5, 5); // P2
ellipse(x2, y2, 5, 5); // P3
ellipse(x4, y4, 5, 5); // P4
} //draw
void mouseDragged()
{
if (dist(mouseX, mouseY, x0, y0) <= 15) {
x0 = mouseX;
//y0 = mouseY;
} else if (dist(mouseX, mouseY, x1, y1) <= 15) {
x1 = mouseX;
//y1 = mouseY;
}
} //mouseDragged
|