Java Code Examples for org.apache.commons.math3.geometry.euclidean.twod.Vector2D#getX()
The following examples show how to use
org.apache.commons.math3.geometry.euclidean.twod.Vector2D#getX() .
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 |
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: PolyhedronsSet.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public SubHyperplane<Euclidean2D> apply(final SubHyperplane<Euclidean2D> sub, final Hyperplane<Euclidean3D> original, final Hyperplane<Euclidean3D> transformed) { if (original != cachedOriginal) { // we have changed hyperplane, reset the in-hyperplane transform final Plane oPlane = (Plane) original; final Plane tPlane = (Plane) transformed; final Vector3D p00 = oPlane.getOrigin(); final Vector3D p10 = oPlane.toSpace((Point<Euclidean2D>) new Vector2D(1.0, 0.0)); final Vector3D p01 = oPlane.toSpace((Point<Euclidean2D>) new Vector2D(0.0, 1.0)); final Vector2D tP00 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p00)); final Vector2D tP10 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p10)); final Vector2D tP01 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p01)); final AffineTransform at = new AffineTransform(tP10.getX() - tP00.getX(), tP10.getY() - tP00.getY(), tP01.getX() - tP00.getX(), tP01.getY() - tP00.getY(), tP00.getX(), tP00.getY()); cachedOriginal = (Plane) original; cachedTransform = org.apache.commons.math3.geometry.euclidean.twod.Line.getTransform(at); } return ((SubLine) sub).applyTransform(cachedTransform); }
Example 3
Source File: CircleScalar.java From astor with GNU General Public License v2.0 | 6 votes |
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: CircleProblem.java From astor with GNU General Public License v2.0 | 6 votes |
public double[] value(double[] params) { final double cx = params[0]; final double cy = params[1]; final double r = params[2]; final double[] model = new double[points.size() * 2]; for (int i = 0; i < points.size(); i++) { final Vector2D p = points.get(i); // Find the circle point closest to the observed point // (observed points are points add through the addPoint method above) final double dX = cx - p.getX(); final double dY = cy - p.getY(); final double scaling = r / FastMath.hypot(dX, dY); final int index = i * 2; model[index] = cx - scaling * dX; model[index + 1] = cy - scaling * dY; } return model; }
Example 5
Source File: NPEfix10_ten_s.java From coming with MIT License | 6 votes |
/** {@inheritDoc} */ public SubHyperplane<Euclidean2D> apply(final SubHyperplane<Euclidean2D> sub, final Hyperplane<Euclidean3D> original, final Hyperplane<Euclidean3D> transformed) { if (original != cachedOriginal) { // we have changed hyperplane, reset the in-hyperplane transform final Plane oPlane = (Plane) original; final Plane tPlane = (Plane) transformed; final Vector3D p00 = oPlane.getOrigin(); final Vector3D p10 = oPlane.toSpace((Point<Euclidean2D>) new Vector2D(1.0, 0.0)); final Vector3D p01 = oPlane.toSpace((Point<Euclidean2D>) new Vector2D(0.0, 1.0)); final Vector2D tP00 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p00)); final Vector2D tP10 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p10)); final Vector2D tP01 = tPlane.toSubSpace((Point<Euclidean3D>) apply(p01)); final AffineTransform at = new AffineTransform(tP10.getX() - tP00.getX(), tP10.getY() - tP00.getY(), tP01.getX() - tP00.getX(), tP01.getY() - tP00.getY(), tP00.getX(), tP00.getY()); cachedOriginal = (Plane) original; cachedTransform = org.apache.commons.math3.geometry.euclidean.twod.Line.getTransform(at); } return ((SubLine) sub).applyTransform(cachedTransform); }
Example 6
Source File: ProjectToBorderEvaluator.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Object doWork(Object value1, Object value2) throws IOException { if(!(value1 instanceof ConvexHull2D)){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - found type %s for value, expecting a ConvexHull2D",toExpression(constructingFactory), value1.getClass().getSimpleName())); } if(!(value2 instanceof Matrix)){ throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - found type %s for value, expecting a Matrix",toExpression(constructingFactory), value2.getClass().getSimpleName())); } ConvexHull2D convexHull2D = (ConvexHull2D)value1; Matrix matrix = (Matrix)value2; double[][] data = matrix.getData(); Region<Euclidean2D> region = convexHull2D.createRegion(); double[][] borderPoints = new double[data.length][2]; int i = 0; for(double[] row : data) { BoundaryProjection<Euclidean2D> boundaryProjection = region.projectToBoundary(new Vector2D(row)); Vector2D point = (Vector2D)boundaryProjection.getProjected(); borderPoints[i][0] = point.getX(); borderPoints[i][1] = point.getY(); i++; } return new Matrix(borderPoints); }
Example 7
Source File: CircleVectorial.java From astor with GNU General Public License v2.0 | 5 votes |
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 8
Source File: OutlineExtractor.java From astor with GNU General Public License v2.0 | 5 votes |
/** Check if a point is geometrically between its neighbour in an array. * <p>The neighbours are computed considering the array is a loop * (i.e. point at index (n-1) is before point at index 0)</p> * @param loop points array * @param n number of points to consider in the array * @param i index of the point to check (must be between 0 and n-1) * @return true if the point is exactly between its neighbours */ private boolean pointIsBetween(final Vector2D[] loop, final int n, final int i) { final Vector2D previous = loop[(i + n - 1) % n]; final Vector2D current = loop[i]; final Vector2D next = loop[(i + 1) % n]; final double dx1 = current.getX() - previous.getX(); final double dy1 = current.getY() - previous.getY(); final double dx2 = next.getX() - current.getX(); final double dy2 = next.getY() - current.getY(); final double cross = dx1 * dy2 - dx2 * dy1; final double dot = dx1 * dx2 + dy1 * dy2; final double d1d2 = FastMath.sqrt((dx1 * dx1 + dy1 * dy1) * (dx2 * dx2 + dy2 * dy2)); return (FastMath.abs(cross) <= (1.0e-6 * d1d2)) && (dot >= 0.0); }
Example 9
Source File: OutlineExtractor.java From astor with GNU General Public License v2.0 | 5 votes |
/** Check if a point is geometrically between its neighbor in an array. * <p>The neighbors are computed considering the array is a loop * (i.e. point at index (n-1) is before point at index 0)</p> * @param loop points array * @param n number of points to consider in the array * @param i index of the point to check (must be between 0 and n-1) * @return true if the point is exactly between its neighbors */ private boolean pointIsBetween(final Vector2D[] loop, final int n, final int i) { final Vector2D previous = loop[(i + n - 1) % n]; final Vector2D current = loop[i]; final Vector2D next = loop[(i + 1) % n]; final double dx1 = current.getX() - previous.getX(); final double dy1 = current.getY() - previous.getY(); final double dx2 = next.getX() - current.getX(); final double dy2 = next.getY() - current.getY(); final double cross = dx1 * dy2 - dx2 * dy1; final double dot = dx1 * dx2 + dy1 * dy2; final double d1d2 = FastMath.sqrt((dx1 * dx1 + dy1 * dy1) * (dx2 * dx2 + dy2 * dy2)); return (FastMath.abs(cross) <= (1.0e-6 * d1d2)) && (dot >= 0.0); }
Example 10
Source File: CircleProblem.java From astor with GNU General Public License v2.0 | 5 votes |
public double[] target() { final double[] t = new double[points.size() * 2]; for (int i = 0; i < points.size(); i++) { final Vector2D p = points.get(i); final int index = i * 2; t[index] = p.getX(); t[index + 1] = p.getY(); } return t; }
Example 11
Source File: CircleVectorial.java From astor with GNU General Public License v2.0 | 5 votes |
public ModelFunctionJacobian getModelFunctionJacobian() { return new ModelFunctionJacobian(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 12
Source File: Vector2DUtil.java From NOVA-Core with GNU Lesser General Public License v3.0 | 4 votes |
public static Vector2D reciprocal(Vector2D vec) { return new Vector2D(1 / vec.getX(), 1 / vec.getY()); }
Example 13
Source File: Plane.java From astor with GNU General Public License v2.0 | 2 votes |
/** Transform an in-plane point into a 3D space point. * @param point in-plane point (must be a {@link * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance) * @return 3D space point (really a {@link Vector3D Vector3D} instance) * @see #toSubSpace */ public Vector3D toSpace(final Point<Euclidean2D> point) { final Vector2D p2D = (Vector2D) point; return new Vector3D(p2D.getX(), u, p2D.getY(), v, -originOffset, w); }
Example 14
Source File: Plane.java From astor with GNU General Public License v2.0 | 2 votes |
/** Get one point from the 3D-space. * @param inPlane desired in-plane coordinates for the point in the * plane * @param offset desired offset for the point * @return one point in the 3D-space, with given coordinates and offset * relative to the plane */ public Vector3D getPointAt(final Vector2D inPlane, final double offset) { return new Vector3D(inPlane.getX(), u, inPlane.getY(), v, offset - originOffset, w); }
Example 15
Source File: Plane.java From astor with GNU General Public License v2.0 | 2 votes |
/** Get one point from the 3D-space. * @param inPlane desired in-plane coordinates for the point in the * plane * @param offset desired offset for the point * @return one point in the 3D-space, with given coordinates and offset * relative to the plane */ public Vector3D getPointAt(final Vector2D inPlane, final double offset) { return new Vector3D(inPlane.getX(), u, inPlane.getY(), v, offset - originOffset, w); }
Example 16
Source File: Plane.java From astor with GNU General Public License v2.0 | 2 votes |
/** Transform an in-plane point into a 3D space point. * @param point in-plane point (must be a {@link * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance) * @return 3D space point (really a {@link Vector3D Vector3D} instance) * @see #toSubSpace */ public Vector3D toSpace(final Vector<Euclidean2D> point) { final Vector2D p2D = (Vector2D) point; return new Vector3D(p2D.getX(), u, p2D.getY(), v, -originOffset, w); }
Example 17
Source File: Plane.java From astor with GNU General Public License v2.0 | 2 votes |
/** Transform an in-plane point into a 3D space point. * @param point in-plane point (must be a {@link * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance) * @return 3D space point (really a {@link Vector3D Vector3D} instance) * @see #toSubSpace */ public Vector3D toSpace(final Vector<Euclidean2D> point) { final Vector2D p2D = (Vector2D) point; return new Vector3D(p2D.getX(), u, p2D.getY(), v, -originOffset, w); }
Example 18
Source File: Plane.java From astor with GNU General Public License v2.0 | 2 votes |
/** Get one point from the 3D-space. * @param inPlane desired in-plane coordinates for the point in the * plane * @param offset desired offset for the point * @return one point in the 3D-space, with given coordinates and offset * relative to the plane */ public Vector3D getPointAt(final Vector2D inPlane, final double offset) { return new Vector3D(inPlane.getX(), u, inPlane.getY(), v, offset - originOffset, w); }
Example 19
Source File: Plane.java From astor with GNU General Public License v2.0 | 2 votes |
/** Transform an in-plane point into a 3D space point. * @param point in-plane point (must be a {@link * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance) * @return 3D space point (really a {@link Vector3D Vector3D} instance) * @see #toSubSpace */ public Vector3D toSpace(final Vector<Euclidean2D> point) { final Vector2D p2D = (Vector2D) point; return new Vector3D(p2D.getX(), u, p2D.getY(), v, -originOffset, w); }
Example 20
Source File: Plane.java From astor with GNU General Public License v2.0 | 2 votes |
/** Transform an in-plane point into a 3D space point. * @param point in-plane point (must be a {@link * org.apache.commons.math3.geometry.euclidean.twod.Vector2D Vector2D} instance) * @return 3D space point (really a {@link Vector3D Vector3D} instance) * @see #toSubSpace */ public Vector3D toSpace(final Vector<Euclidean2D> point) { final Vector2D p2D = (Vector2D) point; return new Vector3D(p2D.getX(), u, p2D.getY(), v, -originOffset, w); }