Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Vector2D {
- double x, y;
- public Vector2D() {
- x = 0;
- y = 0;
- }
- public Vector2D(double x, double y) {
- this.x = x;
- this.y = y;
- }
- public Vector2D add(Vector2D v) {
- return new Vector2D(v.x + x, v.y + y);
- }
- public void add2(Vector2D v) {
- x += v.x;
- y += v.y;
- }
- public Vector2D sub(Vector2D v) {
- return new Vector2D(x - v.x, y - v.y);
- }
- public void sub2(Vector2D v) {
- x -= v.x;
- y -= v.y;
- }
- public Vector2D mult(double a) {
- return new Vector2D(x * a, y * a);
- }
- public void mult2(double a) {
- x *= a;
- y *= a;
- }
- public String toString() {
- return "(" + x + ";" + y + ")";
- }
- public double length() {
- return Math.sqrt(x * x + y * y);
- }
- public double scalarProduct(Vector2D v) {
- return x * v.x + y * v.y;
- }
- public double cos(Vector2D v) {
- return scalarProduct(v) / (length() * v.length());
- }
- public boolean equals(Vector2D v) {
- return v.x == x && v.y == y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement