Java Vector Cross Product crossVec3(final float[] result, final float[] v1, final float[] v2)

Here you can find the source of crossVec3(final float[] result, final float[] v1, final float[] v2)

Description

cross product vec1 x vec2

License

Open Source License

Parameter

Parameter Description
v1 vector 1
v2 vector 2

Return

the resulting vector

Declaration

public static float[] crossVec3(final float[] result, final float[] v1, final float[] v2) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*  ww  w  .  jav  a 2 s  .co  m*/
     * cross product vec1 x vec2
     * @param v1 vector 1
     * @param v2 vector 2
     * @return the resulting vector
     */
    public static float[] crossVec3(final float[] result, final float[] v1, final float[] v2) {
        result[0] = v1[1] * v2[2] - v1[2] * v2[1];
        result[1] = v1[2] * v2[0] - v1[0] * v2[2];
        result[2] = v1[0] * v2[1] - v1[1] * v2[0];
        return result;
    }

    /**
     * cross product vec1 x vec2
     * @param v1 vector 1
     * @param v2 vector 2
     * @return the resulting vector
     */
    public static float[] crossVec3(final float[] r, final int r_offset, final float[] v1, final int v1_offset,
            final float[] v2, final int v2_offset) {
        r[0 + r_offset] = v1[1 + v1_offset] * v2[2 + v2_offset] - v1[2 + v1_offset] * v2[1 + v2_offset];
        r[1 + r_offset] = v1[2 + v1_offset] * v2[0 + v2_offset] - v1[0 + v1_offset] * v2[2 + v2_offset];
        r[2 + r_offset] = v1[0 + v1_offset] * v2[1 + v2_offset] - v1[1 + v1_offset] * v2[0 + v2_offset];
        return r;
    }
}

Related

  1. CrossVec3D(double[] vec3Ret, double[] vec3A, double[] vec3B)