List of usage examples for java.awt.geom Point2D.Double distance
public double distance(Point2D pt)
From source file:Main.java
public static double fromSheetDistance(double d, AffineTransform at) { Point2D.Double pSheet1 = new Point2D.Double(0, 0); Point2D.Double pSheet2 = new Point2D.Double(1, 0); Point2D.Double pScreen1 = new Point2D.Double(); Point2D.Double pScreen2 = new Point2D.Double(); try {//from ww w . j a v a 2s .com at.transform(pSheet1, pScreen1); at.transform(pSheet2, pScreen2); } catch (Exception e) { System.err.print(e.getMessage()); } return pScreen1.distance(pScreen2) * d; }
From source file:MathFunctions.java
public static void runAffineTest() { Map<Point2D.Double, Point2D.Double> pointPairs = new HashMap<Point2D.Double, Point2D.Double>(); // Create sample src and dest points: pointPairs.put(new Point2D.Double(1, 1), new Point2D.Double(18, 2)); pointPairs.put(new Point2D.Double(1, 9), new Point2D.Double(2, 2)); pointPairs.put(new Point2D.Double(9, 9), new Point2D.Double(2, 18)); pointPairs.put(new Point2D.Double(9, 1), new Point2D.Double(18, 18)); // Run the computation to be tested: AffineTransform affineTransform = generateAffineTransformFromPointPairs(pointPairs); // Print input and output: System.out.println(pointPairs); System.out.println(affineTransform); int i = 0;//from w ww . j a va 2s .co m // Check that affineTransform works correctly: for (Map.Entry pair : pointPairs.entrySet()) { Point2D.Double uPt = (Point2D.Double) pair.getKey(); Point2D.Double vPt = (Point2D.Double) pair.getValue(); Point2D.Double result = new Point2D.Double(); affineTransform.transform(uPt, result); System.out.println(uPt + "->" + result + " residual: " + vPt.distance(result)); i++; } }
From source file:Main.java
public static Rectangle2D.Double toSheetRect(Rectangle2D r, AffineTransform at) { Point2D.Double pSheet = toSheetPoint(new Point2D.Double(r.getX(), r.getY()), at); Point2D.Double pSheetX = toSheetPoint(new Point2D.Double(r.getMaxX(), r.getMinY()), at); Point2D.Double pSheetY = toSheetPoint(new Point2D.Double(r.getMinX(), r.getMaxY()), at); Rectangle2D.Double res = new Rectangle2D.Double(); res.setRect(pSheet.getX(), pSheet.getY(), pSheet.distance(pSheetX), pSheet.distance(pSheetY)); return res;//from www. j a v a 2 s . co m }
From source file:Main.java
public static Rectangle2D.Double fromSheetRect(Rectangle2D r, AffineTransform at) { Point2D.Double pSheet = new Point2D.Double(r.getX(), r.getY()); Point2D.Double pSX = new Point2D.Double(r.getMaxX(), r.getMinY()); Point2D.Double pSY = new Point2D.Double(r.getMinX(), r.getMaxY()); Point2D.Double pScreen = new Point2D.Double(); Point2D.Double pScreenX = new Point2D.Double(); Point2D.Double pScreenY = new Point2D.Double(); try {//from w ww . j ava2 s . com at.transform(pSheet, pScreen); at.transform(pSX, pScreenX); at.transform(pSY, pScreenY); } catch (Exception e) { System.err.print(e.getMessage()); } Rectangle2D.Double res = new Rectangle2D.Double(); res.setRect(pScreen.getX(), pScreen.getY(), pScreen.distance(pScreenX), pScreen.distance(pScreenY)); return res; }
From source file:edu.valelab.GaussianFit.CoordinateMapper.java
public static Point2D.Double computeTransformation(EnhancedKDTree kdTree, Point2D.Double testPoint, ControlPoints controlPoints, ExponentPairs exponentPairs) { final List<Point2D.Double> neighbors = kdTree.nearestNeighbor(testPoint, 20, false); double sumWeights = 0; double sumWeightedPolyX = 0; double sumWeightedPolyY = 0; for (Point2D.Double srcPoint : neighbors) { final ControlPoint controlPoint = controlPoints.get(srcPoint); final double r = testPoint.distance(controlPoint.point) / controlPoint.Rnormalized; final double weight = weightFunction(r); if (weight > 0) { sumWeights += weight;//from ww w . jav a2 s .c o m sumWeightedPolyX += weight * evaluatePolynomial(testPoint.x, testPoint.y, controlPoint.polynomialCoefficients.polyX, exponentPairs); sumWeightedPolyY += weight * evaluatePolynomial(testPoint.x, testPoint.y, controlPoint.polynomialCoefficients.polyY, exponentPairs); } } return new Point2D.Double(sumWeightedPolyX / sumWeights, sumWeightedPolyY / sumWeights); }
From source file:ChartUsingJava.XYSmoothLineAndShapeRenderer.java
/** * Updates the control points./*from w ww. j a v a2 s. co m*/ * * @param point0 * @param point1 * @param point2 * @param point3 * @param control1 * @param control2 * @param smooth */ public static void getControlPoints(Point2D.Double point0, Point2D.Double point1, Point2D.Double point2, Point2D.Double point3, Point2D.Double control1, Point2D.Double control2, double smooth) { // Reference: http://www.antigrain.com/research/bezier_interpolation/ if (point0 == null) point0 = point1; //new Point2D.Double(0, 0); if (point3 == null) point3 = point2; //new Point2D.Double(0, 0); Point2D.Double c1 = new Point2D.Double((point0.x + point1.x) / 2.0, (point0.y + point1.y) / 2.0); Point2D.Double c2 = new Point2D.Double((point1.x + point2.x) / 2.0, (point1.y + point2.y) / 2.0); Point2D.Double c3 = new Point2D.Double((point2.x + point3.x) / 2.0, (point2.y + point3.y) / 2.0); double len1 = point1.distance(point0); double len2 = point2.distance(point1); double len3 = point3.distance(point2); double k1 = len1 / (len1 + len2); double k2 = len2 / (len2 + len3); Point2D.Double m1 = new Point2D.Double(c1.x + (c2.x - c1.x) * k1, c1.y + (c2.y - c1.y) * k1); Point2D.Double m2 = new Point2D.Double(c2.x + (c3.x - c2.x) * k2, c2.y + (c3.y - c2.y) * k2); control1.setLocation(new Point2D.Double(m1.x + (c2.x - m1.x) * smooth + point1.x - m1.x, m1.y + (c2.y - m1.y) * smooth + point1.y - m1.y)); control2.setLocation(new Point2D.Double(m2.x + (c2.x - m2.x) * smooth + point2.x - m2.x, m2.y + (c2.y - m2.y) * smooth + point2.y - m2.y)); }
From source file:org.jfree.experimental.chart.renderer.xy.XYSmoothLineAndShapeRenderer.java
/** * Updates the control points.//w ww . j a va 2 s. c o m * * @param point0 * @param point1 * @param point2 * @param point3 * @param control1 * @param control2 * @param smooth */ public static void getControlPoints(Point2D.Double point0, Point2D.Double point1, Point2D.Double point2, Point2D.Double point3, Point2D.Double control1, Point2D.Double control2, double smooth) { // Reference: http://www.antigrain.com/research/bezier_interpolation/ if (point0 == null) { point0 = point1; } //new Point2D.Double(0, 0); if (point3 == null) { point3 = point2; } //new Point2D.Double(0, 0); Point2D.Double c1 = new Point2D.Double((point0.x + point1.x) / 2.0, (point0.y + point1.y) / 2.0); Point2D.Double c2 = new Point2D.Double((point1.x + point2.x) / 2.0, (point1.y + point2.y) / 2.0); Point2D.Double c3 = new Point2D.Double((point2.x + point3.x) / 2.0, (point2.y + point3.y) / 2.0); double len1 = point1.distance(point0); double len2 = point2.distance(point1); double len3 = point3.distance(point2); double k1 = len1 / (len1 + len2); double k2 = len2 / (len2 + len3); Point2D.Double m1 = new Point2D.Double(c1.x + (c2.x - c1.x) * k1, c1.y + (c2.y - c1.y) * k1); Point2D.Double m2 = new Point2D.Double(c2.x + (c3.x - c2.x) * k2, c2.y + (c3.y - c2.y) * k2); control1.setLocation(new Point2D.Double(m1.x + (c2.x - m1.x) * smooth + point1.x - m1.x, m1.y + (c2.y - m1.y) * smooth + point1.y - m1.y)); control2.setLocation(new Point2D.Double(m2.x + (c2.x - m2.x) * smooth + point2.x - m2.x, m2.y + (c2.y - m2.y) * smooth + point2.y - m2.y)); }
From source file:edu.valelab.gaussianfit.datasettransformations.CoordinateMapper.java
/** * Computes the transform of Ch1 into Ch2 coordinates using the LWM * @param kdTree// w ww . j ava 2s . c o m * @param testPoint * @param controlPoints * @param exponentPairs * @return */ public static Point2D.Double computeTransformation(EnhancedKDTree kdTree, Point2D.Double testPoint, ControlPoints controlPoints, ExponentPairs exponentPairs) { final List<Point2D.Double> neighbors = kdTree.nearestNeighbor(testPoint, 20, false); double sumWeights = 0; double sumWeightedPolyX = 0; double sumWeightedPolyY = 0; int count = 0; for (Point2D.Double srcPoint : neighbors) { final ControlPoint controlPoint = controlPoints.get(srcPoint); final double r = testPoint.distance(controlPoint.point) / controlPoint.Rnormalized; final double weight = weightFunction(r); if (weight > 0) { count++; sumWeights += weight; sumWeightedPolyX += weight * evaluatePolynomial(testPoint.x, testPoint.y, controlPoint.polynomialCoefficients.polyX, exponentPairs); sumWeightedPolyY += weight * evaluatePolynomial(testPoint.x, testPoint.y, controlPoint.polynomialCoefficients.polyY, exponentPairs); } } System.out.println("Used " + count + " controlpoints in computeTransform"); return new Point2D.Double(sumWeightedPolyX / sumWeights, sumWeightedPolyY / sumWeights); }
From source file:de.biomedical_imaging.traJ.features.SplineCurveSpatialFeature.java
@Override /**// www .j a v a 2s . co m * @return [0] Mean distance [1] SD distance */ public double[] evaluate() { splinefit = new TrajectorySplineFit(t, nSegments); splinefit.calculateSpline(); if (!splinefit.wasSuccessfull()) { return new double[] { Double.NaN, Double.NaN }; } double[] data = new double[t.size()]; for (int i = 0; i < t.size(); i++) { Point2D.Double help = new Point2D.Double(splinefit.getRotatedTrajectory().get(i).x, splinefit.getRotatedTrajectory().get(i).y); data[i] = help.distance(splinefit.minDistancePointSpline(new Point2D.Double( splinefit.getRotatedTrajectory().get(i).x, splinefit.getRotatedTrajectory().get(i).y), 50)); } Mean m = new Mean(); StandardDeviation sd = new StandardDeviation(); result = new double[] { m.evaluate(data), sd.evaluate(data) }; return result; }
From source file:Polygon2D.java
public Polygon2D getPolygon2D() { Polygon2D pol = new Polygon2D(); for (int i = 0; i < npoints - 1; i++) { pol.addPoint(xpoints[i], ypoints[i]); }/*from ww w .jav a2 s .c o m*/ Point2D.Double p0 = new Point2D.Double(xpoints[0], ypoints[0]); Point2D.Double p1 = new Point2D.Double(xpoints[npoints - 1], ypoints[npoints - 1]); if (p0.distance(p1) > ASSUME_ZERO) pol.addPoint(xpoints[npoints - 1], ypoints[npoints - 1]); return pol; }