Triangular points around a point

I gave the coordinates of 1000 triangles on the plane (triangle number (T0001-T1000) and its coordinates (x1, y1) (x2, y2), (x3, y3)). Now, for a given point P (x, y), I need to find a triangle that contains a point P.

One option might be to check all the triangles and find a triangle containing P. But I'm looking for an effective solution to this problem.

+2
source share
2 answers

You will need to check each triangle at some point during the execution of your program. Is this an obvious right? If you want to maximize the efficiency of this calculation, you are going to create some kind of cache data structure. The data structure details depend on your application. For example: how often do triangles change? How often do you need to calculate where the point is?

One way to make the cache would be this: Divide your plane into a finite grid of boxes. For each field in the grid, save a list of triangles that may intersect with the field.

, , , , ( O (1) , ), .

+2

. .

, / . , .

, , , , ( java , ).

, , (, ), , , .

0

Source: https://habr.com/ru/post/1612866/


All Articles