If you think the Android project X3n0break listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.x3n0m0rph59.breakout;
//fromwww.java2s.compublicfinalclass Vector {
privatefinalfloat x, y, theta;
public Vector(float x, float y, float theta) {
this.x = x;
this.y = y;
this.theta = theta;
}
public Vector add(Vector rhs) {
returnnew Vector(this.x + rhs.x, this.y + rhs.y, theta);
}
public Vector mult(float scalar) {
returnnew Vector(this.x * scalar, this.y * scalar, theta);
}
publicfloat dot(Vector rhs) {
return (this.x * rhs.x) + (this.y * rhs.y);
}
public Vector cross(Vector rhs) {
returnnew Vector(rhs.y, -rhs.x, 0.0f);
}
public Vector normalize() {
if (magnitude() == 0)
returnthis;
elsereturnnew Vector(x / magnitude(), y / magnitude(), theta);
}
publicfloat magnitude() {
return (float) Math.sqrt((x * x) + (y * y));
}
publicfloat getX() {
return x;
}
publicfloat getY() {
return y;
}
publicfloat getTheta() {
return theta;
}
@Override
publicint hashCode() {
finalint prime = 31;
int result = 1;
result = prime * result + Float.floatToIntBits(theta);
result = prime * result + Float.floatToIntBits(x);
result = prime * result + Float.floatToIntBits(y);
return result;
}
@Override
publicboolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Vector other = (Vector) obj;
if (Float.floatToIntBits(theta) != Float.floatToIntBits(other.theta))
return false;
if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
return false;
if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
return false;
return true;
}
@Override
public String toString() {
return"Vector [x=" + x + ", y=" + y + ", theta=" + theta + "]";
}
}