for (Point g : points) { if (g.x != pp.x || g.y != pp.y) { if (pp.distance(g) <= range) { keep = false; break;
public static Shape createArrowShape(Point fromPt, Point toPt) { Polygon arrowPolygon = new Polygon(); arrowPolygon.addPoint(-6,1); arrowPolygon.addPoint(3,1); arrowPolygon.addPoint(3,3); arrowPolygon.addPoint(6,0); arrowPolygon.addPoint(3,-3); arrowPolygon.addPoint(3,-1); arrowPolygon.addPoint(-6,-1); Point midPoint = midpoint(fromPt, toPt); double rotate = Math.atan2(toPt.y - fromPt.y, toPt.x - fromPt.x); AffineTransform transform = new AffineTransform(); transform.translate(midPoint.x, midPoint.y); double ptDistance = fromPt.distance(toPt); double scale = ptDistance / 12.0; // 12 because it's the length of the arrow polygon. transform.scale(scale, scale); transform.rotate(rotate); return transform.createTransformedShape(arrowPolygon); } private static Point midpoint(Point p1, Point p2) { return new Point((int)((p1.x + p2.x)/2.0), (int)((p1.y + p2.y)/2.0)); }
@Override public void mouseDragged(MouseEvent e) { Point tabPt = e.getPoint(); // e.getDragOrigin(); if (Objects.nonNull(this.startPt) && this.startPt.distance(tabPt) > this.gestureMotionThreshold) { DnDTabbedPane src = (DnDTabbedPane) e.getComponent(); TransferHandler th = src.getTransferHandler(); DnDTabbedPane.this.dragTabIndex = src.indexAtLocation(tabPt.x, tabPt.y); th.exportAsDrag(src, e, TransferHandler.MOVE); RECT_LINE.setBounds(0, 0, 0, 0); src.getRootPane().getGlassPane().setVisible(true); src.setDropLocation(new DropLocation(tabPt, -1), null, true); this.startPt = null; } }
Coordinate coord = coords[i]; java.awt.Point p = worldToPixel(coord, worldToScreenTransform); averageDistance += p.distance(oldP) / i; oldP = p;
Point pt = evt.getPoint(); double distance = pt.distance(button); int someLength = 100; // the distance away from the button the point has to be to decide the length of the delay if (distance < someLength) { tim.setDelay(500); } else { tim.setDelay(100); }
private boolean removeControlPoint(Point point, ArrayList<Point> list, double deleteSensitivity){ for (Point elem : list) { if (elem.distance (point) < deleteSensitivity) { list.remove (elem); return true; } } return false; }
private boolean removeControlPoint(Point point, ArrayList<Point> list, double deleteSensitivity){ for (Point elem : list) { if(elem.distance(point)<deleteSensitivity){ list.remove(elem); return true; } } return false; }
private boolean removeControlPoint(Point point, ArrayList<Point> list, double deleteSensitivity){ for (Point elem : list) { if(elem.distance(point)<deleteSensitivity){ list.remove(elem); return true; } } return false; }
protected boolean activeDrag(MouseEvent e, Point first) { Point p = e.getPoint(); double d = first.distance(p); return d > distanceActiveDrag; }
private boolean removeControlPoint(Point point, ArrayList<Point> list, double deleteSensitivity){ for (Point elem : list) { if (elem.distance (point) < deleteSensitivity) { list.remove (elem); return true; } } return false; }
Point vertex1 = new Point(x1cord, y1cord); Point vertex2 = new Point(x2cord, y2cord); Point vertex3 = new Point(x3cord, y3cord); double side1 = Math.abs(vertex1.distance(vertex2)); double side2 = Math.abs(vertex2.distance(vertex3)); double side3 = Math.abs(vertex3.distance(vertex1)); boolean valid = side1 + side2 > side3 && side2 + side3 > side1 && side3 + side1 > side2; if (!valid) { System.out.println("The entered coordinates do not form a triangle"); }
public static void main (String[] args) throws java.lang.Exception { Point A1 = new Point(0,3); Point A2 = new Point(2,0); Point B = new Point(0,0); System.out.println( B.distance(A1,A2) ); }
public double calcAverageDistanceToPoint(@Nonnull final Point point) { final double d1 = point.distance(this.bounds.getX(), this.bounds.getY()); final double d2 = point.distance(this.bounds.getMaxX(), this.bounds.getY()); final double d3 = point.distance(this.bounds.getX(), this.bounds.getMaxY()); final double d4 = point.distance(this.bounds.getMaxX(), this.bounds.getMaxY()); return (d1 + d2 + d3 + d4) / (this.bounds.contains(point) ? 8.0d : 4.0d); }
protected static void paintLine(Point point1, Point point2, Graphics2D g) { int d = 100; int dist = (int) point1.distance(point2); if (dist < d) { d = dist; } CubicCurve2D line = new CubicCurve2D.Double(point1.x, point1.y, point1.x + d, point1.y, point2.x - d, point2.y, point2.x, point2.y); g.draw(line); }
for(Point point : mPoints){ float distance = point.distance(x,y); if(distance > mTouchRange) continue; float force = (float) Math.pow(1 - (distance / mTouchRange), 2) * mForceFactor; float angle = point.angle(x,y); point.dx -= Math.cos(angle) * force; point.dy -= Math.sin(angle) * force; point.isMoving = true; }
private boolean passedDragThreshold(MouseEvent evt) { double distance = dragOrigin.distance(evt.getPoint()); float threshold = dockable.getDockingProperties().getDragThreshold().floatValue(); return distance > threshold; }
@Override public Double evaluate(Transition<Void, Point> transition) { Point source = transition.getFromState(); Point destination = transition.getState(); double distance = source.distance(destination); double roundedDistance = (double) Math.round(distance * 1e5) / 1e5; return roundedDistance; } })