Skip to content

Instantly share code, notes, and snippets.

@RaasAhsan
Created January 17, 2013 00:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save RaasAhsan/4552530 to your computer and use it in GitHub Desktop.
my description of a vector
package com.jantox.dungmast;
public class Vector2D {
public double x, y;
public Vector2D() {
x = y = 0;
}
public Vector2D(double x, double y) {
this.x = x;
this.y = y;
}
public int getX() {
return (int) x;
}
public int getY() {
return (int) y;
}
public double dotProduct(Vector2D b) {
return x * b.x + y * b.y;
}
public double distanceSquared(Vector2D b) {
return Math.pow(b.x - x, 2) + Math.pow(b.y - y, 2);
}
public double length() {
return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
}
public void normalize() {
double length = this.length();
x /= length;
y /= length;
}
public Vector2D copy() {
return new Vector2D(x, y);
}
public void add(Vector2D b) {
x += b.x;
y += b.y;
}
public void subtract(Vector2D b) {
x -= b.x;
y -= b.y;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment