用c++实现Delaunay三角剖分

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Delaunay三角剖分

void main(PointLink *ptUpOutline, PointLink *ptDownOutline)

{

//首先分别对上下轮廓线的点集进行三角化,ptUpOutline, ptDownOutline为对应点集TrianglizationInPlan(ptUpOutline) ;

TrianglizationInPlan(ptDownOutline) ;

//根据两层三角化的结果进行Delaunay剖分,得到四面体链表

GetTetrahedron( UpTriangle , DownTriangle ) ;

//后处理用于删除不正确的四面体

PostProcess() ;

}

其中:

1.函数TrianglizationInPlan()用于平面三角化

void TrianglizationInPlan( PointLink * Head )

{

//对不符合Delaunay剖分的边进行细分

bool Over = 1;

while( Over )

{

First = Head ;

Second = First->next ;

while( Second ){

if( !NotIncludeOtherPoint( First->Point , Second->Point , Head ) ){

PointLink* Point = new PointLink ;

First->next = Point ;

Point->next = Second ;

Over = false ;

}

First = Second ;

Second = Second->next ;

}

}

//对平面进行三角化,保存结果到TriangleLink的链表

Trianglization( Head ) ;

}

2.函数GetTetrahedron()进行Delaunay剖分得到四面体链表

void GetTetrahedron( TriangleLink * First, TriangleLink * Second )

Cur = First ;

while( Cur ){

Temp1 = Cur->Triangle ;

Center = GetCenter( Temp1 ) ;

Cur = ContourUp ;

while( Cur ){

//初始化min

if( Cur == ContourUp ) {

min = Center.distance( Cur->Point ) ;

Value = min ;

Result = Cur->Point ;

}

//找距离最小的点

else {

Value = Center.distance( Cur->Point ) ;

if( min > Value ){

min = Value ;

Result = Cur->Point ;

}

}

Cur = Cur->next ;

}

TetrahedronLink *T1 = new TetrahedronLink ;

T1->volume.Point[0] = Cur->Triangle.Point[0] ;

T1->volume.Point[1] = Cur->Triangle.Point[1] ;

T1->volume.Point[2] = Cur->Triangle.Point[2] ;

T1->volume.Point[3] = Result ;

T1->type = 1 ;

ResultCur->next = T1 ;

T1->next = 0 ;

ResultCur = T1 ;

Cur = Cur->next ;

}

Cur = Second ;

while( Cur ){

Temp1 = Cur->Triangle ;

Center = GetCenter( Temp1 ) ;

//逐个比较找到离圆心最近的点

Cur = ContourDown ;

while( Cur ){

//初始化min

if( Cur == ContourDown ){

min = Center.distance( Cur->Point ) ;

Value = min ;

Result = Cur->Point ;

}

else //找距离最小的点{

Value = Center.distance( Cur->Point ) ;

if( min > Value ){

min = Value ;

Result = Cur->Point ;

}

}

Cur = Cur->next ;

}

TetrahedronLink *T2 = new TetrahedronLink ;

T2->volume.Point[0] = Cur->Triangle.Point[0] ;

T2->volume.Point[1] = Cur->Triangle.Point[1] ;

T2->volume.Point[2] = Cur->Triangle.Point[2] ;

T2->volume.Point[3] = Result ;

T2->type = 2 ;

ResultCur->next = T2 ;

T2->next = 0 ;

ResultCur = T2 ;

Cur = Cur->next ;

}

EdgeCur1 = EdgeUp ;

EdgeCur2 = EdgeDown ;

Edge tempEdge1 , tempEdge2 ;

while( EdgeCur1 ){

tempEdge1 = EdgeCur1->line ;

while( EdgeCur2 ){

tempEdge2 = EdgeCur2->line ;

//判断两条边投影是否相交

if( EdgesIntersect( tempEdge1 , tempEdge2 ) ){

TetrahedronLink *T12 = new TetrahedronLink ;

T12->volume.Point[0] = tempEdge1.Start ;

T12->volume.Point[1] = tempEdge1.End ;

T12->volume.Point[2] = tempEdge2.Start ;

T12->volume.Point[3] = tempEdge2.End ;

T12->type = 12 ;

ResultCur->next = T12 ;

T12->next = 0 ;

ResultCur = T12 ;

}

相关文档
最新文档