modelling 3d cells defined by intersections of surfaces
I'm trying to create an interactive 3d representation of cells that are defined by the intersection of arbitrary surfaces. I'm having a hard time figuring out how to create a mesh from this (or is there something better than a mesh that I should be aiming for to represent 3d volumes?). Each surface s is given by an analytical expression for a plane, sphere, cylinder, cone, etc. as s = f(x,y,z) = 0, such as those here:
For each cell I have a list of surfaces and a +/- sense for each surface. With this it's easy to determine if an x,y,z point lies inside the cell by plugging that point into the equation for each of the bounding surfaces, and if the result is + for all + surfaces 开发者_如何学Pythonand - for all - surfaces the point lies inside. Obviously if the result is zero for any surface then the point lies on that surface.
I can test thousands of grid points, noting for each cell those points that lie inside that cell and then using the outer-most of those points to create a mesh for that cell. However, I have thousands of cells and this simply wouldn't be fast enough. Many cells are very small or low aspect ratio compared to others, so I would need a very fine grid of points if I was going to do it this way.
Can anyone suggest an efficient way of putting cells defined in this way into a static 3d model? Is there any sort of library that works with this kind of geometry specification that can build 3d meshes for me? Am I missing something obvious?
Thanks, Nick
As a general problem, this is quite difficult: I think it's basically a general nonlinear programming problem. If your boundaries are generated by arbitrary functions, there might be an arbitrary number of cells bounded by even one such function; without more information about the functions, I don't think you can do better than checking grid points.
If you know something about your function (e.g., plane, sphere, cylinder, and cone are all conics), you may be able to do better. In any case, you might want to start with a combinatorial approach; say, given any 3 boundaries, determine if there are any points where all three intersect.
In any case, once you identify corners and edges of your cell, you can use a grid-based approach to build a display mesh -- e.g., slice your surface with axis-aligned planes, to determine the vertices and triangles to send to your 3D graphics library of choice.
Another idea: since you're defining your surfaces by f(x,y,z)=0
, you can start with a bunch of points, and numerically migrate them onto nearby surfaces with a Newton's method step or something:
point p = (x,y,z)
scalar value = f(p)
while abs(value) > epsilon:
vector gradient = gradient_of_f(p)
p -= gradient * (value / dot(gradient,gradient))
value = f(p)
Something similar should allow you to approximate edge and corner points. It might be harder to figure out how to connect these kinds of points into a mesh, though...
精彩评论