From fef9177b36885973dd444cee34d7492bbcc1533c Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 5 Feb 2016 21:08:42 -0700 Subject: [PATCH] Add non-mutative getCrossProduct method to Vector. By: 0x277F <0x277F@gmail.com> --- .../src/main/java/org/bukkit/util/Vector.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/util/Vector.java b/paper-api/src/main/java/org/bukkit/util/Vector.java index 685148ec6..cebd3ccb7 100644 --- a/paper-api/src/main/java/org/bukkit/util/Vector.java +++ b/paper-api/src/main/java/org/bukkit/util/Vector.java @@ -303,6 +303,25 @@ public class Vector implements Cloneable, ConfigurationSerializable { return this; } + /** + * Calculates the cross product of this vector with another without mutating + * the original. The cross product is defined as: + * + * + * @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). *