Compute the dot product of two vectors : Vector « Game « Android






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

}

   
  








Related examples in the same category

1.Wrapper activity demonstrating the use of the new SensorEvent rotation vector sensor, Sensor#TYPE_ROTATION_VECTOR TYPE_ROTATION_VECTOR}).
2.Vector2d structure
3.Vector2 Structure
4.Convenience library to do vector calculations
5.Vector3
6.Bit Vector
7.Compute the cross product of two vectors
8.Compute the magnitude (length) of a vector
9.Vector3 structure