예제 #1
0
  public AlgoCircleThreePoints(Construction cons, GeoPointND A, GeoPointND B, GeoPointND C) {

    super(cons);

    setPoints(A, B, C);

    createCircle();
    circle.addPointOnConic(getA());
    circle.addPointOnConic(getB());
    circle.addPointOnConic(getC());

    // temp: line bisectors
    s0 = new GeoLine(cons);
    s1 = new GeoLine(cons);

    center = new GeoPoint(cons);

    setInputOutput(); // for AlgoElement

    compute();
  }
예제 #2
0
 // compute incircle of triangle A, B, C
 @Override
 public void compute() {
   // bisector of angle ABC
   double dAB = getA().distance(getB());
   double dAC = getA().distance(getC());
   double dBC = getB().distance(getC());
   double dmax = dAB > dBC ? dAB : dBC;
   A1.setCoords(
       dmax / dAB * (getA().inhomX - getB().inhomX) + getB().inhomX,
       dmax / dAB * (getA().inhomY - getB().inhomY) + getB().inhomY,
       1.0d);
   C1.setCoords(
       dmax / dBC * (getC().inhomX - getB().inhomX) + getB().inhomX,
       dmax / dBC * (getC().inhomY - getB().inhomY) + getB().inhomY,
       1.0d);
   B1.setCoords((A1.inhomX + C1.inhomX) / 2.0d, (A1.inhomY + C1.inhomY) / 2.0d, 1.0d);
   GeoVec3D.lineThroughPoints(getB(), B1, bisectorB);
   // bisector of angle BCA
   dmax = dAC > dBC ? dAC : dBC;
   A1.setCoords(
       dmax / dAC * (getA().inhomX - getC().inhomX) + getC().inhomX,
       dmax / dAC * (getA().inhomY - getC().inhomY) + getC().inhomY,
       1.0d);
   B1.setCoords(
       dmax / dBC * (getB().inhomX - getC().inhomX) + getC().inhomX,
       dmax / dBC * (getB().inhomY - getC().inhomY) + getC().inhomY,
       1.0d);
   C1.setCoords((A1.inhomX + B1.inhomX) / 2.0d, (A1.inhomY + B1.inhomY) / 2.0d, 1.0d);
   GeoVec3D.lineThroughPoints(getC(), C1, bisectorC);
   // intersect angle bisectors to get incenter
   GeoVec3D.lineThroughPoints(getB(), getC(), sideBC);
   GeoVec3D.cross(bisectorB, bisectorC, incenter);
   GeoVec3D.cross(incenter, sideBC.x, sideBC.y, 0.0, heightBC);
   GeoVec3D.cross(sideBC, heightBC, heightFoot);
   double dist = incenter.distance(heightFoot);
   circle.setCircle(incenter, dist);
 }
예제 #3
0
 public AlgoIncircle(Construction cons, String label, GeoPointND A, GeoPointND B, GeoPointND C) {
   this(cons, A, B, C);
   circle.setLabel(label);
 }
예제 #4
0
 protected AlgoCircleThreePoints(
     Construction cons, String label, GeoPointND A, GeoPointND B, GeoPointND C) {
   this(cons, A, B, C);
   circle.setLabel(label);
 }
예제 #5
0
  // compute circle through A, B, C
  protected void compute() {
    // A, B or C undefined
    if (!getA().isFinite() || !getB().isFinite() || !getC().isFinite()) {
      circle.setUndefined();
      return;
    }

    // get inhomogenous coords of points
    ax = ((GeoPoint) getA()).inhomX;
    ay = ((GeoPoint) getA()).inhomY;
    bx = ((GeoPoint) getB()).inhomX;
    by = ((GeoPoint) getB()).inhomY;
    cx = ((GeoPoint) getC()).inhomX;
    cy = ((GeoPoint) getC()).inhomY;

    // A = B = C
    if (kernel.isEqual(ax, bx)
        && kernel.isEqual(ax, cx)
        && kernel.isEqual(ay, by)
        && kernel.isEqual(ay, cy)) {
      circle.setCircle((GeoPoint) getA(), 0.0); // single point
      return;
    }

    // calc vectors AB, AC, BC
    ABx = bx - ax;
    ABy = by - ay;
    ACx = cx - ax;
    ACy = cy - ay;
    BCx = cx - bx;
    BCy = cy - by;

    double lengthAB = GeoVec2D.length(ABx, ABy);
    double lengthAC = GeoVec2D.length(ACx, ACy);
    double lengthBC = GeoVec2D.length(BCx, BCy);

    // find the two bisectors with max intersection angle
    // i.e. maximum abs of determinant of directions
    // max( abs(det(AB, AC)), abs(det(AC, BC)), abs(det(AB, BC)) )
    det[0] = Math.abs(ABx * ACy - ABy * ACx) / (lengthAB * lengthAC);
    // AB, AC
    det[1] = Math.abs(ACx * BCy - ACy * BCx) / (lengthAC * lengthBC);
    // AC, BC
    det[2] = Math.abs(ABx * BCy - ABy * BCx) / (lengthAB * lengthBC);
    // AB, BC

    // take ip[0] as init minimum and find minimum case
    maxDet = det[0];
    casenr = 0;
    if (det[1] > maxDet) {
      casenr = 1;
      maxDet = det[1];
    }
    if (det[2] > maxDet) {
      casenr = 2;
      maxDet = det[2];
    }

    // A, B, C are collinear: set M to infinite point
    // in perpendicular direction of AB
    if (kernel.isZero(maxDet)) {
      center.setCoords(-ABy, ABx, 0.0d);
      circle.setCircle(center, (GeoPoint) getA());
    }
    // standard case
    else {
      // intersect two line bisectors according to casenr
      switch (casenr) {
        case 0: // bisectors of AB, AC
          s0.x = ABx;
          s0.y = ABy;
          s0.z = -((ax + bx) * s0.x + (ay + by) * s0.y) / 2.0;

          s1.x = ACx;
          s1.y = ACy;
          s1.z = -((ax + cx) * s1.x + (ay + cy) * s1.y) / 2.0;
          break;

        case 1: // bisectors of AC, BC
          s1.x = ACx;
          s1.y = ACy;
          s1.z = -((ax + cx) * s1.x + (ay + cy) * s1.y) / 2.0;

          s0.x = BCx;
          s0.y = BCy;
          s0.z = -((bx + cx) * s0.x + (by + cy) * s0.y) / 2.0;
          break;

        case 2: // bisectors of AB, BC
          s0.x = ABx;
          s0.y = ABy;
          s0.z = -((ax + bx) * s0.x + (ay + by) * s0.y) / 2.0;

          s1.x = BCx;
          s1.y = BCy;
          s1.z = -((bx + cx) * s1.x + (by + cy) * s1.y) / 2.0;
          break;
      }

      // intersect line bisectors to get midpoint
      GeoVec3D.cross(s0, s1, center);
      circle.setCircle(center, center.distance(getA()));
    }
  }