Vector2D extends Vecteur { public Vector2D project(double direction) { if (direction >= Math.PI * 2) direction = direction - Math.PI * 2; Vector2D unitVect = new Vector2D(new Angle(direction), 1); double norm = this.prodScalaire(unitVect); return unitVect.changeNorm(norm); } Vector2D(double x, double y);  Vector2D();  Vector2D(IDirectPosition dp1, IDirectPosition dp2);  Vector2D(IDirectPosition dp1);  Vector2D(Angle angle, double norm); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); Vector2D add(Vector2D v); @Override Vecteur ajoute(Vecteur v1); Vector2D copy(); void scalarMultiplication(double lambda); @Override ILineString translate(ILineString l); double vectorAngle(Vector2D v); double vectorAngle0ToPi(Vector2D v); boolean isNull(); Vector2D changeNorm(double newNorm); Vector2D rotate(double angle); Vector2D opposite(); ILineSegment toGeom(IDirectPosition point); boolean isColinear(Vector2D vect); boolean isColinear(Vector2D vect, double tolerance); Vector2D project(double direction);  }
@Test public void testProject() { IDirectPosition p1 = new DirectPosition(0.0, 0.0); IDirectPosition p2 = new DirectPosition(10.0, 10.0); IDirectPosition p3 = new DirectPosition(0.0, 5.0); IDirectPosition p4 = new DirectPosition(5.0, 0.0); Vector2D vect = new Vector2D(p1, p2); Vector2D vect2 = new Vector2D(p1, p3); Vector2D vect3 = new Vector2D(p1, p4); Vector2D proj = vect.project(0.0); Assert.assertTrue(Math.abs(10 - proj.norme()) < 0.001); Assert.assertTrue(proj.isColinear(vect3)); Vector2D proj2 = vect.project(Math.PI * 2); Assert.assertTrue(Math.abs(10 - proj2.norme()) < 0.001); Assert.assertTrue(proj2.isColinear(vect3)); Vector2D proj3 = vect.project(Math.PI / 2); Assert.assertTrue(Math.abs(10 - proj3.norme()) < 0.001); Assert.assertTrue(proj3.isColinear(vect2, 0.0001)); }