# How to find the genus (number of "handles") of a closed surface?

Hello,

I would like to know if there is a way to determine the genus (number of “handles or holes”) of a closed surface by scripting?

That would be used to find if there was a problem with text engraving punching holes through thin parts of my closed 3D surface. My original closed surface is topologically equivalent to a sphere and punching holes in it would make it equivalent to a torus (genus 1) or higher degree genus surface (see images above).

Regards,

Bruno

Ooh, this is a fun one.
You can use this simple formula for the Euler characteristic

F-E+V = 2-2g

Where F is the number of faces, E is the number of edges, V the number of vertices, and g the genus

genus.gh (65.1 KB)

2 Likes

Yes! I had forget about Euler’s characteristic, shame on me for having a MSc in mathematics and not having thought about it

Just being lazy, would you have a simple way of doing it directly with the Python API instead of running Grasshopper script? Anyway, that’s the way to go!

Thanks,

Bruno

`0.5 * (2 - (M.Faces.Count - M.TopologyEdges.Count + M.Vertices.Count))`

1 Like

Thank you for that answer, much appreciated!

Could I ask you for one more step? Do you know if such equation exists about closed polysurfaces (breps). It seems that TopologyEdges only exist in meshes.

Thanks again!

Alexandre

Use Brep vertex, edge and face counts in the same formula.