Here you can find the source of distanceSq(double[] p1, double[] p2, double[] weights)
public static double distanceSq(double[] p1, double[] p2, double[] weights)
//package com.java2s; public class Main { public static double distanceSq(double[] p1, double[] p2, double[] weights) { double sum = 0; for (int x = 0; x < p1.length; x++) { double z = (p1[x] - p2[x]) * weights[x]; sum += z * z;//from ww w . j a va 2s . c om } return sum; } }