Signed angles

This commit is contained in:
Hazel Trinity 2020-08-16 16:05:09 -07:00
parent 5a482f4d38
commit 73d70527f3

View File

@ -115,6 +115,13 @@ public abstract class Spline {
}
}
/**
* 2 dimensional "cross" product. cross2D(v1, v2) = |v1|*|v2|*sin(theta) or v1 X v2 taking Y to be 0
*/
private double cross2D(Vector2 v1, Vector2 v2) {
return v1.getX() * v2.getZ() - v2.getX() * v1.getZ();
}
/**
* Paste structure at the provided position on the curve. The position will not be position-corrected
* but will be passed directly to the interpolation algorithm.
@ -136,7 +143,7 @@ public abstract class Spline {
Vector3 deriv = interpolation.get1stDerivative(position);
Vector2 deriv2D = Vector2.at(deriv.getX(), deriv.getZ()).normalize();
double angle = Math.toDegrees(
-Math.acos(direction.dot(deriv2D))
-Math.atan2(cross2D(direction, deriv2D), direction.dot(deriv2D))
);
angle = ((angle % 360) + 360) % 360; // Wrap to 360 degrees