mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-24 01:01:58 +01:00
Add non-mutative getCrossProduct method to Vector.
By: 0x277F <0x277F@gmail.com>
This commit is contained in:
parent
0d19656632
commit
fef9177b36
@ -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).
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user