public List<Vector3D> kmeansSample(List<Vector3D> data, int k){
        List<Vector3D> result = new ArrayList<Vector3D>();
        points = new double[data.size()][3];
        for (int i = 0; i < data.size(); i++) {
            Vector3D instance = data.get(i);
            points[i][0] = instance.getX(); 
            points[i][1] = instance.getY();
            points[i][2] = instance.getZ();
        }
        
        if(init) {
            init = false;
            iter = 124;
            centroids = new double[k][3];
            for (int i = 0; i < k; i++) {
                int rand = (int) Math.floor(points.length * Math.random());
                centroids[i] = points[rand];
            }
        } else {
            iter = 1;
            
        }
        prevCentroids = centroids.clone();
        
        EKmeans eKmeans = new EKmeans(centroids, points);
        eKmeans.setEqual(true);
        eKmeans.setIteration(iter);
        eKmeans.run();
        double[][] dists = calcDistances(prevCentroids, centroids, k);
            int[] pairs = findClosestPairs(dists);
            for (int i = 0; i < pairs.length; i++) {
                centroids[pairs[i]][0] += prevCentroids[i][0];
                centroids[pairs[i]][0] /= 2;
                centroids[pairs[i]][1] += prevCentroids[i][1];
                centroids[pairs[i]][1] /= 2;
                centroids[pairs[i]][2] += prevCentroids[i][2];
                centroids[pairs[i]][2] /= 2;
            }
        for (int i = 0; i < k; i++) {
            result.add(new Vector3D(centroids[i][0], centroids[i][1], centroids[i][2]));
        }
        return result;
    }