How to determine that is a node inside the quad?

how to determine that is a node inside the quad?

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.

in multi-select by mouse like C&C game.

I assume by â€śquadâ€ť you mean `com.jme3.scene.shape.Quad`. Correct?

1 Like

Even still, this is quite trivial. Translate the world point into quad-local space. See if itâ€™s with the bounds of the quad.

yes.

I donâ€™t know how to do it.

I found this:

but I donâ€™t know how can I calculate the area of a triangle with three given points (x,y).

â€ś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â€¦â€ť

world-to-localâ€¦world-to-localâ€¦ hmmmâ€¦

1 Like

ok, how can I calculate the area of a triangle with three given points (x,y)?

In local space,
if x < 0 and x > widthâ€¦ itâ€™s not in the quad.
if y < 0 and y > heightâ€¦ itâ€™s not in the quad.

1 Like

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:

``````    /**
* Calculate the area of the specified triangle.
*
* @param triangle (not null, unaffected)
* @return the area (&ge;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 (&ge;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;
}
``````
1 Like

@yn97

Look into this method:

``````FastMath.pointInsideTriangle
``````
1 Like

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.

The cross product is a vector. To compute the abs() of a vector, one must extract a square root.

2 Likes

Sorry I mustâ€™ve been out of my mind last night

1 Like

No worries. I appreciate when people study my code and offer constructive feedback.

1 Like