Hello,
I think that there is something slightly wrong with Vector2F's method. Look:
Code:
public void setTheta(double theta) {
// Next lines are to prevent numbers like -1.8369701E-16
// when working with negative numbers
if ((theta < -360) || (theta > 360)) {
theta = theta % 360;
}
if (theta < 0) {
theta = 360 + theta;
}
double oldTheta = getTheta();
if ((theta < -360) || (theta > 360)) {
oldTheta = oldTheta % 360; // Line1
}
if (theta < 0) {
oldTheta = 360 + oldTheta; // Line 2
}
float len = length();
x = len * (float) FastTrig.cos(StrictMath.toRadians(theta));
y = len * (float) FastTrig.sin(StrictMath.toRadians(theta));
// x = x / (float) FastTrig.cos(StrictMath.toRadians(oldTheta))
// * (float) FastTrig.cos(StrictMath.toRadians(theta));
// y = x / (float) FastTrig.sin(StrictMath.toRadians(oldTheta))
// * (float) FastTrig.sin(StrictMath.toRadians(theta));
}
Lines marked by me as Line1 and Line2 will never execute.
It is minor mistake, but IS A mistake and it should be repaired.
Also, it is reasonable to extract method like this:
Code:
public static double normalizeAngle(double originalAngle) {
double normalizedAngle;
if ((theta < -360) || (theta > 360)) {
normalizedAngle = oldTheta % 360;
}
if (theta < 0) {
normalizedAngle = 360 + normalizedAngle;
}
return normalizedAngle;
}
... and put it in some math tool class.
Thanks for great lib:)
Never give up.