summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/util/Vector.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/util/Vector.java b/src/main/java/org/bukkit/util/Vector.java
index 685148ec..cebd3ccb 100644
--- a/src/main/java/org/bukkit/util/Vector.java
+++ b/src/main/java/org/bukkit/util/Vector.java
@@ -304,6 +304,25 @@ public class Vector implements Cloneable, ConfigurationSerializable {
}
/**
+ * Calculates the cross product of this vector with another without mutating
+ * the original. The cross product is defined as:
+ * <ul>
+ * <li>x = y1 * z2 - y2 * z1
+ * <li>y = z1 * x2 - z2 * x1
+ * <li>z = x1 * y2 - x2 * y1
+ * </ul>
+ *
+ * @param o The other vector
+ * @return a new vector
+ */
+ public Vector getCrossProduct(Vector o) {
+ double x = this.y * o.z - o.y * this.z;
+ double y = this.z * o.x - o.z * this.x;
+ double z = this.x * o.y - o.x * this.y;
+ return new Vector(x, y, z);
+ }
+
+ /**
* Converts this vector to a unit vector (a vector with length of 1).
*
* @return the same vector