public class Bichord extends LineElement {

  CircleElement C,D;	// chord where two circles intersect

  Bichord (CircleElement Cval, CircleElement Dval) {
    dimension = 1;
    A = new PointElement();  B = new PointElement();
    C = Cval;  D = Dval;
  }

  protected void translate (double dx, double dy) {
    A.translate(dx,dy);
    B.translate(dx,dy);
  }

  protected void rotate (PointElement pivot, double ac, double as) {
    A.rotate(pivot,ac,as);
    B.rotate(pivot,ac,as);
  }

  protected void update() {
    double r = C.radius();
    double s = D.radius();
    double d = C.Center.distance(D.Center);
    if (d > r + s) {
      A.x = A.y = B.x = B.y = 0.0/0.0;
      return;
    }
    A.toCircle(D.Center,C);
    double costheta = (d*d + r*r - s*s) / (2.0 * d * r);
    double sintheta = Math.sqrt(1.0-costheta*costheta);
    A.toCircle(D.Center,C);
    B.x = A.x; B.y = A.y;
    A.rotate(C.Center,costheta,sintheta);
    B.rotate(C.Center,costheta,-sintheta);
  }
}
