Subject: CGAL users discussion list
List archive
- From: tang <>
- To:
- Subject: [cgal-discuss] Ask for help: split surface triangles
- Date: Sat, 22 Jun 2013 22:30:03 -0700 (PDT)
Dear all,
I am trying to split surface triangles by inserting new nodes at some
locations, the function is as follows. However, it displayed
Error!!!!!!!!!!!!!!!!!!!!!!!!
when boolean operation with another polyhedron after this function (it is OK
if this function does not work), could anyone take a look at it and give me
suggestion to modify the function?
Thanks,
Zhanghong Tang
The function:
void SplitTriangleAtZ(Polyhedron *obj,double r,double z)
{
/// this function is used to split all triangles whose edges are at r
and
included z
/// i.e. a point with point.z =z will be inserted into the edges
/// Zhanghong Tang @ 06/23/2013
double eps=1.0e-10;
/// check for small area triangle
Point_3 p1, p2, p3, p;
Halfedge_handle h, hnew, h1, h2, h3, ho, splitedge;
double x1, y1, z1, x2, y2, z2, x3, y3, z3, xp, yp;
double rr1,rr2,rr3,r2;
int found;
r2=r*r;
while(1)
{
found=0;
for ( Facet_iterator i = obj->facets_begin() ; i !=
obj->facets_end();
++i)
{
/// get 3 points of this facet(triangle)
h1 = i->halfedge();
h2 = h1->next();
h3 = h2->next();
/// (p3->p1): h1
/// (p1->p2): h->next()
/// (p2->p3): h->next()->next()
p1 = h1->vertex()->point();
p2 = h2->vertex()->point();
p3 = h3->vertex()->point();
x1=CGAL::to_double(p1.x());
x2=CGAL::to_double(p2.x());
x3=CGAL::to_double(p3.x());
y1=CGAL::to_double(p1.y());
y2=CGAL::to_double(p2.y());
y3=CGAL::to_double(p3.y());
z1=CGAL::to_double(p1.z());
z2=CGAL::to_double(p2.z());
z3=CGAL::to_double(p3.z());
if((z1-z)*(z2-z)<0.0)
{
rr1=x1*x1+y1*y1;
rr2=x2*x2+y2*y2;
if(rr1-r2<eps && rr2-r2<eps) //
p1, p2
{
xp=x1+(z-z1)*(x2-x1)/(z2-z1);
yp=y1+(z-z1)*(y2-y1)/(z2-z1);
p=Point_3(xp,yp,z);
splitedge = h2; /// h2 will be
splitted by p
h = h3;
found=1;
}
}
else if((z2-z)*(z3-z)<0.0)
{
rr2=x2*x2+y2*y2;
rr3=x3*x3+y3*y3;
if(rr2-r2<eps && rr3-r2<eps)
// p2, p3
{
xp=x2+(z-z2)*(x3-x2)/(z3-z2);
yp=y2+(z-z2)*(y3-y2)/(z3-z2);
p=Point_3(xp,yp,z);
splitedge = h3; /// h3 will be
splitted by p
h = h1;
found=1;
}
}
else if((z3-z)*(z1-z)<0.0)
{
rr3=x3*x3+y3*y3;
rr1=x1*x1+y1*y1;
if(rr3-r2<eps && rr1-r2<eps)
// p3, p1
{
xp=x3+(z-z3)*(x1-x3)/(z1-z3);
yp=y3+(z-z3)*(y1-y3)/(z1-z3);
p=Point_3(xp,yp,z);
splitedge = h1; /// h1 will be
splitted by p
h = h2;
found=1;
}
}
if(found==1)
{
/// the opposite facet
ho = splitedge->opposite()->next();
/// split the edge
hnew = obj->split_edge(splitedge);
/// set the new vertex
hnew->vertex()->point() = p;
/// split the facet
hnew = obj->split_facet(h, hnew);
/// split opposite facet
obj->split_facet(ho, splitedge->opposite());
break;
}
}
if(found==0)break;
}
}
--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Ask-for-help-split-surface-triangles-tp4657696.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
- [cgal-discuss] Ask for help: split surface triangles, tang, 06/23/2013
Archive powered by MHonArc 2.6.18.