Comparing Geometries with Brep.IsDuplicate() and GeometryBase.Equals()


I am trying to compare geometries to each other to find duplicates…
In the example below I am having geometry tagged as “a” (two breps) and “b”/“c” which are curves.
I also got two very dirty breps “d” from an external model, which are identical.

“a” is identified as equal, but “d” is not. I assume this happens because the faces of the brep might be build/converted differently.
Is there any chance to match this?

“b” and “c” are not working at all - which confuses me, because even their build-up is identical.

Is there anything I am missing or are there strategies to make this work properly?


tol_abs = sc.doc.ModelAbsoluteTolerance

objs = rs.ObjectsByName("a")
objs = [rs.coercegeometry(id) for id in objs]
print(objs[0].IsDuplicate(objs[1], tol_abs))

objs = rs.ObjectsByName("d")
objs = [rs.coercegeometry(id) for id in objs]
objs = [x.Duplicate() for x in objs]

objs = rs.ObjectsByName("b")
objs = [rs.coercegeometry(id) for id in objs]
print(Rhino.Geometry.GeometryBase.Equals(objs[0], objs[1]))

objs = rs.ObjectsByName("c")
objs = [rs.coercegeometry(id) for id in objs]
print(Rhino.Geometry.GeometryBase.Equals(objs[0], objs[1]))

Compare.3dm (416.4 KB)

I just added the missing file :slight_smile:

Hi @tobias.stoltmann,

Rather than GeometryBase.Equals, use GeometryBase.GeometryEquals.

import Rhino
import rhinoscriptsyntax as rs

names = ["a", "b", "c", "d"]
for name in names:
    ids = rs.ObjectsByName(name)
    if ids and len(ids) == 2:
        geom = [rs.coercegeometry(id) for id in ids]
        gtype = geom[0].ObjectType
        print("{0}: {1}".format(name, gtype))
        # Determines if two geometries equal one another, in pure geometrical shape.
        rc = Rhino.Geometry.GeometryBase.GeometryEquals(geom[0], geom[1])
        print(" GeometryBase.GeometryEquals: {0}".format(rc))
        if gtype == Rhino.DocObjects.ObjectType.Brep:
            # Determines if two Breps equal one another, in pure geometrical shape.
            rc = geom[0].IsDuplicate(geom[1], 0.0)
            print(" Brep.IsDuplicate: {0}".format(rc))

Note, Brep.IsDuplicate uses the same underlying function as GeometryBase.GeometryEquals.

– Dale

1 Like

Hi @dale,
perfect. Thousand thanks!

2 questions though:
There is no way to use GeometryBase.GeometryEquals with any kind of tolerance, right?
The limitations also are, that if the build-up of a brep is not 100% identical (order of faces, edges, …) the comparison will not detect that?


– Dale