You might think of a triangle as the intersection of three half-spaces. To find the number of points inside the triangle A, B, C, we first consider the set of points on one side of an infinite line in the direction AB. Let these sets L (AB) and R (AB) for points on the left and on the right. In the same way, you and the other two edges build the sets L (AC) and R (AC) and the sets L (BC) and R (BC).
Thus, the number of points in ABC will be the number of intersection points of L (AB), L (AC) and L (BC). (Instead, you can consider R (AB) depending on the orientation of the triangle).
Now, if we want to consider a complete set of 500 points. First, take all pairs of points AB and construct the sets L (AB) and R (AB). This will lead to O (n ^ 3) operations.
Then we check all the triangles and find the intersections of the three sets. If we use a hash table structure for sets, then finding intersection points is like a hash table. If L (AB) has l elements, L (AC) has m elements and L (BC) n elements. Say l> m> n. For each point in L (BC), we need to search in L (AC) and L (BC) so that there is a maximum of 2n searches in the hash table.
You might find it easier to look at the geometric search table. Divide your entire domain into a coarse grid, say, a 10 by 10 grid. Then we can put each point in the set G (i, j). Then we can split the sets L (AB) into each grid cell. Let's say we call these sets L (AB, i, j) and R (AB, i, j). When testing for intersections, the first training session, the grid cells of which lie at the intersection. This greatly reduces the search space, and since each set L (AB, i, j) contains fewer members, there will be fewer hash table queries.
source share