Subject: CGAL users discussion list
List archive
- From: Samer Afach <>
- To:
- Subject: [cgal-discuss] Tetrahedron-Polyhedron problem
- Date: Fri, 12 Mar 2010 17:15:08 +0100
Hello :),
I'm starting to create some simply polyhedra in order to go to bigger
applications, and so I'm trying to understand how this library works
with it.
I have a problem, the problem is that I'm failing to create 4 triangles
and form a tetrahedron from them. I'm avoiding using the function
Polyhedron::make_tetrahedron(...) because my aim in the future is
creating random polyhedra by combining triangles and check whether they
are closed and fulfill some conditions. Here's my program:
#include <CGAL/Homogeneous.h>
#include <CGAL/Polyhedron_traits_with_normals_3.h>
#include <CGAL/Polyhedron_3.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct Normal_vector
{
template <class Facet>
typename Facet::Plane_3 operator()( Facet& f) {
typename Facet::Halfedge_handle h = f.halfedge();
// Facet::Plane_3 is the normal vector type. We assume the
// CGAL Kernel here and use its global functions.
return CGAL::cross_product(
h->next()->vertex()->point() - h->vertex()->point(),
h->next()->next()->vertex()->point() - h->next()->vertex()->point());
}
};
typedef CGAL::Homogeneous<int> Kernel;
typedef Kernel::Point_3 Point_3;
typedef Kernel::Vector_3 Vector_3;
typedef CGAL::Polyhedron_traits_with_normals_3<Kernel> Traits;
typedef CGAL::Polyhedron_3<Traits> Polyhedron;
typedef Polyhedron::Halfedge_handle Halfedge_handle;
int main() {
Point_3 p( 1, 0, 0);
Point_3 q( 0, 1, 0);
Point_3 r( 0, 0, 1);
Point_3 s( 0, 0, 0);
Polyhedron P;
//P.make_tetrahedron( p, q, r, s);
P.make_triangle(p,q,r);
P.make_triangle(p,r,s);
P.make_triangle(p,s,q);
P.make_triangle(q,s,r);
if(P.is_closed())
{
cout<<"It's closed"<<endl;
}
if(P.is_pure_trivalent())
{
cout<<"Trivalent"<<endl;
}
std::transform( P.facets_begin(), P.facets_end(), P.planes_begin(),
Normal_vector());
CGAL::set_pretty_mode( std::cout);
std::copy( P.planes_begin(), P.planes_end(),
std::ostream_iterator<Vector_3>( std::cout, "\n"));
return 0;
}
I copied this program from a sample in the manual. What's confusing me
is that when I create a tetrahedron using the make_tetrahedron function,
the conditions work fine, but I can't get the same output when creating
a tetrahedron by "connecting" 3 dimensional triangles. I was even
careful having the same output as the example (same order for the norms)
Could anyone please tell me why that's happening, and I would appreciate
it so much if someone also could apply the function
Polyhedron::is_tetrahedron(Polyhedron::Halfedge_handle) also, because I
failed to do it because I didn't know how to get the right call for
Halfedge_handle.
Sincerest regards,
Samer Afach
Institute of computational physics, University of Stuttgart
- [cgal-discuss] Tetrahedron-Polyhedron problem, Samer Afach, 03/12/2010
Archive powered by MHonArc 2.6.16.