Compute the dot product of two vectors - Android java.lang

Android examples for java.lang:Math Vector

Description

Compute the dot product of two vectors

Demo Code


//package com.java2s;

public class Main {
    /**/*from w ww. j ava  2s .  co  m*/
     * 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(int size, float[] v1, int offsetV1, float[] v2,
            int offsetV2) {
        float res = 0;
        for (int i = 0; i < size; i++)
            res += v1[offsetV1 + i] * v2[offsetV2 + i];
        return res;
    }
}

Related Tutorials