Java Array Cross Product cross(final double[] left, final double[] right)

Here you can find the source of cross(final double[] left, final double[] right)

Description

cross product or 2 3x1 vectors

License

Apache License

Parameter

Parameter Description
left a vector of length 3
right a vector of length 3

Return

a cross b

Declaration

public static double[] cross(final double[] left, final double[] right) 

Method Source Code

//package com.java2s;
/**/*from  w w  w . ja  va2 s  . co m*/
 * =====================================================================
 *   This file is part of JSatTrak.
 *
 *   Copyright 2007-2013 Shawn E. Gano
 *   
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *   
 *       http://www.apache.org/licenses/LICENSE-2.0
 *   
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * =====================================================================
 */

public class Main {
    /**
     * cross product or 2 3x1 vectors
     *
     * @param left a vector of length 3
     * @param right a vector of length 3
     * @return a cross b
     */
    public static double[] cross(final double[] left, final double[] right) {
        if ((left.length != 3) || (right.length != 3)) {
            System.out.println("ERROR: Invalid dimension in Cross(Vector,Vector)");
        }

        double[] Result = new double[3];
        Result[0] = left[1] * right[2] - left[2] * right[1];
        Result[1] = left[2] * right[0] - left[0] * right[2];
        Result[2] = left[0] * right[1] - left[1] * right[0];

        return Result;
    }
}

Related

  1. cross(double v0x, double v0y, double v1x, double v1y)
  2. cross(double v1[], double v2[])
  3. cross(double[] p, double[] q)
  4. cross(double[] vec1, double[] vec2, double[] outvec)
  5. cross(final double[] a, final double[] b, final double[] c)
  6. cross(float[] v1, float[] v2, float[] out)
  7. cross(float[] vec1, float[] vec2)
  8. cross(int x1, int y1, int x2, int y2)
  9. cross2D(final float[] v1, final float[] v2)