Examples of Vector2d


Examples of org.apache.commons.math3.geometry.euclidean.twod.Vector2D

        }
        return r.divide(points.size());
    }

    public double value(double[] variables)  {
        Vector2D center = new Vector2D(variables[0], variables[1]);
        double radius = getRadius(center);

        double sum = 0;
        for (Vector2D point : points) {
            double di = point.distance(center) - radius;
View Full Code Here

Examples of org.apache.commons.math3.geometry.euclidean.twod.Vector2D

            new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
                                                    new SimpleValueChecker(1e-30, 1e-30),
                                                    new BrentSolver(1e-15, 1e-13));
        PointValuePair optimum =
            optimizer.optimize(100, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
        Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]);
        Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8);
        Assert.assertEquals(96.075902096, center.getX(), 1.0e-8);
        Assert.assertEquals(48.135167894, center.getY(), 1.0e-8);
    }
View Full Code Here

Examples of org.apache.commons.math3.geometry.euclidean.twod.Vector2D

            = optimizer.optimize(new MaxEval(100),
                                 problem.getObjectiveFunction(),
                                 problem.getObjectiveFunctionGradient(),
                                 GoalType.MINIMIZE,
                                 new InitialGuess(new double[] { 98.680, 47.345 }));
        Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]);
        Assert.assertEquals(69.960161753, problem.getRadius(center), 1.0e-8);
        Assert.assertEquals(96.075902096, center.getX(), 1.0e-7);
        Assert.assertEquals(48.135167894, center.getY(), 1.0e-6);
    }
View Full Code Here

Examples of org.apache.commons.math3.geometry.euclidean.twod.Vector2D

        PointValuePair optimum =
            optimizer.optimize(200, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
        Assert.assertEquals(200, optimizer.getMaxEvaluations());
        PointValuePair[] optima = optimizer.getOptima();
        for (PointValuePair o : optima) {
            Vector2D center = new Vector2D(o.getPointRef()[0], o.getPointRef()[1]);
            Assert.assertEquals(69.960161753, circle.getRadius(center), 1.0e-8);
            Assert.assertEquals(96.075902096, center.getX(), 1.0e-8);
            Assert.assertEquals(48.135167894, center.getY(), 1.0e-8);
        }
        Assert.assertTrue(optimizer.getEvaluations() > 70);
        Assert.assertTrue(optimizer.getEvaluations() < 90);
        Assert.assertEquals(3.1267527, optimum.getValue(), 1.0e-8);
    }
View Full Code Here

Examples of org.apache.commons.math3.geometry.euclidean.twod.Vector2D

                                 new Weight(new double[] { 1, 1, 1, 1, 1 }),
                                 new InitialGuess(new double[] { 98.680, 47.345 }));
        Assert.assertTrue(optimizer.getEvaluations() < 10);
        double rms = optimizer.getRMS();
        Assert.assertEquals(1.768262623567235,  FastMath.sqrt(circle.getN()) * rms,  1e-10);
        Vector2D center = new Vector2D(optimum.getPointRef()[0], optimum.getPointRef()[1]);
        Assert.assertEquals(69.96016176931406, circle.getRadius(center), 1e-6);
        Assert.assertEquals(96.07590211815305, center.getX(),            1e-6);
        Assert.assertEquals(48.13516790438953, center.getY(),            1e-6);
        double[][] cov = optimizer.computeCovariances(optimum.getPoint(), 1e-14);
        Assert.assertEquals(1.839, cov[0][0], 0.001);
        Assert.assertEquals(0.731, cov[0][1], 0.001);
        Assert.assertEquals(cov[0][1], cov[1][0], 1e-14);
        Assert.assertEquals(0.786, cov[1][1], 0.001);

        // add perfect measurements and check errors are reduced
        double  r = circle.getRadius(center);
        for (double d= 0; d < 2 * FastMath.PI; d += 0.01) {
            circle.addPoint(center.getX() + r * FastMath.cos(d), center.getY() + r * FastMath.sin(d));
        }
        double[] target = new double[circle.getN()];
        Arrays.fill(target, 0);
        double[] weights = new double[circle.getN()];
        Arrays.fill(weights, 2);
View Full Code Here

Examples of org.rascalmpl.library.vis.util.vector.Vector2D

    double cy = 0;
    for (SpringGraphNode n : nodes){
      cx += n.getCenterX();
      cy += n.getCenterY();
    }
    return new Vector2D(cx / nodes.size(), cy / nodes.size());
  }
View Full Code Here

Examples of org.rascalmpl.library.vis.util.vector.Vector2D

  public void init() {
    x = FigureMath.random(width()/2, G.minSize.getX() - width()/2);
    y = FigureMath.random(height()/2, G.minSize.getY() -height()/2);
    temperature = G.MAX_LOCAL_TEMPERATURE;
    skew = 0;
    oldImpulse = new Vector2D(0, 0);
  }
View Full Code Here

Examples of org.rascalmpl.library.vis.util.vector.Vector2D

  protected double getCenterY() {
    return y;
  }
 
  public Vector2D getCenter() {
    return new Vector2D(x, y);
  }
View Full Code Here

Examples of org.rascalmpl.library.vis.util.vector.Vector2D

  // Perform one step of the spring simulation algorithm for this node

  public void step() {
    if(debug) print("update, before");
    Vector2D impulse = computeNodeImpulse();
    double angle = oldImpulse.angle(impulse);
    adjustTemperatureAndSkew(angle);
    double dx = G.UPDATE_STEP * impulse.getX() * temperature;
    double dy = G.UPDATE_STEP * impulse.getY() * temperature;

    moveBy(dx, dy); // adjust local position

    if(debug){
      print("relax, after ");
      System.err.printf("             imp (%3.2f, %3.2f), angle %1.2f, dx %3.2f, dy %3.2f\n",
            impulse.getX(), impulse.getY(), Math.toDegrees(angle),
            dx, dy);
    }
    oldImpulse = impulse;
  }
View Full Code Here

Examples of org.rascalmpl.library.vis.util.vector.Vector2D

   * A = (this - other) * distance^2 / (EDGE_LENGTH_2 * PHI) * ATTRACT
   *
   */
  public Vector2D attractiveForce(SpringGraphNode other) {
    double distance2 = distance2(other);
    Vector2D thisVector = new Vector2D(x, y);
    Vector2D otherVector = new Vector2D(other.x, other.y);
    return thisVector.sub(otherVector).mul(distance2).div(G.EDGE_LENGTH_2 * getMass()) .mul(G.ATTRACT);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.