Here you can find the source of distance3d(double x1, double y1, double z1, double x2, double y2, double z2)
public static double distance3d(double x1, double y1, double z1, double x2, double y2, double z2)
//package com.java2s; public class Main { public static double distance3d(double x1, double y1, double z1, double x2, double y2, double z2) { double dx = Math.abs(x2 - x1); double dy = Math.abs(y2 - y1); double dz = Math.abs(z2 - z1); double max = Math.max(dx, dy); max = Math.max(max, dz);/*from www . jav a 2 s. c o m*/ if (max == 0) return 0; dx /= max; dy /= max; dz /= max; return max * Math.sqrt(dx * dx + dy * dy + dz * dz); } }