Java Code Examples for org.apache.commons.math3.geometry.euclidean.twod.Vector2D#distance()

The following examples show how to use org.apache.commons.math3.geometry.euclidean.twod.Vector2D#distance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public ObjectiveFunctionGradient getObjectiveFunctionGradient() {
    return new ObjectiveFunctionGradient(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                Vector2D center = new Vector2D(params[0], params[1]);
                double radius = getRadius(center);
                // gradient of the sum of squared residuals
                double dJdX = 0;
                double dJdY = 0;
                for (Vector2D pk : points) {
                    double dk = pk.distance(center);
                    dJdX += (center.getX() - pk.getX()) * (dk - radius) / dk;
                    dJdY += (center.getY() - pk.getY()) * (dk - radius) / dk;
                }
                dJdX *= 2;
                dJdY *= 2;

                return new double[] { dJdX, dJdY };
            }
        });
}
 
Example 2
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public ObjectiveFunctionGradient getObjectiveFunctionGradient() {
    return new ObjectiveFunctionGradient(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                Vector2D center = new Vector2D(params[0], params[1]);
                double radius = getRadius(center);
                // gradient of the sum of squared residuals
                double dJdX = 0;
                double dJdY = 0;
                for (Vector2D pk : points) {
                    double dk = pk.distance(center);
                    dJdX += (center.getX() - pk.getX()) * (dk - radius) / dk;
                    dJdY += (center.getY() - pk.getY()) * (dk - radius) / dk;
                }
                dJdX *= 2;
                dJdY *= 2;

                return new double[] { dJdX, dJdY };
            }
        });
}
 
Example 3
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public ObjectiveFunctionGradient getObjectiveFunctionGradient() {
    return new ObjectiveFunctionGradient(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                Vector2D center = new Vector2D(params[0], params[1]);
                double radius = getRadius(center);
                // gradient of the sum of squared residuals
                double dJdX = 0;
                double dJdY = 0;
                for (Vector2D pk : points) {
                    double dk = pk.distance(center);
                    dJdX += (center.getX() - pk.getX()) * (dk - radius) / dk;
                    dJdY += (center.getY() - pk.getY()) * (dk - radius) / dk;
                }
                dJdX *= 2;
                dJdY *= 2;

                return new double[] { dJdX, dJdY };
            }
        });
}
 
Example 4
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public double getRadius(Vector2D center) {
    double r = 0;
    for (Vector2D point : points) {
        r += point.distance(center);
    }
    return r / points.size();
}
 
Example 5
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
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;
        sum += di * di;
    }

    return sum;
}
 
Example 6
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] params) {
            final int n = points.size();
            final Vector2D center = new Vector2D(params[0], params[1]);

            double dRdX = 0;
            double dRdY = 0;
            for (Vector2D pk : points) {
                double dk = pk.distance(center);
                dRdX += (center.getX() - pk.getX()) / dk;
                dRdY += (center.getY() - pk.getY()) / dk;
            }
            dRdX /= n;
            dRdY /= n;

            // Jacobian of the radius residuals.
            double[][] jacobian = new double[n][2];
            for (int i = 0; i < n; i++) {
                final Vector2D pi = points.get(i);
                final double di = pi.distance(center);
                jacobian[i][0] = (center.getX() - pi.getX()) / di - dRdX;
                jacobian[i][1] = (center.getY() - pi.getY()) / di - dRdY;
            }

            return jacobian;
        }
    };
}
 
Example 7
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ObjectiveFunction getObjectiveFunction() {
    return new ObjectiveFunction(new MultivariateFunction() {
            public double value(double[] params)  {
                Vector2D center = new Vector2D(params[0], params[1]);
                double radius = getRadius(center);
                double sum = 0;
                for (Vector2D point : points) {
                    double di = point.distance(center) - radius;
                    sum += di * di;
                }
                return sum;
            }
        });
}
 
Example 8
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public double getRadius(Vector2D center) {
    double r = 0;
    for (Vector2D point : points) {
        r += point.distance(center);
    }
    return r / points.size();
}
 
Example 9
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public double getRadius(Vector2D center) {
    double r = 0;
    for (Vector2D point : points) {
        r += point.distance(center);
    }
    return r / points.size();
}
 
