cross Vector - Java java.lang

Java examples for java.lang:Math Matrix

Description

cross Vector

Demo Code


//package com.java2s;

public class Main {
    public static float[] crossVec(float[] vec1, float[] vec2) {
        if ((vec1.length != vec2.length) || (vec1.length != 3)) {
            return null;
        }//from  w w w.  jav  a2 s.  c o  m

        float[] returnFloat = new float[vec1.length];

        returnFloat[0] = (vec1[1] * vec2[2]) - (vec2[1] * vec1[2]);
        returnFloat[1] = (vec1[2] * vec2[0]) - (vec2[2] * vec1[0]);
        returnFloat[2] = (vec1[0] * vec2[1]) - (vec2[0] * vec1[1]);

        return returnFloat;
    }
}

Related Tutorials