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?
我想将立方体或多边形表示为集合粒子,这样它就可以分为空间网格。背后的原因是我想计算流体粒子(SPH技术)与建筑物,地形等固体物体的碰撞。如何将实体对象表示为粒子集合?
1 个解决方案
#1
1
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:
网格应该是点/掩模的2D矩阵,这将极大地简化编码:
GLfloat xyz[ys][xs][3]; bool on[ys][xs];
xyz
are the coordinateson
is flag if the point is used or not (inside polygon)xs,ys
is the grid resolution of the bounding box...如果使用或不使用点,则xyz是is标志(在多边形内部)xs,ys是边界框的网格分辨率...
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 ...
通过这种方式,您可以知道哪个点相邻哪个点,因此绘制很简单(使用四条带...这种表示也适用于模拟。对于体积使用立方体网格(如体素)或BR模型像立方体表面网格...
-
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
在周边,每个网格位置可以有多于1个点,因此将它们合并在一起(或使用最接近的网格位置)。例如,请看右下方的图像。网格点位于多边形外部,创建2个交叉点。如果将其合并为单个,那么上述结构仍然足够
#1
1
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:
网格应该是点/掩模的2D矩阵,这将极大地简化编码:
GLfloat xyz[ys][xs][3]; bool on[ys][xs];
xyz
are the coordinateson
is flag if the point is used or not (inside polygon)xs,ys
is the grid resolution of the bounding box...如果使用或不使用点,则xyz是is标志(在多边形内部)xs,ys是边界框的网格分辨率...
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 ...
通过这种方式,您可以知道哪个点相邻哪个点,因此绘制很简单(使用四条带...这种表示也适用于模拟。对于体积使用立方体网格(如体素)或BR模型像立方体表面网格...
-
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
在周边,每个网格位置可以有多于1个点,因此将它们合并在一起(或使用最接近的网格位置)。例如,请看右下方的图像。网格点位于多边形外部,创建2个交叉点。如果将其合并为单个,那么上述结构仍然足够