//////// Vector2D.java ////////// public class Vector2D { public Vector2D() {} public Vector2D(float x, float b) { this.x = x; y = b; } public boolean equals(Vector2D v) { return( x == v.x && y == v.y ); } public String toString() { return( "(" + x + ", " + y + ')' ); } public boolean nonzero() { return ( x != 0.0f || y != 0.0f ); } public float inner(Vector2D a) { return(x * a.x + y * a.y); } public Vector2D minus(Vector2D a) { Vector2D tmp = new Vector2D(); tmp.x = x - a.x; tmp.y = y - a.y; return(tmp); } // test if the host is parallel to b // (pointing in the same direction) public boolean isParallel(Vector2D b) { return( nonzero() && b.nonzero() && x*b.x >= 0.0f && y*b.y >= 0.0f && Math.abs(x*b.y-y*b.x) < delta ); } public boolean isPerpendicular(Vector2D b) { return ( nonzero() && b.nonzero() && Math.abs(x*b.x + y*b.y) < delta ); } private static float delta = 0.00000001f; private float x, y; }