List of usage examples for java.awt.geom Point2D distance
public double distance(Point2D pt)
From source file:com.net2plan.libraries.GraphUtils.java
/** Computes the Euclidean distance between two points. * /*from ww w . j av a 2s . co m*/ * @param point1 Point 1 * @param point2 Point 2 * @return Euclidean distance between two points */ public static double computeEuclideanDistance(Point2D point1, Point2D point2) { return point1.distance(point2); }
From source file:org.gumtree.vis.awt.JChartPanel.java
private void findSelectedMarker(Point point) { Line2D marker = null;/* w ww . j a va 2s .co m*/ double distance = Double.MAX_VALUE; double cDis; for (Entry<Line2D, Color> entry : domainMarkerMap.entrySet()) { Line2D line = entry.getKey(); Point2D p2 = line.getP2(); double height = p2.getY(); cDis = Double.MAX_VALUE; if (height < 1e-4) { double xScr = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart()).getX(); cDis = Math.abs(point.getX() - xScr); } else { Point2D newP2 = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart()); if (newP2.getY() < point.getY()) { cDis = Math.abs(point.getX() - newP2.getX()); } else { cDis = newP2.distance(point); } } if (cDis <= distance) { distance = cDis; marker = line; } } for (Entry<Line2D, Color> entry : rangeMarkerMap.entrySet()) { Line2D line = entry.getKey(); Point2D p1 = line.getP1(); Point2D p2 = line.getP2(); double width = p2.getX(); cDis = Double.MAX_VALUE; if (width < 1e-4) { double yScr = ChartMaskingUtilities.translateChartPoint(p1, getScreenDataArea(), getChart()).getY(); cDis = Math.abs(point.getY() - yScr); } else { Point2D newP2 = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart()); if (newP2.getX() > point.getX()) { cDis = Math.abs(point.getY() - newP2.getY()); } else { cDis = newP2.distance(point); } } if (cDis <= distance) { distance = cDis; marker = line; } } for (Entry<Line2D, Color> entry : markerMap.entrySet()) { Line2D line = entry.getKey(); Point2D p1 = line.getP1(); p1 = ChartMaskingUtilities.translateChartPoint(p1, getScreenDataArea(), getChart()); cDis = p1.distance(point); if (cDis <= distance) { distance = cDis; marker = line; } } if (distance < 5) { selectedMarker = marker; } else { selectedMarker = null; } }
From source file:Distortions.java
public void showWithRadialTangential(String[] preTitles, String title, double[][] preData, // [0] - dx, [1] - dy int width, int deciamte, double x0, double y0) { int indexDx = 0; int indexDy = 1; int indexDr = 0; int indexDt = 1; int indexDa = 2; String[] extraTitles = { "R-corr(pix)", "T-corr{pix)", "A-corr(pix)" }; int newImages = extraTitles.length; int length = preData[0].length; int height = length / width; double[][] data = new double[preData.length + newImages][length]; String[] titles = new String[preTitles.length + newImages]; for (int i = 0; i < preData.length; i++) { data[i + newImages] = preData[i]; titles[i + newImages] = preTitles[i]; }// w ww . j ava 2 s. co m for (int i = 0; i < newImages; i++) { titles[i] = extraTitles[i]; data[i] = new double[length]; } Point2D Z = new Point2D.Double(0.0, 0.0); for (int i = 0; i < length; i++) { Point2D R = new Point2D.Double((deciamte * (i % width)) - x0, (deciamte * (i / width)) - y0); double r = R.distance(Z); Point2D uR = new Point2D.Double(1.0, 0.0); if (r > 0) uR.setLocation(R.getX() / r, R.getY() / r); Point2D dXY = new Point2D.Double(preData[indexDx][i], preData[indexDy][i]); data[indexDr][i] = dXY.getX() * uR.getX() + dXY.getY() * uR.getY(); data[indexDt][i] = -dXY.getX() * uR.getY() + dXY.getY() * uR.getX(); data[indexDa][i] = dXY.distance(Z); } this.SDFA_INSTANCE.showArrays(data, width, height, true, title, titles); }