Hi everyone,

Is there a way in JME to check wether a point is inside a geometry object?

I want to check if a single vector (1d, 2d, 3d) is inside an arbitrary bounding

geometry (1d, 2d, 3d). The Ray class seems not to be appropriate as

it has a direction.

The reason for this:

I have implemented a Java version of "Fast Poisson Disk Sampling in Arbitrary Dimensions"

and now want to use an arbitrary bounding volume for the algorithm, since squares and cubes

are start to get boring. (I planned to make the result available on this forum)

Assuming your geometry is absolutely closed (no gaps, otherwise in and out has no meaning), there is a very elegant topological result:

If you cast a ray from a point into ANY direction, and it intersects your geometry in no critical point (I'll explain later) an ODD number of times, then it is in the interior, if it does that an EVEN number of times, then it is in the exterior.

A critical point would be a place where the ray is tangent to the geometry, like a ray barely touching the geometry… you should not worry much about this…

| | Geometry

/

__V_______ Ray

(a feeble attempt at illustrating the issue)

duenez said:

| | Geometry

/

__V_______ Ray

(a feeble attempt at illustrating the issue)

I got your point :D

Perhaps it is possible to shoot the ray always towards the center of the geometry and

avoid this issue? (if a center is available of course)

Thanks for the insight! I will try this out.

Not really, what if your geometry is like this:

__ ___

| | | |

| V |

_____/

Then aiming at the center would do you no good... In general, this is an open problem with not much of a solution... You should cast two or three rays, and if all of them hit an odd number of times, you can be pretty confident you got it right.