Skip to content

Instantly share code, notes, and snippets.

@cheremin
Last active February 22, 2016 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheremin/a1fa2c30088038b3f7c5 to your computer and use it in GitHub Desktop.
Save cheremin/a1fa2c30088038b3f7c5 to your computer and use it in GitHub Desktop.
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