Vector { public Vector cross(final Matrix by){ float x = vals[I1]*by.get(Matrix.I11) + vals[I2]*by.get(Matrix.I21) + vals[I3]*by.get(Matrix.I31); float y = vals[I1]*by.get(Matrix.I12) + vals[I2]*by.get(Matrix.I22) + vals[I3]*by.get(Matrix.I32); float z = vals[I1]*by.get(Matrix.I13) + vals[I2]*by.get(Matrix.I23) + vals[I3]*by.get(Matrix.I33); return new Vector(x, y, z); } Vector(final float x, final float y, final float z); float get(final int index); Vector cross(final Matrix by); Vector subtract(final Vector v); Vector cross(final Vector with); Vector normalize(); Vector multiply(final float by); float dot(final Vector with); float length(); float lengthSquared(); @Override String toString(); @Override int hashCode(); @Override boolean equals(final Object obj); static final int I1; static final int I2; static final int I3; }
@Test public void testCrossVector() { Vector v = new Vector(2, 3, 4); Matrix m = new Matrix(5, 6, 7, 8, 9, 10); Vector shouldBe = new Vector(67, 76, 4); Vector rslt = v.cross(m); Assert.assertEquals(shouldBe, rslt); }