private double distanceTo(Actor opponent) { double actorToMoveX = opponent.getAvatar().getTranslateX(); double actorToMoveY = opponent.getAvatar().getTranslateY(); double currentX = getAvatar().getTranslateX(); double currentY = getAvatar().getTranslateY(); double deltaX = actorToMoveX - currentX; double deltaY = actorToMoveY - currentY; double calculatedDistance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); return calculatedDistance; }
private double euclideanDistance(Features point, Centroid centroid) { if (point.getNumberOfDim() != centroid.getNumberOfDim()) throw new IllegalArgumentException(); double sumOfSquares = 0; for (int i = 0; i < point.getNumberOfDim(); i++) { sumOfSquares += (point.getDim(i) - centroid.getDim(i)) * (point.getDim(i) - centroid.getDim(i)); } return Math.sqrt(sumOfSquares); }