class Delaunay
{
private static int INIT_VERTICES_COUNT = 6;
private static int INIT_FACES_COUNT = 8;
private static int VECTOR_LENGTH = 1;
private static double DBL_EPSILON = 2.2204460492503131e-016;
private static List<Vector3D> _AuxiliaryDots =new List<Vector3D>(INIT_VERTICES_COUNT);
private static long[] _Statistics=new long[4];
private static List< Vector3D> _ProjectedDots=new List<Vector3D>();
static private List<Triangle> _Mesh = new List<Triangle>();
private Delaunay()
{
for (int i = 0; i < INIT_VERTICES_COUNT; i++)
{
_AuxiliaryDots.Add( new Vector3D(
(i % 2 == 0 ? 1 : -1) * (i / 2 == 0 ? VECTOR_LENGTH : 0),
(i % 2 == 0 ? 1 : -1) * (i / 2 == 1 ? VECTOR_LENGTH : 0),
(i % 2 == 0 ? 1 : -1) * (i / 2 == 2 ? VECTOR_LENGTH : 0),
true, 0, 0, 0
));
}
}
static double GetDistance(Vector3D v0, Vector3D v1)
{
return Math.Sqrt(Math.Pow((v0.X- v1.X), 2) +
Math.Pow((v0.Y - v1.Y), 2) + Math.Pow((v0.Z - v1.Z), 2));
}
static void RemoveExtraTriangles()
{
for (int i=0;i< _Mesh.Count;i++)
{
bool isExtraTriangle = false;
for (int j = 0; j < 3; j++)
{
if (_Mesh[i].Vertex[j].IsAuxiliaryDot)
{
isExtraTriangle = true;
break;
}
}
if (isExtraTriangle)
{
_Mesh.RemoveAt(i);
i--;
}
}
}
public static List<Tuple<int,int,int>> GetTriangulationResult(ref List<Vector3D> dots)
{
for (int i = 0; i < INIT_VERTICES_COUNT; i++)
{
_AuxiliaryDots.Add( new Vector3D(
(i % 2 == 0 ? 1 : -1) * (i / 2 == 0 ? VECTOR_LENGTH : 0),
(i % 2 == 0 ? 1 : -1) * (i / 2 == 1 ? VECTOR_LENGTH : 0),
(i % 2 == 0 ? 1 : -1) * (i / 2 == 2 ? VECTOR_LENGTH : 0),
true, 0, 0, 0
));
}
//_Statistics[2] = clock();
for (int i=0;i<dots.Count;i++)
{
Vector3D projectedDot = new Vector3D(dots[i],VECTOR_LENGTH);
_ProjectedDots.Add(projectedDot);
}
BuildInitialHull(ref _ProjectedDots);
for (int i=0;i<_ProjectedDots.Count;i++)
{
Vector3D dot = _ProjectedDots[i];
if (!dot.IsVisited)
{
InsertDot(dot);
}
}
// remove trianges connected with auxiliary dots
RemoveExtraTriangles();
// generate output
List<Tuple<int, int, int>> mesh = new List<Tuple<int, int, int>>();
for
三维---三角网生成算法
最新推荐文章于 2024-06-08 11:05:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)