# Robust sections on Mesh objects

When dealing with a badly defined mesh (overlapping triangles, edges shared by more than two triangles and so on) our Mesh.Section() method can fail.

The following code shows how to extract a section even in these problematic situations.

Mesh sectioning methods can be used also for surfaces, after converting a surface to a mesh by Surface.ConvertToMesh().

``````//Mesh
Mesh mesh = Mesh.CreateTorus(5, 2, 10, 20);
mesh.Translate(110, 30, 0);

Plane pln = Plane.YZ;

pln.Origin = new Point3D(108, 0, 0);

foreach (IndexTriangle it in mesh.Triangles)
{
Point3D p1 = mesh.Vertices[it.V1];
Point3D p2 = mesh.Vertices[it.V2];
Point3D p3 = mesh.Vertices[it.V3];

Segment3D s1 = new Segment3D(p1, p2);
Segment3D s2 = new Segment3D(p2, p3);
Segment3D s3 = new Segment3D(p3, p1);

Point3D intPoint1;
bool rc1 = s1.IntersectWith(pln, out intPoint1);

Point3D intPoint2;
bool rc2 = s2.IntersectWith(pln, out intPoint2);

Point3D intPoint3;
bool rc3 = s3.IntersectWith(pln, out intPoint3);

Line result = null;

if (rc1 && rc2)
{
result = new Line(intPoint1, intPoint2);
}

else if (rc2 && rc3)
{
result = new Line(intPoint2, intPoint3);
}

else if (rc3 && rc1)
{
result = new Line(intPoint3, intPoint1);
}

if (result != null && result.Length() > 1e-3)
{