Java Array Dot Product dotProduct(float[] p, int a, int b, int c)

Here you can find the source of dotProduct(float[] p, int a, int b, int c)

Description

dot Product

License

Open Source License

Declaration

public static double dotProduct(float[] p, int a, int b, int c) 

Method Source Code

//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;
    }
}

Related

  1. dotProduct(double[] x, double[] y)
  2. dotProduct(final double[] a, final double[] b)
  3. dotProduct(final double[] anArray, final double[] anotherArray)
  4. dotProduct(final double[] v1, final double[] v2, int n)
  5. dotProduct(float x1, float y1, float x2, float y2)
  6. dotProduct(float[] v1, float[] v2)
  7. dotProduct(float[] vector1, float[] vector2)
  8. dotProduct(int[] xs, int[] ys)