Java Angle angle(double[] vec1, double[] vec2)

Here you can find the source of angle(double[] vec1, double[] vec2)

Description

angle

License

Apache License

Declaration

public static double angle(double[] vec1, double[] vec2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static double angle(double[] vec1, double[] vec2) {
        double small, undefined, magv1, magv2, temp;
        small = 0.00000001;// w w  w.j  a v  a  2s  .c o m
        undefined = 999999.1;

        magv1 = mag(vec1);
        magv2 = mag(vec2);

        if (magv1 * magv2 > small * small) {
            temp = dot(vec1, vec2) / (magv1 * magv2);
            if (Math.abs(temp) > 1.0) {
                temp = Math.signum(temp) * 1.0;
            }
            return Math.acos(temp);
        } else {
            return undefined;
        }
    }

    public static double mag(double[] x) {
        return Math.sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
    }

    public static double dot(double[] x, double[] y) {
        return (x[0] * y[0] + x[1] * y[1] + x[2] * y[2]);
    }
}

Related

  1. angle(double aX, double aY, double bX, double bY)
  2. angle(double px, double py, double qx, double qy)
  3. angle(double x1, double y1, double x2, double y2)
  4. angle(double x1, double y1, double x2, double y2)
  5. angle(double x1, double y1, double x2, double y2)
  6. angle(float x, float y, float x1, float y1)
  7. angle(float x1, float y1, float x2, float y2)
  8. angle2degree(double angle)
  9. angle2pixels(double angle)