package KinematicSimulator; /** * A mathematical Vector, two dimensional. * * @author Steve */ class Vector2D { public Vector2D add(Vector2D vector2d) { Vector2D vector2d1 = new Vector2D(x + vector2d.x, y + vector2d.y); return vector2d1; } public double dot(Vector2D vector2d) { return x * vector2d.x + y * vector2d.y; } Vector2D(double d, double d1) { x = d; y = d1; } Vector2D(Vector2D vector2d) { x = vector2d.x; y = vector2d.y; } public double length() { return Math.sqrt(Math.pow(x, 2D) + Math.pow(y, 2D)); } public double get_x() { return x; } public double get_y() { return y; } public double angle() { return Math.atan2(x, y); } public Vector2D negative() { Vector2D vector2d = new Vector2D(-x, -y); return vector2d; } public Vector2D scale(double d) { return new Vector2D(x * d, y * d); } public Vector2D subtract(Vector2D vector2d) { Vector2D vector2d1 = new Vector2D(x - vector2d.x, y - vector2d.y); return vector2d1; } public Vector2D projection(Vector2D vector2d) { Vector2D vector2d1 = scale(dot(vector2d) / Math.pow(length(), 2D)); return vector2d1; } private double x; private double y; }