Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Intersection between plane and triangle through the same three points

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Intersection between plane and triangle through the same three points


Chronological Thread 
  • From: Marc Glisse <>
  • To: Marc Alexa <>
  • Subject: Re: [cgal-discuss] Intersection between plane and triangle through the same three points
  • Date: Tue, 18 May 2021 12:26:35 +0200 (CEST)
  • Ironport-hdrordr: A9a23:tqhPV61sNEoIsfe8Xx5X+gqjBKckLtp133Aq2lEZdPUzSL38qynOpoV46faasl0ssR0b8+xofZPvfZq+z+8X3WByB9aftWDd0QOVxcNZjbcKpQeMJ8SUzIFgPMlbH5RDNA==

On Tue, 18 May 2021, Marc Alexa wrote:

I think I just now fully understood the consequences of “inexact constructions”. It does lead to some interesting results, I have to say. I put a minimal program together that generates such a result, which is of course unsurprising in general, but still a bit surprising to me for the ‘exact predicates’ statement.

Indeed, it computes an exact predicate on a wrong plane, so not the result you expect. It would be possible to define your own plane type that stores a triangle, here is a quick hack based on your code (no guarantee, and I didn't handle Line_3) where the construction of an inexact Plane_3 is done inside a predicate and thus safe. Although do_intersect is not the best example of how CGAL does predicates, some of the overloads are unusual.


#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/intersections.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 Point;
typedef K::Line_3 Line;
typedef K::Plane_3 Plane;
typedef K::Triangle_3 Triangle;

struct My_plane { Point p[3]; bool has_on(Point const&q)const{return
CGAL::orientation(p[0],p[1],p[2],q)==CGAL::COPLANAR;}};
template<class Ker>
struct My_inter {
typedef typename Ker::Boolean result_type;
template<class Obj>
auto operator()(typename Ker::Point_3 const&p0, typename Ker::Point_3 const&p1,
typename Ker::Point_3 const&p2, Obj const&o)const{
typename Ker::Plane_3 p(p0, p1, p2);
return typename Ker::Do_intersect_3()(p, o);
}
};
template<class Obj>
inline bool my_do_intersect(My_plane const&p, Obj const&o) {
return CGAL::Filtered_predicate<My_inter<K::Exact_kernel>,
My_inter<K::Approximate_kernel>, K::C2E, K::C2F>()(p.p[0], p.p[1], p.p[2], o);
}

int main()
{
Point V0(1.0,0.3,0.7);
Point V1(0.3,1.1,0.2);
Point V2(3.3,4.7,5.1);

My_plane p{V0,V1,V2};

std::cerr << "V0 on plane? " << p.has_on(V0) << std::endl;
std::cerr << "V1 on plane? " << p.has_on(V1) << std::endl;
std::cerr << "V2 on plane? " << p.has_on(V2) << std::endl;

Triangle t(V0,V1,V2);

std::cerr << "Triangle intersects plane? " << my_do_intersect(p,t) <<
std::endl;

Line l(V0,V1);
std::cerr << "V0 on line? " << l.has_on(V0) << std::endl;
std::cerr << "V1 on line? " << l.has_on(V1) << std::endl;

std::cerr << "Triangle intersects line? " << CGAL::do_intersect(l,t) <<
std::endl;

std::cerr << "Plane intersects line? " << my_do_intersect(p,l) <<
std::endl;

return 0;
}


--
Marc Glisse



Archive powered by MHonArc 2.6.19+.

Top of Page