Check points is inside a polygon - doesn't work correct

I create a room based on any Array with points. Objects that can be moved are added to the room. The goal is to block the possibility of moving the object out of the room.

When the object is moved, I check if all 4 bottom points belong to the floor - if so, you can move the object further - if not, it means that the object would go behind the wall, so you have to restore it to the previous position.

The code can be seen here:

Prisoner849 user - gave in response an algorithm that checks if points are inside a polygon. It works great until I add rotation to the polygon - this solution does not work. Ultimately, orbitControls will be added to the cameras.

The problem can be seen here:

I want the checkPoints function to show true or false depending on whether all 4 points are on the floor or not.

1 Like

Are you looking for something like this?

Just another idea is to use polybool.js (related topic [Closed] How to split/separate a single ShapeGeometry into individual Geometries base on faces?) to work with polygons: find intersection of the polygon of your floor and the polygon of your four point rectangle, if the result (its area or coordinates of vertices or amount of veriteces) is not the same as your original rectangle, then your rectangle is out of the floor.


Thank you very much :slight_smile: I think that the codepen solution will work for me :slight_smile:

Checking the points works perfectly, but it does not quite solve my stackowerflow problem.
the idea is that the green square (in the original will be different models) could not go beyond the lines. Any attempt to modify the cube.position ends badly.
Look at:

You know position of the cube, you know its size, thus you have to check four points instead of one.

thanks for help - everything works as it should be :slight_smile:

1 Like

You’re welcome :slight_smile: :beers: