I have a point (node.get World Translation) and four positions of a quad (vertices[4]).
I want to determine if that point is inside the quad or not. and without using shape collision.
“I wonder how to translate something from world to local space… let me check the javadoc just in case this is one of those 1 in 10 times that there is something…”
When someone helps you with an issue, you should communicate your thanks. This is a special case of “Treat the list like people”. For more tips, see the “How to get answers” link in the left sidebar of this Forum: mikeash.com: Getting Answers
/**
* Calculate the area of the specified triangle.
*
* @param triangle (not null, unaffected)
* @return the area (≥0)
*/
public static double area(Triangle triangle) {
Vector3f a = triangle.get1();
Vector3f b = triangle.get2();
Vector3f c = triangle.get3();
Vector3f ab = b.subtract(a);
Vector3f ac = c.subtract(a);
Vector3f cross = ab.cross(ac);
double areaSquared = lengthSquared(cross) / 4.0;
double area = Math.sqrt(areaSquared);
return area;
}
/**
* Calculate the squared length of a vector. Unlike
* {@link com.jme3.math.Vector3f#lengthSquared()}, this method returns a
* double-precision value for precise comparison of lengths.
*
* @param vector input (not null, unaffected)
* @return the squared length (≥0)
*/
public static double lengthSquared(Vector3f vector) {
double xx = vector.x;
double yy = vector.y;
double zz = vector.z;
double result = xx * xx + yy * yy + zz * zz;
return result;
}
I don’t get why you do (x^2)/4 then take the square root of that. You just square then sqrt. The same as just taking abs( cross / 2), which is a property of the cross product. Abs(cross) is equal to the area of the parallelogram formed by the two vectors.