There are analytical ex开发者_StackOverflow中文版pressions that permit the calculation of the curve resulting from the overlapping between three penetrating spheres. There are also approximate methods that using grids or another methodologies, calculate points with more or less accuracy that belong to this interesection. I wonder if for the latter, the calculation can be done somehow using special hardware functions from the GPU, with CUDA or OpenGL. I need it for a very computing intensive number crunching program, so trivial implementations are not valid since they are very slow, and that is why I consider the GPU option
To test if a point (x, y, z) is in a sphere centered on (a, b, c) with radius r, the test is:
(x - a)^2 + (y - b)^2 + (z - c)^2 < r^2
Testing if the point is in multiple spheres is just an and
of similar expressions. This only requires subtraction, multiplication, and comparison, no special hardware functions needed. You can write a CUDA kernel that does this with no problem.
The closest "specialized hardware" that might be applicable is the rsqrtf()
function in CUDA, which computes 1/sqrt(x) in single precision to good accuracy with a single hardware instruction. You might use this to help calculate z values given x and y values of spheres, this could be useful for more sophisticated point generation algorithms for this problem.
精彩评论