Here you can find the source of angleBetween(double[] v1, double[] v2)
Parameter | Description |
---|---|
v1 | a parameter |
v2 | a parameter |
public static double angleBetween(double[] v1, double[] v2)
//package com.java2s; //License from project: Academic Free License public class Main { /**/*from w ww. j a va 2 s . c o m*/ * Determine the angle of rotation between two vectors. * * @param v1 * @param v2 * @return */ public static double angleBetween(double[] v1, double[] v2) { double m1 = mag(v1); double m2 = mag(v2); double ang = dot(v1, v2) / (m1 * m2); ang = Math.acos(ang); return ang; } /** * Calculates the magnitude of the vector. * * @param v * @return */ public static double mag(double v[]) { return Math.sqrt(dot(v, v)); } /** * Calculates the dot product of two vectors. * * @param v1 * @param v2 * @return */ public static double dot(double v1[], double v2[]) { int size = v1.length; double cp = 0.0; for (int i = 0; i < size; i++) { cp += v1[i] * v2[i]; } return cp; } }