Here you can find the source of distance(double[] x, int p, int q, int dim)
Parameter | Description |
---|---|
x | array of coordinates |
p | number of the first point |
q | number of the second point |
dim | dimension of the points |
public static double distance(double[] x, int p, int q, int dim)
//package com.java2s; /*// w w w . j a v a 2 s . co m * Copyright (C) 2013-14 Susanne Westphal * CONRAD is developed as an Open Source project under the GNU General Public License (GPL). */ public class Main { /** * computes the euclidean distance of two dim-dimensional points * * @param x * array of coordinates * @param p * number of the first point * @param q * number of the second point * @param dim * dimension of the points * @return the euclidean distance of the two points */ public static double distance(double[] x, int p, int q, int dim) { double sum = 0.0; for (int i = 0; i < dim; ++i) { sum += Math.pow(x[p * dim + i] - x[q * dim + i], 2); } return Math.sqrt(sum); } }