Here are simple demos show how to use CGAL, the Computational Geometry Algorithms Library. I use cmake to manage these small projects.

Create Point And Vector

My project file CMakeLists.txt can be simpler for this small program. I didn’t remove some settings just because I want to use the same file for more CGAL demos.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.1...3.15)
project(CGAL_Test)

find_package(CGAL REQUIRED)

# Link with Boost.ProgramOptions (optional)
find_package(Boost QUIET COMPONENTS program_options)
if(Boost_PROGRAM_OPTIONS_FOUND)
  if(TARGET Boost::program_options)
    set(Boost_PROGRAM_OPTIONS_LIBRARY Boost::program_options)
  endif()
  if(CGAL_AUTO_LINK_ENABLED)
    message(STATUS "Boost.ProgramOptions library: found")
  else()
    message(
      STATUS "Boost.ProgramOptions library: ${Boost_PROGRAM_OPTIONS_LIBRARY}")
  endif()
  add_definitions("-DCGAL_USE_BOOST_PROGRAM_OPTIONS")
  list(APPEND CGAL_3RD_PARTY_LIBRARIES ${Boost_PROGRAM_OPTIONS_LIBRARY})
endif()

# Find Eigen3 (requires 3.1.0 or greater)
find_package(Eigen3 3.1.0)
include(CGAL_Eigen_support)

create_single_source_cgal_program( "main.cpp" CXX_FEATURES ${CMAKE_CXX11_COMPILE_FEATURES} )  #defined in CGAL_CreateSingleSourceCGALProgram.cmake

target_link_libraries(main PUBLIC CGAL::Eigen_support)

main.cpp

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

using namespace std;

typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef K::Point_3 Point_3;
typedef K::Vector_3 Vector_3;

int main()
{
    Point_2 pt1(0,0);
    cout << pt1 << endl;

    Point_3 pt2(1, 2, 3);
    cout << pt2 << endl;

    Point_3 pt3(3.0, 2.0, 1.1);
    Vector_3 vec = pt3 - pt2;
    cout << vec << endl;
    return 0;
}

Output:

0 0
1 2 3
2 -0 -1.9

Judge Orientation Of Point_2

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

using namespace std;

typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Point_2 Point_2;

int main()
{
    Point_2 pt0( 1, 0 ), pt1(1, 1), pt2( 2, 0 );
    CGAL::Sign result = CGAL::orientation( pt0, pt1, pt2 );
    cout << result << endl;
    return 0;
}

output:

-1

The result -1 means enum Sign value RIGHT_TURN.

Is Point In Circle

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

using namespace std;

typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Point_2 Point_2;

int main()
{
    Point_2 p1(0, -5), p2(3, -4), p3(4, 3), in(-1, 4), out(5, -1), on(0, 5);
    CGAL::Bounded_side inside, onside, outside;
    inside = CGAL::side_of_bounded_circle(p1, p2, p3, in);
    outside = CGAL::side_of_bounded_circle(p1, p2, p3, out);
    onside = CGAL::side_of_bounded_circle(p1, p2, p3, on);
    cout << inside << ", " << outside << ", " << onside << endl;
    return 0;
}

Output:

1, -1, 0
enum  Bounded_side
{
    ON_UNBOUNDED_SIDE = -1,
    ON_BOUNDARY,
    ON_BOUNDED_SIDE
};
Categories: CGAL

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] have used CGAL to do simple tasks, the related article: Simple Demos About Using CGAL. But those tasks work in header mode, I want to build CGAL libraries with source code and install […]

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
1
0
Would love your thoughts, please comment.x
()
x