Add non-mutative getCrossProduct method to Vector.

By: 0x277F <0x277F@gmail.com>
This commit is contained in:
Bukkit/Spigot 2016-02-05 21:08:42 -07:00
parent 0d19656632
commit fef9177b36

View File

@ -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:
* <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).
*