cgal demo

[判断一条二维直线与二维Delaunay的交点数量(C)]

#include<vector>
#include<algorithm>
#include<CGAL/point_generators_2.h>
#include<CGAL/algorithm.h>
#include<CGAL/random_selection.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include<CGAL/Delaunay_triangulation_2.h>
#include <CGAL/intersections.h>

#ifdef CGAL_USE_BASIC_VIEWER	
#include <CGAL/draw_triangulation_2.h>
#endif

using namespace CGAL;

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point;
typedef Kernel::Line_2 Line;
typedef Kernel::Segment_2 Segment;
typedef Kernel::Intersect_2 Intersect_2;
typedef Creator_uniform_2<double, Point> Creator;
typedef std::vector<Point> Vector;
typedef CGAL::Delaunay_triangulation_2<Kernel> Delaunay;
typedef Delaunay::Vertex_iterator Vertex_iterator;
typedef Delaunay::Vertex_handle Vertex_handle;
typedef Delaunay::Edge_iterator Edge_iterator;
typedef Delaunay::Face_iterator Face_iterator;


int main() {
	Vector points;
	points.reserve(10);

	Random_points_in_disc_2<Point, Creator> g(150.0);
	CGAL::cpp11::copy_n(g, 10, std::back_inserter(points));

	Delaunay dt;

	dt.insert(points.begin(), points.end());
	

	//�������ɶ�άƽ�������㹹��һ��ֱ��
	Vector lpoints;
	lpoints.reserve(2);

	Random_points_in_disc_2<Point, Creator> g1(150.0);
	CGAL::cpp11::copy_n(g1, 2, std::back_inserter(lpoints));

	std::cout << "Line is:" << std::endl;
	std::cout << "(" << lpoints[0].x() << "," << lpoints[0].y() << ")"<< "(" << lpoints[1].x() << "," << lpoints[1].y() << ")" << std::endl;
	Line l(lpoints[0], lpoints[1]);

	std::vector<Segment> tri_edges;


	//�����ߣ��߹����߶�
	std::cout << "Edges are:" << std::endl;
	for (Edge_iterator eg = dt.edges_begin(); eg != dt.edges_end(); eg++) {
		Vertex_handle f_v1 = eg->first->vertex(dt.cw(eg->second));
		Vertex_handle f_v2 = eg->first->vertex(dt.ccw(eg->second));
		Point p1 = f_v1->point();
		Point p2 = f_v2->point();
		std::cout << "(" << p1.x() << "," << p1.y() << ")" << "(" << p2.x() << "," << p2.y() << ")" << std::endl;
		Segment temp_l(p1, p2);
		tri_edges.push_back(temp_l);
	}
	
	//��ֱ����ÿ�����߶εĽ���
	std::cout << "intersection points are:" << std::endl;
	int intersection_number = 0;
	for (int i = 0; i < tri_edges.size(); i++) {
		CGAL::cpp11::result_of<Intersect_2(Line, Segment)>::type
			result = intersection(l, tri_edges[i]);
		if (result)
		{
			const Point* p = boost::get<Point>(&*result);
			std::cout << *p << std::endl;
			intersection_number++;
		}
	}
	std::cout << "intersection points number is:" << intersection_number << std::endl;


	return EXIT_SUCCESS;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lst0426

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值