Answer the question
In order to leave comments, you need to log in
Fastest algorithm to determine if a point is inside a region?
There is a large area (polygon, 1000+- points) of complex shape (both convex and "convex") and an array of points (10-30). For each point, it is required to check its entry into the polygon.
Implementation in PHP and possibly JS.
I found neither one nor two algorithms, but those are just algorithms without speed comparison, and in order to conduct your own tests, you will have to implement each one, which is not that fast.
Maybe someone knows what algorithm is best suited for these purposes? Or maybe there are alternative options for the implementation of the following undertaking?
Answer the question
In order to leave comments, you need to log in
Is the game very serious? I mean that
The client cannot be trusted
Well, from what I understood from the description, I would use a Quad-tree to group both points and polygons by area. I would make the minimum level of Qaud such that its size is much smaller than the size of the polygon, so that if it is intersected by the polygon Qaud-a, it would be divided into 2 or more triangles. Well, then the verification algorithm itself: we find Qaud for a point (a time-constant operation, since it can be determined by a formula by a position), we look if this Qaud contains a part of a given polygon, we check whether this part is completely contained in Quad or not ., if completely - everything is OK, if not completely - we divide into triangles formed by the intersection points of the polygon and Quad and check if the point hits the triangle belonging to the polygon.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question