예제 #1
0
  @Override
  public final void compute() {
    int size = geoList.size();
    if (!geoList.isDefined() || size <= 1) {
      g.setUndefined();
      return;
    }

    double sigmax = 0;
    double sigmay = 0;
    double sigmaxx = 0;
    // double sigmayy=0; not needed
    double sigmaxy = 0;

    for (int i = 0; i < size; i++) {
      GeoElement geo = geoList.get(i);
      if (geo.isGeoPoint()) {
        double x;
        double y;
        if (geo.isGeoElement3D()) {
          Coords coords = ((GeoPointND) geo).getInhomCoordsInD3();
          if (!Kernel.isZero(coords.getZ())) {
            g.setUndefined();
            return;
          }
          x = coords.getX();
          y = coords.getY();
        } else {
          double xy[] = new double[2];
          ((GeoPoint) geo).getInhomCoords(xy);
          x = xy[0];
          y = xy[1];
        }

        sigmax += x;
        sigmay += y;
        sigmaxx += x * x;
        sigmaxy += x * y;
        // sigmayy+=y*y; not needed
      } else {
        g.setUndefined();
        return;
      }
    }
    // y on x regression line
    // (y - sigmay / n) = (Sxx / Sxy)*(x - sigmax / n)
    // rearranged to eliminate all divisions
    g.x = size * sigmax * sigmay - size * size * sigmaxy;
    g.y = size * size * sigmaxx - size * sigmax * sigmax;
    g.z = size * sigmax * sigmaxy - size * sigmaxx * sigmay; // (g.x)x +
    // (g.y)y +
    // g.z = 0
  }
 /** Calls doRemove() for all output objects of this algorithm except for keepGeo. */
 @Override
 public void removeOutputExcept(GeoElement keepGeo) {
   for (int i = 0; i < super.getOutputLength(); i++) {
     GeoElement geo = super.getOutput(i);
     if (geo != keepGeo) {
       if (geo.isGeoPoint()) {
         removePoint(geo);
       } else {
         geo.doRemove();
       }
     }
   }
 }