Last active
February 22, 2016 18:00
-
-
Save cheremin/a1fa2c30088038b3f7c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final class Vector2D { | |
private double x; | |
private double y; | |
public Vector2D( final double x, | |
final double y ) { | |
this.x = x; | |
this.y = y; | |
} | |
public Vector2D add( final Vector2D other ) { | |
return new Vector2D( | |
x + other.x, | |
y + other.y | |
); | |
} | |
public void addAccumulate( final Vector2D other ) { | |
x = x + other.x; | |
y = y + other.y; | |
} | |
public double dot( final Vector2D other ) { | |
return x * other.x + y * other.y; | |
} | |
public double length() { | |
return Math.sqrt( this.dot( this ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment