d.valkanov,
Have a look at this code:
private void MarkTriangle(int pa, int pb, int tNum, Polygon boundary, RemoveTriangles In_Or_Out)
{
if (tNum != -1)
{
// Current triangle
Triangle t = triangles[tNum];
// Find which edge passes through points pa and pb
int pc = t.GetThirdVertex(pa, pb);
// Centre of gravity
Point mc = ONE_THIRD * (points[pa] + points[pb] + points[pc]);
// If current triangle is not marked and ...
if (!t.ToBeDeleted)
{
bool inside; // Point is inside or outside of polygon
if (In_Or_Out == RemoveTriangles.Inside) // If In_Or_Out is true it is a hole in the mesh
inside = boundary.InPolygon(mc); // mc MUST be inside of hole
else // otherwise it is a outer boundary.
inside = !boundary.InPolygon(mc);
// centre of gravity is outside of boubdary
if (inside)
{
// Mark triangle to be deleted.
t.ToBeDeleted = true;
// Get opposed triangle of pa
int tOpp = t.OpposedTriangle(pa);
// Recursively mark neighbour.
MarkTriangle(pb, pc, tOpp, boundary, In_Or_Out);
// Get opposed triangle of pb
tOpp = t.OpposedTriangle(pb);
// Recursively mark neighbour.
MarkTriangle(pc, pa, tOpp, boundary, In_Or_Out);
}
}
}
}