Here you can find the source of angleBetween2LinesVectorAlgebra(double x11, double y11, double x12, double y12, double x21, double y21, double x22, double y22)
public static double angleBetween2LinesVectorAlgebra(double x11, double y11, double x12, double y12, double x21, double y21, double x22, double y22)
//package com.java2s; /*// w w w . j a v a 2s .co m * Beigesoft ? * * Licensed under the Apache License, Version 2.0 * * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 */ public class Main { public static double angleBetween2LinesVectorAlgebra(double x11, double y11, double x12, double y12, double x21, double y21, double x22, double y22) { /* * U(u1,u2) - vector line1 * V(v1,v2) - vector line2 * cosa = abs(u1*v1+u2*v2)/sqrt((u1*u1+u2*u2)*(v1*v1+v2*v2)) */ double[] u = { x12 - x11, y12 - y11 }; double[] v = { x22 - x21, y22 - y21 }; double cosa = Math.abs(u[0] * v[0] + u[1] * v[1]) / Math.sqrt((u[0] * u[0] + u[1] * u[1]) * (v[0] * v[0] + v[1] * v[1])); return Math.acos(cosa); } }