tags:

views:

128

answers:

5

Hi

There are thousands of rays and triangles. We need get all the intersection points. If we use the normal two level loops,we need O(m*n) time complexity.Is there any way to low the time complexity fronm O(m*n) to O(m* logn) or O(logm*n)?

Best Regards,

A: 

In 2D there's SweepLine algorithm. It looks to me like it can be generalized for 3D.

Drakosha
+2  A: 

No. The reason is simple: there may actually be O(m * n) intersection points. just creating a list of them is O(n * m).

Ofri Raviv
This impies only the there can't be a better worst case complexity than O(nm). And if you allow the algorithm to output chunks of intersection points, even that doesn't hold true.
drhirsch
The question is the algorithm running in O(#answers) or O(m*n)!!
Drakosha
Because some rays and triangles have no intersection,I think the O(mn)is the worst.
ET 0.618
It depends on what you mean by m and n. In raytracing, m would be the width of the viewpane, n the height. In that case, it can be optimized.
Fortega
@Fortega m means the number of Rays, n means the number of triangles
ET 0.618
A: 

You could group the triangles close to each other in cubes. Then for each ray: if it does not hit the cube, you are sure it does not hit one of the triangles inside the cube, so you can skip all the intersection calculations with those triangles for this specific ray.

Fortega
+7  A: 

What you probably want to look at is some kind of space partitioning technique. This allows you to quickly rule out collections of triangles.

I'd probably consider some approach using spherical Bounding Volume Hierarchies. But other techniques you may also want to look into are BSP (Binary Space Partitioning) Trees/ KD Trees or using an Octree

Adam Luchjenbroers
+1  A: 

The classic solution to this problem is to build a KD tree based on the triangles, and query it for each ray. You can optimize the tree for the kind of queries you expect; if your rays are randomly distributed, the probability of a hit is proportional to the surface area in question.

Even if you aren't actually doing ray tracing, this problem is currently the main performance bottleneck for ray tracing, so you should probably check out the literature on it.

comingstorm