List of usage examples for org.apache.commons.math3.geometry.euclidean.twod Vector2D getX
public double getX()
From source file:org.micromanager.plugins.magellan.surfacesandregions.SurfaceInterpolator.java
private static Point2D.Double[] getPositionCornersWithPadding(XYStagePosition pos, double xyPadding) { if (xyPadding == 0) { return pos.getDisplayedTileCorners(); } else {/*from w w w . j a va 2 s .co m*/ //expand to bigger square to acount for padding //make two lines that criss cross the smaller square Point2D.Double[] corners = pos.getDisplayedTileCorners(); double diagonalLength = new Vector2D(corners[0].x, corners[0].y) .distance(new Vector2D(corners[2].x, corners[2].y)); Vector2D center = new Vector2D(pos.getCenter().x, pos.getCenter().y); Point2D.Double[] paddedCorners = new Point2D.Double[4]; Vector2D c0 = center.add(xyPadding + 0.5 * diagonalLength, new Vector2D(corners[0].x - corners[2].x, corners[0].y - corners[2].y).normalize()); Vector2D c1 = center.add(xyPadding + 0.5 * diagonalLength, new Vector2D(corners[1].x - corners[3].x, corners[1].y - corners[3].y).normalize()); Vector2D c2 = center.add(xyPadding + 0.5 * diagonalLength, new Vector2D(corners[2].x - corners[0].x, corners[2].y - corners[0].y).normalize()); Vector2D c3 = center.add(xyPadding + 0.5 * diagonalLength, new Vector2D(corners[3].x - corners[1].x, corners[3].y - corners[1].y).normalize()); paddedCorners[0] = new Point2D.Double(c0.getX(), c0.getY()); paddedCorners[1] = new Point2D.Double(c1.getX(), c1.getY()); paddedCorners[2] = new Point2D.Double(c2.getX(), c2.getY()); paddedCorners[3] = new Point2D.Double(c3.getX(), c3.getY()); return paddedCorners; } }
From source file:org.orekit.bodies.Ellipse.java
/** Create a point from its ellipse-relative coordinates. * @param p point defined with respect to ellipse * @return point defined with respect to 3D frame * @see #toPlane(Vector3D)/* www . jav a 2 s .c o m*/ */ public Vector3D toSpace(final Vector2D p) { return new Vector3D(1, center, p.getX(), u, p.getY(), v); }
From source file:org.orekit.bodies.Ellipse.java
/** Find the closest ellipse point. * @param p point in the ellipse plane to project on the ellipse itself * @return closest point belonging to 2D meridian ellipse *//* w ww . j a va2s . c o m*/ public Vector2D projectToEllipse(final Vector2D p) { final double x = FastMath.abs(p.getX()); final double y = p.getY(); if (x <= ANGULAR_THRESHOLD * FastMath.abs(y)) { // the point is almost on the minor axis, approximate the ellipse with // the osculating circle whose center is at evolute cusp along minor axis final double osculatingRadius = a2 / b; final double evoluteCuspZ = FastMath.copySign(a * e2 / g, -y); final double deltaZ = y - evoluteCuspZ; final double ratio = osculatingRadius / FastMath.hypot(deltaZ, x); return new Vector2D(FastMath.copySign(ratio * x, p.getX()), evoluteCuspZ + ratio * deltaZ); } if (FastMath.abs(y) <= ANGULAR_THRESHOLD * x) { // the point is almost on the major axis final double osculatingRadius = b2 / a; final double evoluteCuspR = a * e2; final double deltaR = x - evoluteCuspR; if (deltaR >= 0) { // the point is outside of the ellipse evolute, approximate the ellipse // with the osculating circle whose center is at evolute cusp along major axis final double ratio = osculatingRadius / FastMath.hypot(y, deltaR); return new Vector2D(FastMath.copySign(evoluteCuspR + ratio * deltaR, p.getX()), ratio * y); } // the point is on the part of the major axis within ellipse evolute // we can compute the closest ellipse point analytically final double rEllipse = x / e2; return new Vector2D(FastMath.copySign(rEllipse, p.getX()), FastMath.copySign(g * FastMath.sqrt(a2 - rEllipse * rEllipse), y)); } else { final double k = FastMath.hypot(x / a, y / b); double projectedX = x / k; double projectedY = y / k; double deltaX = Double.POSITIVE_INFINITY; double deltaY = Double.POSITIVE_INFINITY; int count = 0; final double threshold = ANGULAR_THRESHOLD * ANGULAR_THRESHOLD * a2; while ((deltaX * deltaX + deltaY * deltaY) > threshold && count++ < 100) { // this loop usually converges in 3 iterations final double omegaX = evoluteFactorX * projectedX * projectedX * projectedX; final double omegaY = evoluteFactorY * projectedY * projectedY * projectedY; final double dx = x - omegaX; final double dy = y - omegaY; final double alpha = b2 * dx * dx + a2 * dy * dy; final double beta = b2 * omegaX * dx + a2 * omegaY * dy; final double gamma = b2 * omegaX * omegaX + a2 * omegaY * omegaY - a2 * b2; final double deltaPrime = MathArrays.linearCombination(beta, beta, -alpha, gamma); final double ratio = (beta <= 0) ? (FastMath.sqrt(deltaPrime) - beta) / alpha : -gamma / (FastMath.sqrt(deltaPrime) + beta); final double previousX = projectedX; final double previousY = projectedY; projectedX = omegaX + ratio * dx; projectedY = omegaY + ratio * dy; deltaX = projectedX - previousX; deltaY = projectedY - previousY; } return new Vector2D(FastMath.copySign(projectedX, p.getX()), projectedY); } }
From source file:org.orekit.bodies.Ellipse.java
/** Project position-velocity-acceleration on an ellipse. * @param pv position-velocity-acceleration to project, in the reference frame * @return projected position-velocity-acceleration *///www. ja v a 2 s. co m public TimeStampedPVCoordinates projectToEllipse(final TimeStampedPVCoordinates pv) { // find the closest point in the meridian plane final Vector2D p2D = toPlane(pv.getPosition()); final Vector2D e2D = projectToEllipse(p2D); // tangent to the ellipse final double fx = -a2 * e2D.getY(); final double fy = b2 * e2D.getX(); final double f2 = fx * fx + fy * fy; final double f = FastMath.sqrt(f2); final Vector2D tangent = new Vector2D(fx / f, fy / f); // normal to the ellipse (towards interior) final Vector2D normal = new Vector2D(-tangent.getY(), tangent.getX()); // center of curvature final double x2 = e2D.getX() * e2D.getX(); final double y2 = e2D.getY() * e2D.getY(); final double eX = evoluteFactorX * x2; final double eY = evoluteFactorY * y2; final double omegaX = eX * e2D.getX(); final double omegaY = eY * e2D.getY(); // velocity projection ratio final double rho = FastMath.hypot(e2D.getX() - omegaX, e2D.getY() - omegaY); final double d = FastMath.hypot(p2D.getX() - omegaX, p2D.getY() - omegaY); final double projectionRatio = rho / d; // tangential velocity final Vector2D pDot2D = new Vector2D(Vector3D.dotProduct(pv.getVelocity(), u), Vector3D.dotProduct(pv.getVelocity(), v)); final double pDotTangent = pDot2D.dotProduct(tangent); final double pDotNormal = pDot2D.dotProduct(normal); final double eDotTangent = projectionRatio * pDotTangent; final Vector2D eDot2D = new Vector2D(eDotTangent, tangent); final Vector2D tangentDot = new Vector2D( a2 * b2 * (e2D.getX() * eDot2D.getY() - e2D.getY() * eDot2D.getX()) / f2, normal); // velocity of the center of curvature in the meridian plane final double omegaXDot = 3 * eX * eDotTangent * tangent.getX(); final double omegaYDot = 3 * eY * eDotTangent * tangent.getY(); // derivative of the projection ratio final double voz = omegaXDot * tangent.getY() - omegaYDot * tangent.getX(); final double vsz = -pDotNormal; final double projectionRatioDot = ((rho - d) * voz - rho * vsz) / (d * d); // acceleration final Vector2D pDotDot2D = new Vector2D(Vector3D.dotProduct(pv.getAcceleration(), u), Vector3D.dotProduct(pv.getAcceleration(), v)); final double pDotDotTangent = pDotDot2D.dotProduct(tangent); final double pDotTangentDot = pDot2D.dotProduct(tangentDot); final double eDotDotTangent = projectionRatio * (pDotDotTangent + pDotTangentDot) + projectionRatioDot * pDotTangent; final Vector2D eDotDot2D = new Vector2D(eDotDotTangent, tangent, eDotTangent, tangentDot); // back to 3D final Vector3D e3D = toSpace(e2D); final Vector3D eDot3D = new Vector3D(eDot2D.getX(), u, eDot2D.getY(), v); final Vector3D eDotDot3D = new Vector3D(eDotDot2D.getX(), u, eDotDot2D.getY(), v); return new TimeStampedPVCoordinates(pv.getDate(), e3D, eDot3D, eDotDot3D); }
From source file:org.orekit.bodies.Ellipse.java
/** Find the center of curvature (point on the evolute) at the nadir of a point. * @param point point in the ellipse plane * @return center of curvature of the ellipse directly at point nadir * @since 7.1/*from w w w. ja v a2 s .c om*/ */ public Vector2D getCenterOfCurvature(final Vector2D point) { final Vector2D projected = projectToEllipse(point); return new Vector2D(evoluteFactorX * projected.getX() * projected.getX() * projected.getX(), evoluteFactorY * projected.getY() * projected.getY() * projected.getY()); }
From source file:org.orekit.bodies.OneAxisEllipsoid.java
/** {@inheritDoc} */ public GeodeticPoint transform(final Vector3D point, final Frame frame, final AbsoluteDate date) throws OrekitException { // transform point to body frame final Vector3D pointInBodyFrame = frame.getTransformTo(bodyFrame, date).transformPosition(point); final double r2 = pointInBodyFrame.getX() * pointInBodyFrame.getX() + pointInBodyFrame.getY() * pointInBodyFrame.getY(); final double r = FastMath.sqrt(r2); final double z = pointInBodyFrame.getZ(); // set up the 2D meridian ellipse final Ellipse meridian = new Ellipse(Vector3D.ZERO, new Vector3D(pointInBodyFrame.getX() / r, pointInBodyFrame.getY() / r, 0), Vector3D.PLUS_K, getA(), getC(), bodyFrame);// w ww. ja va2 s . co m // project point on the 2D meridian ellipse final Vector2D ellipsePoint = meridian.projectToEllipse(new Vector2D(r, z)); // relative position of test point with respect to its ellipse sub-point final double dr = r - ellipsePoint.getX(); final double dz = z - ellipsePoint.getY(); final double insideIfNegative = g2 * (r2 - ae2) + z * z; return new GeodeticPoint(FastMath.atan2(ellipsePoint.getY(), g2 * ellipsePoint.getX()), FastMath.atan2(pointInBodyFrame.getY(), pointInBodyFrame.getX()), FastMath.copySign(FastMath.hypot(dr, dz), insideIfNegative)); }
From source file:org.ratchetrobotics.algorithms.geometry.converter.PointsConverter.java
public PointsConverterDoubleArray toDoubleArrays() { List<Double> x = new ArrayList<>(); List<Double> y = new ArrayList<>(); for (Vector2D point : points) { x.add(point.getX()); y.add(point.getY());//www . jav a 2s. c om } return new PointsConverterDoubleArray(ArrayUtils.toPrimitive(x.toArray(new Double[x.size()])), ArrayUtils.toPrimitive(y.toArray(new Double[y.size()]))); }
From source file:uk.ac.ebi.cysbgn.methods.ArcSegmentationAlgorithm.java
public void calculateAuxPortPosition(List<SegmentationPoint> points, CustomEdgePoint customPoint, Double distance) {/*from w w w . j av a 2s . com*/ // boolean isAnchor = false; // if( points.size() > 2 ) // isAnchor = true; // Get point before last int pointBeforeLastX = (int) points.get(points.size() - 2).getX(); int pointBeforeLastY = (int) points.get(points.size() - 2).getY(); // Get last point int lastPointX = (int) points.get(points.size() - 1).getX(); int lastPointY = (int) points.get(points.size() - 1).getY(); Vector2D portPosition = SegmentMethods.calculateLinePointByDistanceToStart( new Vector2D(lastPointX, lastPointY), new Vector2D(pointBeforeLastX, pointBeforeLastY), distance); // if( isAnchor ){ // Rectangle2D.Double portBoundaries = new Rectangle2D.Double(portPosition.getX(), portPosition.getY(), 3, 3); // // if( portBoundaries.contains(arcLastX, arcLastY) ){ // edgeAnchors.remove( (edgeAnchors.size()-1) ); // // Cytoscape.getEdgeAttributes().setAttribute(edge.getIdentifier(), SBGNAttributes.EDGE_ANCHORS.getName(), CyEdgeAttrUtils.getAnchorAttribute(edgeAnchors)); // // calculateAuxPortPosition(arc, edge, auxPort, distance); // // return; // } // } customPoint.setX((float) portPosition.getX()); customPoint.setY((float) portPosition.getY()); }
From source file:uk.ac.ebi.cysbgn.methods.SegmentMethods.java
public static Vector2D pointOutNodeBoundary(Rectangle2D.Double nodeRectangle, Vector2D start, Vector2D end, double distance) { // C = A - k ( A - B ) // k = distance / distance_From_A_to_B Line arcLine = new Line(start, end); // Calculate the point here the arc intersects the node boundary rectangle Vector2D boundaryPoint = nodeArcIntersectionPoint(nodeRectangle, arcLine); Double k = distance / boundaryPoint.distance(end); Double Xc = boundaryPoint.getX() - k * (boundaryPoint.getX() - end.getX()); Double Xy = boundaryPoint.getY() - k * (boundaryPoint.getY() - end.getY()); return new Vector2D(Xc, Xy); }
From source file:uk.ac.ebi.cysbgn.methods.SegmentMethods.java
public static Vector2D calculateLinePointByDistanceToStart(Vector2D A, Vector2D B, double distance) { // C = A - k ( A - B ) // k = distance / distance_From_A_to_B Double k = distance / A.distance(B); Double Cx = A.getX() - k * (A.getX() - B.getX()); Double Cy = A.getY() - k * (A.getY() - B.getY()); Vector2D C = new Vector2D(Cx, Cy); return C;/*from w ww . jav a 2s . com*/ }