[英]Find triangles on exterior of 3D object
I am trying to take a set of vertices (vi = xi,yi,zi) and make a solid object out of them. 我正在尝试获取一组顶点(vi = xi,yi,zi),并从中创建一个固体对象。 To draw the object, I use triangles, so I need to find a set of triangles t = v1, v2, v3, which forms a solid surface.
要绘制对象,我使用三角形,因此我需要找到一组三角形t = v1,v2,v3,它们形成一个实体曲面。
I know that if I construct every possible triangle from the vertices, I will see a solid surface, but this wastes a lot of resources on triangles which are hidden in the interior of the object, and calculating them all costs O(N^3) where N is the number of vertices. 我知道,如果我从顶点构造每个可能的三角形,我会看到一个实体表面,但是这浪费了隐藏在对象内部的三角形上的大量资源,并计算所有成本为O(N ^ 3)其中N是顶点数。 How do I find the triangles only on the exterior?
如何仅在外部找到三角形?
Here is my code (java) to generate all the triangles in an object with random vertices. 这是我的代码(java),用于在具有随机顶点的对象中生成所有三角形。
public class myObject {
public ArrayList<float[]> Vertex_Coords;
ArrayList<float[]> Vertex_Colors;
ArrayList<int[]> triangles;
public myObject() {
Vertex_Colors = new ArrayList<float[]>();
Vertex_Coords = new ArrayList<float[]>();
triangles = new ArrayList<int[]>();
addball(20);
}
public void addvertex() {
float[] coords = new float[3];
float[] colors = new float[4];
int i;
for (i = 0; i < 3; i++)
coords[i] = maxModelSize * ((float) Math.random()-0.5f);
for (i = 0; i < 4; i++)
colors[i] = (float) Math.random();
Vertex_Coords.add(coords);
Vertex_Colors.add(colors);
}
public void addball(int numpoints)
{
int i;
for(i = 0;i<numpoints;i++)
{
addvertex(false,true);
}
connectalltriangles();
}
public void connectalltriangles()
{
int i,j,k;
int [] tri;
for(i=0;i<Vertex_Coords.size();i++)
for(j=i+1;j<Vertex_Coords.size();j++)
for(k=j+1;k<Vertex_Coords.size();k++)
{
tri = new int[3];
tri[0]=i;
tri[1]=j;
tri[2]=k;
triangles.add(tri);
}
}
} }
What you exactly need is a Convex Hull algorithm, if you are sure if your geometry is always convex. 如果您确定几何图形始终是凸形的,那么您真正需要的是Convex Hull算法。
Convex Hull: This algorithm creates a mesh by connecting only the outermost vertices of a given set of points in 3d space. 凸包:此算法通过仅连接3d空间中一组给定点的最外顶点来创建网格。 Obviously you will loose the vertices which are inside the convex structure and will not be used in any triangles.
显然,您将失去凸结构内部的顶点,并且这些顶点将不会在任何三角形中使用。 This only works for convex shapes.
这仅适用于凸形。
Below is a good example for a convex hull construction. 下面是凸包构造的一个很好的例子。
There are many Libraries that implement Convex hulling algorithm. 有许多实现凸包算法的库。 Ex: CGAL, BulletPhysics and OpenMesh.
例如:CGAL,BulletPhysics和OpenMesh。 If you are looking for a quick way to build a convex hull, QuickHull is the best place.
如果您正在寻找构建凸包的快速方法,则QuickHull是最佳选择。 http://www.qhull.org
http://www.qhull.org
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.