public static double distanceToLine(Line2D l, Point2D p) { return l.ptLineDist(p); }
Line2D line = new Line2D.Double(x0, y0, x1, y1); double distance = line.ptLineDist(px, py); if (Math.abs(distance) < threshold) { // is Near line }
Polygon p; //your polygon int x_mouse;//your mouse click pos int y_mouse; for (int i = 0; i < p.npoints; i ++){ int x_from = 0; int y_from = 0; int x_to = 0; int y_to = 0; if (i == 0){ //i-1 == -1 -> p.npoints-1 x_from = p.xpoints[p.npoints-1]; y_from = p.ypoints[p.npoints-1]; }else{ x_from = p.xpoints[i-1]; y_from = p.ypoints[i-1]; } x_to = p.xpoints[i]; y_to = p.ypoints[i]; Line2D line = new Line2D.Double(x_from, y_from, x_to, y_to); if (line.ptLineDist(new Point(x_mouse, y_mouse)) <= 0.01){ //you hit } }
Line2D a = new Line2D.Double(); Line2D b = new Line2D.Double(); Line2D c = new Line2D.Double(); a.setLine(x1, y1, x2, y2); b.setLine(x2, y2, x3, y3); c.setLine(x3, y3, x1, y1); double pntX = s.nextDouble(); double pntY = s.nextDouble(); if (a.ptLineDist(pntX, pntY) == 0 || b.ptLineDist(pntX, pntY) == 0 || c.ptLineDist(pntX, pntY) == 0) c++;
/** * Adds or removes a control point on a specified location * @param localLocation the local location */ public void addRemoveControlPoint (Point localLocation) { ArrayList<Point> list = new ArrayList<Point> (getControlPoints()); if(!removeControlPoint(localLocation,list,deleteSensitivity)){ Point exPoint=null;int index=0; for (Point elem : list) { if(exPoint!=null){ Line2D l2d=new Line2D.Double(exPoint,elem); if(l2d.ptLineDist(localLocation)<createSensitivity){ list.add(index,localLocation); break; } } exPoint=elem;index++; } } setControlPoints(list,false); }
/** * Adds or removes a control point on a specified location * @param localLocation the local location */ public void addRemoveControlPoint (Point localLocation) { ArrayList<Point> list = new ArrayList<Point> (getControlPoints()); if(!removeControlPoint(localLocation,list,deleteSensitivity)){ Point exPoint=null;int index=0; for (Point elem : list) { if(exPoint!=null){ Line2D l2d=new Line2D.Double(exPoint,elem); if(l2d.ptLineDist(localLocation)<createSensitivity){ list.add(index,localLocation); break; } } exPoint=elem;index++; } } setControlPoints(list,false); }
/** * Adds or removes a control point on a specified location * @param widget the connection widget * @param localLocation the local location */ private void addRemoveControlPoint (ConnectionWidget widget, Point localLocation) { ArrayList<Point> list = new ArrayList<Point> (widget.getControlPoints ()); if (!removeControlPoint (localLocation, list, deleteSensitivity)) { Point exPoint = null; int index = 0; for (Point elem : list) { if (exPoint != null) { Line2D l2d = new Line2D.Double (exPoint, elem); if (l2d.ptLineDist (localLocation) < createSensitivity) { list.add (index, localLocation); break; } } exPoint = elem; index++; } } if (routingPolicy != null) widget.setRoutingPolicy (routingPolicy); widget.setControlPoints (list, false); }
double dist = theory.ptLineDist(seedCenter);
|| (otherMedian.ptLineDist(endPt) > params.maxBeamsGapY)) { it.remove();
double yDistance = Line2D.ptLineDist(pt2.getX(), pt2.getY(), pt.getX(), pt.getY(), p.getX(), p.getY()); int direction = Line2D.relativeCCW(pt2.getX(), pt2.getY(), pt.getX(), pt.getY(), p.getX(), p.getY());
double height = Line2D.ptLineDist(p0.x, p0.y, p2.x, p2.y, p1.x, p1.y);
double dist = targetLine.ptLineDist(center);
double yDistance = Line2D.ptLineDist(p0.getX(), p0.getY(), pe.getX(), pe.getY(), x, y); int direction = Line2D.relativeCCW(p0.getX(), p0.getY(),
double yDistance = Line2D.ptLineDist(p0.getX(), p0.getY(), pe.getX(), pe.getY(), x, y); int direction = Line2D.relativeCCW(p0.getX(), p0.getY(),
/** * Tests {@link Line#isoscelesTriangleBase}. */ @Test public void testIsoscelesTriangleBase() { final Line test = new Line(); test.setFromPoints(20,30, 80,95); final double slope = 1.083333333333333333333333; final double offset = 8.333333333333333333333333; assertEquals("slope", slope, test.slope(), EPS); assertEquals("y0", offset, test.y0(), EPS); assertEquals("x0", -offset/slope, test.x0(), EPS); final double distance = 40; final Point2D summit = new Point2D.Double(27, -9); // An arbitrary point. final Line2D base = test.isoscelesTriangleBase(summit, distance); assertEquals("distance P1", distance, base.getP1().distance(summit), EPS); assertEquals("distance P2", distance, base.getP2().distance(summit), EPS); final double x = 10; // Can be any arbitrary point. final double y = 8; assertEquals("nearest colinear point", base.ptLineDist(x,y), test.nearestColinearPoint(new Point2D.Double(x,y)).distance(x,y), EPS); } }