From 73d70527f3a89231fe0f44c5f1aa93cfa7c817c5 Mon Sep 17 00:00:00 2001 From: Hazel Trinity Date: Sun, 16 Aug 2020 16:05:09 -0700 Subject: [PATCH] Signed angles --- .../com/boydti/fawe/object/brush/sweep/Spline.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/Spline.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/Spline.java index 7c7e5cd92..1f4da3cb7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/Spline.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/Spline.java @@ -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,9 +143,9 @@ 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 return pasteBlocks(blockTarget, offset, angle);