请给我C++具体代码,来实现输入三维点坐标后通过CGAL中的Delaunay Triangulation完成三角剖分
时间: 2024-05-23 07:14:58 浏览: 16
好的,以下是C语言的代码实现:
#include <stdio.h>
#include <stdlib.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_3<K> DT;
typedef K::Point_3 Point;
int main() {
int n;
printf("请输入点的个数n:\n");
scanf("%d", &n);
Point *points = (Point *)malloc(n * sizeof(Point));
printf("请输入%d个点的x、y、z坐标:\n", n);
for (int i = 0; i < n; i++) {
double x, y, z;
scanf("%lf%lf%lf", &x, &y, &z);
points[i] = Point(x, y, z);
}
DT dt(points, points+n);
printf("点的三角剖分结果如下:\n");
for (auto it = dt.finite_cells_begin(); it != dt.finite_cells_end(); ++it) {
printf("(%lf, %lf, %lf), (%lf, %lf, %lf), (%lf, %lf, %lf)\n",
it->vertex(0)->point().x(), it->vertex(0)->point().y(), it->vertex(0)->point().z(),
it->vertex(1)->point().x(), it->vertex(1)->point().y(), it->vertex(1)->point().z(),
it->vertex(2)->point().x(), it->vertex(2)->point().y(), it->vertex(2)->point().z());
}
free(points);
return 0;
}
注意:上面的代码使用了CGAL库来进行三角剖分,需要在编译时链接该库,例如使用gcc编译时可以使用命令:
gcc main.c -o main -lCGAL
其中main.c为包含以上代码的文件名,main为编译生成的可执行文件名,-lCGAL表示链接CGAL库。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)