CGAL学习记录

1 篇文章 0 订阅

说明

1.学习CGAL中点对象,先对象,多边形对象的构造;
2.学习如何获取相交对象,并打印输出;

重点

相交结果的返回类型为:

CGAL::cpp11::result_of<Kernel::Intersect_2(A, B)>::type, 等价于boost::optional< boost::variant< T… > >
不相交时类型为:boost::optional,相交时(a point or segment)类型为:boost::variant

As explained in the boost manual pages for boost::variant, there are two ways to access the variants. The first examples uses boost::get.

代码

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2									  Point_2;
typedef Kernel::Line_2								      Line_2;
typedef Kernel::Segment_2								  Segment_2;
typedef Kernel::Intersect_2								  Intersect_2;
typedef CGAL::Polygon_2<Kernel>							  Polygon_2;

#include "print_utils.h"

using namespace std;

int main()
{
	Segment_2 seg(Point_2(0, 0), Point_2(2, 2));
	Line_2 lin(1, 1, 0);

	CGAL::cpp11::result_of<Intersect_2(Segment_2, Line_2)>::type
		result = intersection(seg, lin);
	if (result)
	{
		if (const Segment_2* s = boost::get<Segment_2>(&*result))
		{
			cout << *s << endl;
		}
		else
		{
			const Point_2* p = boost::get<Point_2>(&*result);
			cout << *p << endl;
		}
	}
	return 0;
}

参考:
2D and 3D Linear Geometry Kernel
learnCGAL

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值