zoukankan      html  css  js  c++  java
  • 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
    ";
            break;
        case CGAL::LEFT_TURN:
            std::cout << "point is the left of the line
    ";
            break;
        case CGAL::RIGHT_TURN:
            std::cout << "point is the right of the line
    ";
            break;
        }
    
        std::cout << "---------cal midpoint----------- " << std::endl;
        std::cout << " midpoint(p,q) = " << CGAL::midpoint(p, q) << std::endl;
        return 0;
    }
    
    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    DVI与DVI-D的区别
    easyui.combotree.search.js
    显示实时日期时间(html+js)
    Jquery 内容简介
    EasyUI 格式化DataGrid列
    EasyUI DataGrid 添加排序
    EasyUI DataGrid 复选框
    EasyUI 自定义DataGrid分页
    EasyUI DataGrid能编辑
    EasyUI 我的第一个窗口
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/13520085.html
Copyright © 2011-2022 走看看