cgal 的初步學習
阿新 • • 發佈:2020-08-17
簡介
cgal 其實說白了就是一個封裝好的圖形學計算庫。因為有很多函式我們經常用到為什麼不把他們封裝好呢?
https://www.cgal.org/ 官網
https://blog.csdn.net/a15005784320/article/details/101346916 比較好的中文教程頁面
安裝
安裝windows下可執行檔案
安裝這兩個好了
測試
編寫cmakelists.txt
cmake_minimum_required(VERSION 3.1.0) project(cgalc) SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "D:/code/1TopTopic/boost_1_74_0/boost_1_74_0") SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "D:/code/1TopTopic/boost_1_74_0/boost_1_74_0/stage/lib") find_package(CGAL REQUIRED) include(${CGAL_USE_FILE}) add_executable(${PROJECT_NAME} "main.cpp") target_link_libraries(${PROJECT_NAME} ${CGAL_LIBS})
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "D:/code/1TopTopic/boost_1_74_0/boost_1_74_0")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "D:/code/1TopTopic/boost_1_74_0/boost_1_74_0/stage/lib")
這兩句是自己加的如果boost沒有安裝的預設的位置那麼就要明確指出來
#include <iostream> #include <CGAL/Simple_cartesian.h> typedef CGAL::Simple_cartesian<double> Kernel; typedef Kernel::Point_2 Point_2; typedef Kernel::Segment_2 Segment_2; int main() { Point_2 p(1, 1), q(10, 10), m(5, 9); Segment_2 s(p, q); std::cout << "p position:" << p << std::endl; std::cout << "q position:" << q.x() << " " << q.y() << std::endl; std::cout << "m position:" << m << std::endl; std::cout << "---------cal Euclid ^2 ----------- " << std::endl; std::cout << "point distance(p,q) = " << CGAL::squared_distance(p, q) << std::endl; std::cout << "---------cal Euclid ^2----------- " << std::endl; std::cout << "(line point(p,q), m) = " << CGAL::squared_distance(s, m) << std::endl; std::cout << "---------check the relationship of the point and the line----------- " << std::endl; std::cout << "p, q, m "; switch (CGAL::orientation(p, q, m)) { case CGAL::COLLINEAR: std::cout << "point in the line\n"; break; case CGAL::LEFT_TURN: std::cout << "point is the left of the line\n"; break; case CGAL::RIGHT_TURN: std::cout << "point is the right of the line\n"; break; } std::cout << "---------cal midpoint----------- " << std::endl; std::cout << " midpoint(p,q) = " << CGAL::midpoint(p, q) << std::endl; return 0; }