计算几何算法库 CGAL 编译

最近需要开发图形学上一系列算子,如果用C++写原始函数,觉得太慢,故从网上下载CGAL源码编译。

CGAL ,计算几何算法库,是一个大型C + +库的几何数据结构和算法,如Delaunay三角网,网格生成,布尔运算的多边形,以及各种几何处理算法。 CGAL是用来在各个领域:计算机图形学,科学可视化,计算机辅助设计与建模,地理信息系统,分子生物学,医学影像学...

下载的是最新版本 CGAL-4.14-beta2,网址 https://www.cgal.org/download.html

我的开发环境 Visual Studio 2015,boost_1_69_0,CMake 3.13.2

参考此文 https://blog.csdn.net/jaggerjack330/article/details/84874711 进行源码编译(折磨许久,与文中编译稍微不同,直到CMake无错时才能打开项目)

完成后编写示例如下:

// cgalDemo.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"


#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/intersections.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef K::Segment_2 Segment_2;
typedef K::Line_2 Line_2;
typedef K::Intersect_2 Intersect_2;

int main()
{
    Segment_2 seg(Point_2(0, 0), Point_2(2, 2));
    Line_2 lin(-1, -1, 1);
    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)) {
            std::cout << *s << std::endl;
        }
        else {
            const Point_2* p = boost::get<Point_2 >(&*result);
            std::cout << *p << std::endl;
        }
    }

    return 0;
}

目的是求线段与直线相交,线段由两点组成容易理解,但直线不好理解,查阅资料得知其中直线定义如下:

CGAL::Line_2< Kernel > Class Template Reference

2D and 3D Linear Geometry Kernel Reference » 2D Kernel Objects

#include <CGAL/Line_2.h>

Definition

An object l of the data type Line_2 is a directed straight line in the two-dimensional Euclidean plane E2.

It is defined by the set of points with Cartesian coordinates (x,y) that satisfy the equation

l:ax+by+c=0.

The line splits E2 in a positive and a negative side. A point p with Cartesian coordinates (px,py) is on the positive side of l, iff apx+bpy+c>0, it is on the negative side of l, iff apx+bpy+c<0. The positive side is to the left of l.

Example

Let us first define two Cartesian two-dimensional points in the Euclidean plane E2. Their dimension and the fact that they are Cartesian is expressed by the suffix _2 and the representation type Cartesian.

Point_2< Cartesian<double> > p(1.0,1.0), q(4.0,7.0);

To define a line l we write:

Line_2< Cartesian<double> > l(p,q);

由此看来 Line_2 lin(-1, -1, 1)代表的直线是 -x-y+1=0

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值