Vector2D implements Vector<Euclidean2D> { public double crossProduct(final Vector2D p1, final Vector2D p2) { final double x1 = p2.getX() - p1.getX(); final double y1 = getY() - p1.getY(); final double x2 = getX() - p1.getX(); final double y2 = p2.getY() - p1.getY(); return MathArrays.linearCombination(x1, y1, -x2, y2); } Vector2D(double x, double y);  Vector2D(double[] v);  Vector2D(double a, Vector2D u);  Vector2D(double a1, Vector2D u1, double a2, Vector2D u2);  Vector2D(double a1, Vector2D u1, double a2, Vector2D u2,
                   double a3, Vector2D u3);  Vector2D(double a1, Vector2D u1, double a2, Vector2D u2,
                   double a3, Vector2D u3, double a4, Vector2D u4); double getX(); double getY(); double[] toArray(); Space getSpace(); Vector2D getZero(); double getNorm1(); double getNorm(); double getNormSq(); double getNormInf(); Vector2D add(Vector<Euclidean2D> v); Vector2D add(double factor, Vector<Euclidean2D> v); Vector2D subtract(Vector<Euclidean2D> p); Vector2D subtract(double factor, Vector<Euclidean2D> v); Vector2D normalize(); static double angle(Vector2D v1, Vector2D v2); Vector2D negate(); Vector2D scalarMultiply(double a); boolean isNaN(); boolean isInfinite(); double distance1(Vector<Euclidean2D> p); double distance(Vector<Euclidean2D> p); double distance(Point<Euclidean2D> p); double distanceInf(Vector<Euclidean2D> p); double distanceSq(Vector<Euclidean2D> p); double dotProduct(final Vector<Euclidean2D> v); double crossProduct(final Vector2D p1, final Vector2D p2); static double distance(Vector2D p1, Vector2D p2); static double distanceInf(Vector2D p1, Vector2D p2); static double distanceSq(Vector2D p1, Vector2D p2); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); String toString(final NumberFormat format); static final Vector2D ZERO; static final Vector2D NaN; static final Vector2D POSITIVE_INFINITY; static final Vector2D NEGATIVE_INFINITY; }
@Test public void testCrossProduct() { final double epsilon = 1e-10; Vector2D p1 = new Vector2D(1, 1); Vector2D p2 = new Vector2D(2, 2); Vector2D p3 = new Vector2D(3, 3); Assert.assertEquals(0.0, p3.crossProduct(p1, p2), epsilon); Vector2D p4 = new Vector2D(1, 2); Assert.assertEquals(1.0, p4.crossProduct(p1, p2), epsilon); Vector2D p5 = new Vector2D(2, 1); Assert.assertEquals(-1.0, p5.crossProduct(p1, p2), epsilon); }