Example 10
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public double getRadius(Vector2D center) {
    double r = 0;
    for (Vector2D point : points) {
        r += point.distance(center);
    }
    return r / points.size();
}
 
Example 11
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
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;
        sum += di * di;
    }

    return sum;
}
 
Example 12
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public double getRadius(Vector2D center) {
    double r = 0;
    for (Vector2D point : points) {
        r += point.distance(center);
    }
    return r / points.size();
}
 
Example 13
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkInSegment(Vector2D p,
                               Vector2D p1, Vector2D p2,
                               double tolerance) {
    Line line = new Line(p1, p2);
    if (line.getOffset(p) < tolerance) {
        double x  = (line.toSubSpace(p)).getX();
        double x1 = (line.toSubSpace(p1)).getX();
        double x2 = (line.toSubSpace(p2)).getX();
        return (((x - x1) * (x - x2) <= 0.0)
                || (p1.distance(p) < tolerance)
                || (p2.distance(p) < tolerance));
    } else {
        return false;
    }
}
 
Example 14
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ObjectiveFunction getObjectiveFunction() {
    return new ObjectiveFunction(new MultivariateFunction() {
            public double value(double[] params)  {
                Vector2D center = new Vector2D(params[0], params[1]);
                double radius = getRadius(center);
                double sum = 0;
                for (Vector2D point : points) {
                    double di = point.distance(center) - radius;
                    sum += di * di;
                }
                return sum;
            }
        });
}
 
Example 15
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public double getRadius(Vector2D center) {
    double r = 0;
    for (Vector2D point : points) {
        r += point.distance(center);
    }
    return r / points.size();
}
 
Example 16
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] params) {
            final int n = points.size();
            final Vector2D center = new Vector2D(params[0], params[1]);

            double dRdX = 0;
            double dRdY = 0;
            for (Vector2D pk : points) {
                double dk = pk.distance(center);
                dRdX += (center.getX() - pk.getX()) / dk;
                dRdY += (center.getY() - pk.getY()) / dk;
            }
            dRdX /= n;
            dRdY /= n;

            // Jacobian of the radius residuals.
            double[][] jacobian = new double[n][2];
            for (int i = 0; i < n; i++) {
                final Vector2D pi = points.get(i);
                final double di = pi.distance(center);
                jacobian[i][0] = (center.getX() - pi.getX()) / di - dRdX;
                jacobian[i][1] = (center.getY() - pi.getY()) / di - dRdY;
            }

            return jacobian;
        }
    };
}
 
Example 17
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
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;
        sum += di * di;
    }

    return sum;
}
 
Example 18
Source File: PolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkInSegment(Vector2D p,
                               Vector2D p1, Vector2D p2,
                               double tolerance) {
    Line line = new Line(p1, p2);
    if (line.getOffset(p) < tolerance) {
        double x  = (line.toSubSpace(p)).getX();
        double x1 = (line.toSubSpace(p1)).getX();
        double x2 = (line.toSubSpace(p2)).getX();
        return (((x - x1) * (x - x2) <= 0.0)
                || (p1.distance(p) < tolerance)
                || (p2.distance(p) < tolerance));
    } else {
        return false;
    }
}
 
Example 19
Source File: CircleScalar.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public double getRadius(Vector2D center) {
    double r = 0;
    for (Vector2D point : points) {
        r += point.distance(center);
    }
    return r / points.size();
}
 
Example 20
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] params) {
            final int n = points.size();
            final Vector2D center = new Vector2D(params[0], params[1]);

            double dRdX = 0;
            double dRdY = 0;
            for (Vector2D pk : points) {
                double dk = pk.distance(center);
                dRdX += (center.getX() - pk.getX()) / dk;
                dRdY += (center.getY() - pk.getY()) / dk;
            }
            dRdX /= n;
            dRdY /= n;

            // Jacobian of the radius residuals.
            double[][] jacobian = new double[n][2];
            for (int i = 0; i < n; i++) {
                final Vector2D pi = points.get(i);
                final double di = pi.distance(center);
                jacobian[i][0] = (center.getX() - pi.getX()) / di - dRdX;
                jacobian[i][1] = (center.getY() - pi.getY()) / di - dRdY;
            }

            return jacobian;
        }
    };
}