Mega Code Archive

 
Categories / Android / Game
 

Compute the dot product of two vectors

class Main {   /**    * Compute the dot product of two vectors    *     * @param v1    *            The first vector    * @param v2    *            The second vector    * @return v1 dot v2    **/   public static float dot(float[] v1, float[] v2) {     float res = 0;     for (int i = 0; i < v1.length; i++)       res += v1[i] * v2[i];     return res;   } }