Java Angle Between angle_between(double x1, double y1, double z1, double x2, double y2, double z2)

Here you can find the source of angle_between(double x1, double y1, double z1, double x2, double y2, double z2)

Description

Calculate the angle between two vectors in three dimensions.

License

Open Source License

Parameter

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

Return

the interior angle, in the range [0, pi)

Declaration

public static double angle_between(double x1, double y1, double z1, double x2, double y2, double z2) 

Method Source Code

//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)));
    }
}

Related

  1. angle2DBetween(double[] coord1, double[] coord2)
  2. angleBetween(double[] v1, double[] v2)
  3. angleBetween(final double ax, final double ay, final double bx, final double by)
  4. angleBetween2Lines(double l1x1, double l1y1, double l1x2, double l1y2, double l2x1, double l2y1, double l2x2, double l2y2)
  5. angleBetween2LinesVectorAlgebra(double x11, double y11, double x12, double y12, double x21, double y21, double x22, double y22)