CGAL求三角形交线的bug

求三角形交线时候错误

3dface
-1.2251099999999999,-5.8899699999999999,-7.987949999999999
0.40490799999999999,-6.0014500000000002,-3.314319999999999
-1.2251099999999999,-5.8899699999999999,-3.314319999999999


3dface
-0.21243100000000001,-5.7414293000000001,-4.50379500000000
-0.15238699999999999,-6.0416264999999996,-4.51681199999999
-0.56714299999999995,-5.9451375000000004,-4.37800200000000

对以上2个三角形使用CGAL::intersection(triA, triB);,并不能找到交线,实际上是存在交线的,跟入cagl的内部代码查看

1.首先会找到三角形平面的交线

2.判断三角形的3个点在交线的哪一侧

Triangle_Line_Inter inter1 = intersection_coplanar(t1,*line,k);下的

const Orientation pqa = coplanar_orientation(p,q,a);
  const Orientation pqb = coplanar_orientation(p,q,b);
  const Orientation pqc = coplanar_orientation(p,q,c);

函数coplanar_orientationC3中直接先从x开始判断,然后y,然后z

x的微小容差会导致结果判断失败。

kernel_ftC3.h 194行的函数改为

    template < class FT >
    CGAL_KERNEL_MEDIUM_INLINE
        typename Same_uncertainty_nt<Orientation, FT>::type
        coplanar_orientationC3(const FT& px, const FT& py, const FT& pz,
            const FT& qx, const FT& qy, const FT& qz,
            const FT& rx, const FT& ry, const FT& rz)
    {
        typedef typename Same_uncertainty_nt<Orientation, FT>::type  Ori;
        FT num[3] =
        {
            determinant(qx - px, qy - py, rx - px, ry - py),
            determinant(qy - py, qz - pz, ry - py, rz - pz),
            determinant(qx - px, qz - pz, rx - px, rz - pz)
        };

        FT fnum[3];
        for (int i = 0; i < 3; ++i)
        {
            fnum[i] = num[i] > 0 ? num[i] : -num[i];
        }
        int inx = fnum[1] > fnum[0] ? 1 : 0;

        inx = fnum[inx] > fnum[2] ? inx : 2;


        return enum_cast<Sign>(CGAL_NTS compare(num[inx], 0));
        /*    Ori oxy_pqr = orientationC2(px, py, qx, qy, rx, ry);
            if (oxy_pqr != COLLINEAR)
                return oxy_pqr;

            Ori oyz_pqr = orientationC2(py, pz, qy, qz, ry, rz);
            if (oyz_pqr != COLLINEAR)
                return oyz_pqr;

            return orientationC2(px, pz, qx, qz, rx, rz);*/
    }后正确

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值