mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-17 13:24:17 -07:00
Add non-mutative getCrossProduct method to Vector.
By: 0x277F <0x277F@gmail.com>
This commit is contained in:
@@ -303,6 +303,25 @@ public class Vector implements Cloneable, ConfigurationSerializable {
|
|||||||
return this;
|
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).
|
* Converts this vector to a unit vector (a vector with length of 1).
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user