Skip to content

@Agrosis /gist:4552530
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.