cgal demo

该代码示例展示了使用CGAL库进行精确几何计算,包括点、线段和直线的构造、距离计算以及交点检测。在处理交点时,出现了结果在不同环境中输出不一致的问题,特别是涉及到浮点数精度时。代码中尝试使用精确构造内核来解决精度不足的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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;
//#pragma comment(lib, "gmp.dll")
#include <iostream>

#include "gmp.h"

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/intersections.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Point_2 Point_21;
typedef K::Line_2 Line_2;
typedef K::Intersect_2 Intersect_2;
using namespace std;
int main()
{
    std::cout << "Hello World!\n";
    //std::cout << __cplusplus << _MSVC_LANG << BOOST_MSVC << std::endl;
    Point_2 p(1, 1), q(10, 10);
    std::cout << "p = " << p << std::endl;
    std::cout << "q = " << q.x() << " " << q.y() << std::endl;
    std::cout << "sqdist(p,q) = "
        << CGAL::squared_distance(p, q) << std::endl;
    Segment_2 s(p, q);
    Point_2 m(5, 9);
    std::cout << "m = " << m << std::endl;
    std::cout << "sqdist(Segment_2(p,q), m) = "
        << CGAL::squared_distance(s, m) << std::endl << __cplusplus << std::endl;
    std::cout << "p, q, and m ";
    switch (CGAL::orientation(p, q, m)) {
    case CGAL::COLLINEAR:
        std::cout << "are collinear\n";
        break;
    case CGAL::LEFT_TURN:
        std::cout << "make a left turn\n";
        break;
    case CGAL::RIGHT_TURN:
        std::cout << "make a right turn\n";
        break;
    }

    Line_2 lina(1, 1, 2);
    Line_2 linb(1, -1, 1);
    CGAL::cpp11::result_of<Intersect_2(Line_2, Line_2)>::type
        result = intersection(lina, linb);
    if (result)
    {
        const Point_21* p = boost::get<Point_21 >(&*result);
        std::cout << "ok\n";
        //std::cout << "q = " << p->x() << " " << p->y() << std::endl;
        //std::cout << *p << std::endl;
        std::cout << p->x() << ", " << p->y() << std::endl;
    }
    system("pause");
    
    
    return 0;
}

出现的问题

if (result)
    {
        const Point_21* p = boost::get<Point_21 >(&*result);
        std::cout << "ok\n";
        //std::cout << "q = " << p->x() << " " << p->y() << std::endl;
        //std::cout << *p << std::endl;
        std::cout << p->x() << ", " << p->y() << std::endl;
        acutPrintf(_T("\n%f %f"), p->x(),p->y() );
    }

这里输出的是-1.5,-0.5
但是到arx里面输出的都是0.又遇到奇葩恶心人的问题了。这样也用不了啊,
acutPrintf(_T(“\n%f %f”), p->x(),p->y() );这句输出全是0

typedef CGAL::Exact_predicates_exact_constructions_kernel K;这里不用精确的模型。用一般进度的结果到时对的,但是怕精度不够

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lst0426

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值