Last active
February 6, 2017 20:11
-
-
Save ase34/11375298 to your computer and use it in GitHub Desktop.
bukkit plane/line intersection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* See the whitepaper at https://docs.google.com/file/d/0B9Sf4F-ig8lPUlhOdHZ2ZGtzdnM | |
*/ | |
public static double determinant(double[][] matrix) { | |
return matrix[0][0] * matrix[1][1] * matrix[2][2] + matrix[0][1] * matrix[1][2] * matrix[2][0] + matrix[0][2] * matrix[1][0] * matrix[2][1] - matrix[0][2] * matrix[1][1] * matrix[2][0] - matrix[0][1] * matrix[1][0] * matrix[2][2] - matrix[0][0] * matrix[1][2] * matrix[2][1]; | |
} | |
public static Vector getIntersection(Vector linePoint, Vector lineDirection, Vector planeOrigin, Vector planeXDirection, Vector planeYDirection) { | |
double[][] coefficients = { | |
{lineDirection.getX(), -planeXDirection.getX(), -planeYDirection.getX()}, | |
{lineDirection.getY(), -planeXDirection.getY(), -planeYDirection.getY()}, | |
{lineDirection.getZ(), -planeXDirection.getZ(), -planeYDirection.getZ()} | |
}; | |
double[] solutions = { | |
planeOrigin.getX() - linePoint.getX(), | |
planeOrigin.getY() - linePoint.getY(), | |
planeOrigin.getZ() - linePoint.getZ() | |
}; | |
double[][] dMatrix = { | |
{solutions[0], coefficients[0][1], coefficients[0][2]}, | |
{solutions[1], coefficients[1][1], coefficients[1][2]}, | |
{solutions[2], coefficients[2][1], coefficients[2][2]} | |
}; | |
double[][] sMatrix = { | |
{coefficients[0][0], solutions[0], coefficients[0][2]}, | |
{coefficients[1][0], solutions[1], coefficients[1][2]}, | |
{coefficients[2][0], solutions[2], coefficients[2][2]} | |
}; | |
double[][] tMatrix = { | |
{coefficients[0][0], coefficients[0][1], solutions[0]}, | |
{coefficients[1][0], coefficients[1][1], solutions[1]}, | |
{coefficients[2][0], coefficients[2][1], solutions[2]} | |
}; | |
double det = determinant(coefficients); | |
double d = determinant(dMatrix) / det; | |
double s = determinant(uMatrix) / det; | |
double t = determinant(vMatrix) / det; | |
return new Vector(s, t, 0); | |
} |
@blablubbabc Yes, it is actually missing... It's really strange how this works though. Anyway, I really thank you for finding this stupid mistake of mine.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Isn't determinant missing + matrix[0][2] * matrix[1][0] * matrix[2][1] ?