cgal 的初步学习


简介

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;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM