Vector { public Vector cross(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(float x, float y, float z); float get(int index); Vector cross(Matrix by); Vector subtract(Vector v); Vector cross(Vector with); Vector normalize(); Vector multiply(float by); float dot(Vector with); float length(); float lengthSquared(); @Override String toString(); @Override int hashCode(); @Override boolean equals(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); }