Here you can find the source of dotProduct(float[] p, int a, int b, int c)
public static double dotProduct(float[] p, int a, int b, int c)
//package com.java2s; /*/* ww w. j a va2 s . co m*/ * Copyright 2012, 2013 Hannes Janetzek * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * * This program is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { public static double dotProduct(float[] p, int a, int b, int c) { double ux = (p[b] - p[a]); double uy = (p[b + 1] - p[a + 1]); double ab = Math.sqrt(ux * ux + uy * uy); double vx = (p[b] - p[c]); double vy = (p[b + 1] - p[c + 1]); double bc = Math.sqrt(vx * vx + vy * vy); double d = ab * bc; if (d <= 0) return 0; double dotp = (ux * -vx + uy * -vy) / d; if (dotp > 1) dotp = 1; else if (dotp < -1) dotp = -1; return dotp; } }