Here you can find the source of angle_between(double x1, double y1, double z1, double x2, double y2, double z2)
Parameter | Description |
---|---|
x1 | x element of the first vector |
y1 | y element of the first vector |
z1 | z element of the first vector |
x2 | x element of the second vector |
y2 | y element of the second vector |
z2 | z element of the second vector |
public static double angle_between(double x1, double y1, double z1, double x2, double y2, double z2)
//package com.java2s; public class Main { /** /*from w w w . j a v a 2s . c o m*/ * Calculate the angle between two vectors in three dimensions. * @param x1 x element of the first vector * @param y1 y element of the first vector * @param z1 z element of the first vector * @param x2 x element of the second vector * @param y2 y element of the second vector * @param z2 z element of the second vector * @return the interior angle, in the range [0, pi) */ public static double angle_between(double x1, double y1, double z1, double x2, double y2, double z2) { double magnitude1 = StrictMath.sqrt((x1 * x1) + (y1 * y1) + (z1 * z1)); double magnitude2 = StrictMath.sqrt((x2 * x2) + (y2 * y2) + (z2 * z2)); double dotProduct = ((x1 * x2) + (y1 * y2) + (z1 * z2)); return (StrictMath.acos(dotProduct / (magnitude1 * magnitude2))); } }