# RhinoCommon: Capping a Brep with unequally oriented Faces?

hey guys,

i am dealing with a brep in rhinocommon (C#) that looks just like an orthogonal extrusion of a rectangle: four rectangular surfaces that are connected to some kind of ring. i get that ring by adding four rectangular nurbs surfaces to a new brep (mybrep). note that orientations of these nurbs surfaces will vary.

i now want to get a solid by:

mybrep.JoinNakedEdges()
mybrep.CapPlanerHoles()

since the four ring faces are not equally oriented ‘outward’, capping won’t work. in fact, it produces a lot of duplicate surfaces instead of capping my ring.

is there a way to automatically re-orient all surfaces as it happens in rhino when joining? when i explode and re-join my ring in rhino, all inward faces will be flipped.

alternatively - how can i sort out inward-oriented faces of my brep and flip them?

best regards,

heinz.

In case of simple, more or less planar surfaces you could do the following:

• determine the center of the bounding box of the sides together (let’s call this point C)
• for each side:
• determine the point on the side surface that is closest to C (let’s call this P)
• take the normal on the surface at P (let’s call this N)
• calculate the angle between the vector PC and N
• if the angle is close to 0 degrees, the normal is pointing outward
• if the angle is close to 180 degrees, the normal is pointing inward

The orientation of a Surface can be changed by calling `Transpose()` on it.
http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Geometry_Surface_Transpose_1.htm

The orientation of a BrepFace can be changed by toggling `BrepFace.OrientationIsReversed`. This will leave the underlying surface the same, but set a flag that the face normal is flipped. This can be seen using the `Dir` command - look for a small purple line opposite of the direction arrow. If the purple line is present, the OrientationIsReversed is true; if it is absent the face orientation follows the underlying surface orientation.

http://4.rhino3d.com/5/rhinocommon/html/P_Rhino_Geometry_BrepFace_OrientationIsReversed.htm

thanks a lot, menno!