1 CGAL overview
Computational Geometry Algorithms Library (CGAL) is a C + + algorithm library, which provides efficient and reliable geometric algorithms.
CGAL provides many data structures and algorithms, such as triangulation( triangulations ). Voronoi diagram( Voronoi diagrams ), polygon( Polygons ), unit complex and polyhedron( Cell Complexes and Polyhedra ). curve arrangement( arrangements of curves ), grid generation( mesh generation )Geometric processing( geometry processing )Convex hull algorithm( convex hull algorithms )Wait.
All these data structures and algorithms operate on geometric objects such as points and segments, and test them geometrically. These objects and predicates are in the CGAL kernel( CGAL Kernels )Regroup in.
Finally, support library( Support Library )It provides geometric object generator and spatial sorting functions, as well as matrix search framework and solvers for linear and quadratic programming. It also provides interfaces with third-party software, such as GUI library Qt, Geomview and Boost graphics library.
2 install CGAL from the Source Archive
2.1 CGAL Download
CGAL-5.3.1.zip download address: https://github.com/CGAL/cgal/releases
Cgal-5.3.1. To be downloaded Zip and put it in a path, here in the following path
D:\Program Files\CGAL-5.3.1
2.2 GMP and MPRF installation
Pre compiled versions of GMP and MPFR are provided in Assets, which are suitable for Windows 64 bit. If we install these libraries only to use CGAL, we should install CGAL-5.3.1-win64-auxiliary-libraries-gmp-MPFR Unzip the zip file, and then add and copy the auxiliary folder to the unzipped directory of CGAL-5.3.1.
Since the auxiliary folder is already included in the CGAL-5.3.1 directory, you can directly replace it here.
2.3 boost installation and environment variable setting
2.3.1 boost installation
Boost is a mandatory dependency of CGAL. SourceForge The binary version of Boost is provided on (this version can be used directly without compilation). The Boost installer installs both the Boost header file and the precompiled library. When CGAL 5.3.1 was released, the latest version of Boost was 1.71 (as of January 20, 2022, the latest version of Boost was 1.78.0).
VS and boost version correspondenceVS | boost |
---|---|
vs2015 | boost-msvc-14.0 |
vs2017 | boost-msvc-14.1 |
vs2019 | boost-msvc-14.2 |
Install boot1.0 with VS2017 78.0 as an example, install boost as follows:
1) Download and run boost_1_78_0-msvc-14.1-64.exe file, select the installation directory
2) Click Next > to install
3) Click Finish to complete the installation.
2.3.2 environment variable setting
Open the control panel, search for "advanced" and select "view advanced system settings" under "system"
Select environment variables
If you want to set this user, select new in user variable; If you want to be valid for all users, select the system variable.
Both options, the operation is the same. Take "user variable" as an example:
Select new under user variable to open the new user variable dialog box
Set the variable name and variable value in turn
BOOST_LIBRARYDIR = D:\Program Files\libboost_1_78_0\lib64-msvc-14.1
BOOST_INCLUDEDIR = D:\Program Files\libboost_1_78_0
Finally, add the path of the boost dll file (subject to your own path) to the path environment variable: double click path in user variables to open the edit environment variable dialog box
Click new to paste the path of the boost dll file
D:\Program Files\boost_1_78_0\lib64-msvc-14.1
3 VS property sheet configuration
1) Open vs2017 and click "file - > New - > new project - > empty project" in the upper left corner
2) Select "attribute Manager - > debug | x64" and right-click "add new project attribute table" (once and for all, you can call it directly when creating a new project in the future without reconfiguration)
3) Double click the new property sheet to add the included directory
Add the following path to "general properties - > VC + + Directory - > include directory"
D:\Program Files\CGAL-5.3.1\include
D:\Program Files\CGAL-5.3.1\auxiliary\gmp\include
D:\Program Files\boost_1_78_0
4) Add Library Directory
Add the following path to "general properties - > VC + + Directory - > Library Directory"
D:\Program Files\CGAL-5.3.1\auxiliary\gmp\lib
D:\Program Files\boost_1_78_0\libs
5) Add additional dependencies (lib file under D:\Program Files\CGAL-5.3.1\auxiliary\gmp\lib)
Paste the following file name into "general properties - > linker - > input > additional dependencies"
libgmp-10.lib libmpfr-4.lib
4 test code
code:
#include <iostream> #include <CGAL/Simple_ cartesian. h> // Cartesian coordinate correlation header file using namespace std; typedef CGAL::Simple_cartesian<double> Kernel; typedef Kernel::Point_2 Point_2; typedef Kernel::Segment_2 Segment_2; int main() { //Define two 2D points Point_2 p(1, 1), q(10, 10); cout << "p = " << p << endl; cout << "q = " << q.x() << " " << q.y() << endl; //Square distance between two points double sqDist_pq; sqDist_pq = CGAL::squared_distance(p, q); cout << "->Square distance between two points:"<< CGAL::squared_distance(p, q) << endl; //Midpoint of two points cout << "->Midpoint between two points:" << CGAL::midpoint(p, q) << endl; //Two points define a straight line Segment_2 s(p, q); Point_2 m(5, 9); cout << "m = " << m << endl; //Distance from point to line double sqDist_sm; sqDist_sm = CGAL::squared_distance(s, m); cout << "->Distance from point to line" << sqDist_sm << endl; //Judge the relationship between the three points cout << "p, q, and m The relationship between the three points is:"; switch (CGAL::orientation(p, q, m)) { case CGAL::COLLINEAR: cout << "Three points collinear\n"; break; case CGAL::LEFT_TURN: cout << "Three points make a left turn\n"; break; case CGAL::RIGHT_TURN: cout << "Three points make a right turn\n"; break; } return 0; }
Output results:
p = 1 1 q = 10 10 ->Square distance between two points: 162 ->Midpoint between two points: 5.5 5.5 m = 5 9 ->Distance from point to line 8 ->p, q, and m The relationship between the three points is: three points constitute a left turn