3dcomputational-geometry

Find visibility polyhedron given a point inside it


I have some mesh objects ready, which means I have all the vertices and the triangles of the mesh in arrays. I also have a point which I can move with the keyboard arrows and whenever the point is inside the mesh I want to find its viewpoint, that is the part of the polyhedron it can see.

I have thought of the very simple O(n^2) algorithm, meaning :

For every triangle of the mess I draw a polyhedron consisting of the triangle's 3 vertices and the moving point. Then check if this polyhedron intersects with any other triangle. If it doesn't the triangle is included in the result. If it does I follow some calculations to see what part of the triangle is visible.

Obviously, this is very slow. Finding a faster algorithm in 2D was not a problem but here I don't have many ideas.

Clearly, there has to be a way to avoid checking for intersections with other triangles that have no chance of intersecting. So I suppose there must be a way to kind of sort the triangles in space? How should I approach the whole problem? Are there any linear algorithms on this one like in the 2D problem?

Edit: Should I use a kd-tree triangle sorting approach?


Solution

  • This is a problem of hidden parts removal.

    To cope with the 4π solid angle span, you can project on the six faces of a cube centered on the query point. Then this turns to an ordinary hidden face removal problem for which several well established algorithms are available. https://en.wikipedia.org/wiki/Hidden_surface_determination

    This is a pretty vast topic and the choice of the algorithm depends on what processing will follow.

    In your particular case, it can be useful to use the space transformation (x,y,z) => (x/z,y/z,1/z) (centered at the viewing point), which turns the central projection to a parallel one. Then by means of AABB around the facets, you reduce the problem to that of finding overlaps in a collection of rectangles. This can be addressed by a sweepline approach, among others.