Here you can find the source of dotProduct(double x1, double y1, double x2, double y2, double x3, double y3)
public static double dotProduct(double x1, double y1, double x2, double y2, double x3, double y3)
//package com.java2s; public class Main { /**//from w w w.j a v a 2s . c o m * Return the dot product of the vector (x1, y1)(x2, y2) * and the vector (x2, y2)(x3, y3). */ public static double dotProduct(double x1, double y1, double x2, double y2, double x3, double y3) { double nVx1 = x2 - x1; double nVy1 = y2 - y1; double nVx2 = x3 - x2; double nVy2 = y3 - y2; double nVMag1 = Math.sqrt(nVx1 * nVx1 + nVy1 * nVy1); double nVMag2 = Math.sqrt(nVx2 * nVx2 + nVy2 * nVy2); if ((nVMag1 == 0) || (nVMag2 == 0)) { return 1; // 0 angle } else { double dot = (nVx1 / nVMag1) * (nVx2 / nVMag2) + (nVy1 / nVMag1) * (nVy2 / nVMag2); return dot; } } /** * Return the dot product of the vector (p1xh, p1yh)(p1xt, p1yt) * and the vector (p2xh,p2yh)(p2xt, p2yt) * h = head, t = tail, tail-------->head */ public static double dotProduct(double p1xh, double p1yh, double p1xt, double p1yt, double p2xh, double p2yh, double p2xt, double p2yt) { double vec_fx = p1xh - p1xt; double vec_fy = p1yh - p1yt; double vec_bx = p2xh - p2xt; double vec_by = p2yh - p2yt; double vec_f_mag = Math.sqrt(Math.pow(vec_fx, 2) + Math.pow(vec_fy, 2)); double vec_b_mag = Math.sqrt(Math.pow(vec_bx, 2) + Math.pow(vec_by, 2)); double dot = (vec_fx * vec_bx + vec_fy * vec_by) / (vec_f_mag * vec_b_mag); return dot; } }