summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
author0x277F <0x277F@gmail.com>2016-02-05 21:08:42 -0700
committermd_5 <git@md-5.net>2016-02-07 10:06:22 +1100
commit01d1820664a5f881665b84b28871dadd132deaef (patch)
treeba9c762891a705601d3f4efd5d5b5e4442ba86ef /src/main
parentf517b6e6a95a7a7f5498bce806a9b997e433f75b (diff)
downloadbukkit-01d1820664a5f881665b84b28871dadd132deaef.tar
bukkit-01d1820664a5f881665b84b28871dadd132deaef.tar.gz
bukkit-01d1820664a5f881665b84b28871dadd132deaef.tar.lz
bukkit-01d1820664a5f881665b84b28871dadd132deaef.tar.xz
bukkit-01d1820664a5f881665b84b28871dadd132deaef.zip
Add non-mutative getCrossProduct method to Vector.
Diffstat (limited to 'src/main')
-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