Hi all,
Say that you have U polygons, where each polygon has V vertices (that is, every polygon has the same number of vertices). One can consider line segments between each pair of points (A, x), (B, y), where A and B are polygon numbers, and x and y are vertex numbers.
My problem is to determine whether any such line segment (A, x), (B, y) intersects any polygon in the system.
My algorithm was initially designed for CPU execution, and took the following form (to answer the question "does the given line segment intersect with any polygon in the system?"):
1) does the line segment intersect with the polygon it originates from? if yes, return TRUE, else continue to 2)
2) does the line segment intersect with the polygon it ends at? if yes, return TRUE, else continue to 3)
3) does the line segment NOT intersect with the bounding box of any polygon apart from the ones it originates and ends at? if yes, return FALSE, else continue to 4)
4) for each polygon whose bounding box the line segment intersects with, check to see if each the line segment intersects with any edge -- if yes, return TRUE
I am now thinking of re-organizing my code for execution on a CUDA GPU. My thought is that instead of trying to faithfully translate the above algorithm, in order to take advantage of the massively-parallel capacity of the GPU, I should do the following:
Kernel: given two line segments, check to see if they intersect
Problem space: line segment of interest, all polygon edges in system
So, on each thread I would solve the problem: "does the line segment of interest intersect with the polygon edge assigned to this thread"? Much of the sophistication of the CPU algorithm (e.g. checking for bounding box intersections separately, checking to see if self-intersections apply, etc.) are thrown out of the window, in order to take advantage of the massively-parallel capacity of the GPU.
Does this make sense?
Kind regards,
Brian