I want to represent cube or polygon as a collection particles, so that it can be divided into spatial grid. The reason behind is that I want to calculate the collision of fluid particle (SPH technique) with solid objects like building, terrain. How can I represent solid objects as collection of particles?
-
1it's easier/more performant to keep it as a mesh – ratchet freak Mar 13 '15 at 00:54
-
@ratchetfreak I think he means mesh but with point grid like terrain instead of perimeter vertexes only – Spektre Mar 13 '15 at 07:34
1 Answers
If I get it right you want to achieve something like this:
so just divide your mesh to quads or any other primitives I would do it like this:
obtain the points
just all the global grid points that are inside polygon. You can also add the intersection of grid axises with perimeter polyline so loop through all grid points inside bounding rectangle of polygon and use points that are inside with hit test
Another option is make something like
but rasterize with grid step instead of single pixel and store the point coordinates instead of outputing it to image/screen ...
quad/triangulate ...
the inside is straight forward but the perimeter can be a mess. If you ignore perimeter grid points then the problem is much simplified. Connect points according to their coordinates and handle special cases or use any standard triangulation algorithm for these areas.
The mesh should be a 2D matrix of point/mask that will greatly simplify the coding:
GLfloat xyz[ys][xs][3]; bool on[ys][xs];
xyz
are the coordinates
on
is flag if the point is used or not (inside polygon)
xs,ys
is the grid resolution of the bounding box...this way you know which point neighbors which points so the draw is simple (use quad strips ... This representation is also good for the simulation. For volumes use cube grid (like voxels) or just BR model like cube surface grid ...
What to do with perimeter multi-points
on the perimeter there can be more then 1 point per grid position so merge them all together (or use the closest one to grid position). For example see the image on the right side the bottom half. The grid point is outside the polygon creating 2 intersection points. If you merge this to single one then the above structure is still enough
-
How can I fill polygon with particles? like in 3D, a cube is represented with filled particles. I need this information before the rendering so that I can calculate the interaction of fluid particles with these cube particles. – user3059007 Mar 13 '15 at 20:30
-
@user3059007 surface only or in volume too? for surface I use 3 such structures for top and bottom side and 1 for the 4 sides between them ... for 3D volume you need `xyz[zs][ys][[xs][3]` and rewrite the hit test to test if you are inside mesh or not the rest is the same ... the render of volume can be set of transluent layers or rigid cut ... – Spektre Mar 14 '15 at 09:01
-
@user3059007 also read this http://stackoverflow.com/a/22966118/2521214 for some ideas – Spektre Mar 14 '15 at 09:07