SOLVED: Help with computing shared face.

Need help, or want to share a macro? Post here!
edwilliams16
Veteran
Posts: 1358
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Help with computing shared face.

Post by edwilliams16 »

How about

Code: Select all

print(f'is planar?  {obj.Shape.Faces[0].Surface.TypeId == "Part::GeomPlane"}')
But that possibly might depend on how it was constructed. I've only tested a few possibilities.
keithsloan52
Veteran
Posts: 2394
Joined: Mon Feb 27, 2012 5:31 pm

Re: Help with computing shared face.

Post by keithsloan52 »

CommonFace function currently looks like

Code: Select all

def commonFace(self, shape0, shape1):
        print(f'Common Face : {len(shape0.Faces)} : {len(shape1.Faces)}')
        zero = FreeCAD.Vector(0.0, 0.0, 0.0)
        for i, face0 in enumerate(shape0.Faces):
            for j, face1 in enumerate(shape1.Faces):
               print('dir surface')
               print(dir(face0.Surface))
               print(face0.Surface.TypeId)
               print(isinstance(face0.Surface, Part.Plane))
               print(isinstance(face1.Surface, Part.Plane))
               if isinstance(face0.Surface, Part.Plane) and \
                  isinstance(face1.Surface, Part.Plane):
                  print('Both Flat')
And that outputs for the boxes :-(

Code: Select all

20:24:39  dir surface
20:24:39  ['Content', 'Continuity', 'FirstUKnotIndex', 'FirstVKnotIndex', 'LastUKnotIndex', 'LastVKnotIndex', 'MaxDegree', 'MemSize', 'Module', 'NbUKnots', 'NbUPoles', 'NbVKnots', 'NbVPoles', 'Rotation', 'Tag', 'TypeId', 'UDegree', 'UKnotSequence', 'UPeriod', 'VDegree', 'VKnotSequence', 'VPeriod', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'approximate', 'bounds', 'buildFromNSections', 'buildFromPolesMultsKnots', 'clone', 'copy', 'curvature', 'curvatureDirections', 'deleteExtensionOfName', 'deleteExtensionOfType', 'dumpContent', 'exchangeUV', 'getAllDerivedFrom', 'getD0', 'getDN', 'getExtensionOfName', 'getExtensionOfType', 'getExtensions', 'getPole', 'getPoles', 'getPolesAndWeights', 'getResolution', 'getUKnot', 'getUKnots', 'getUMultiplicities', 'getUMultiplicity', 'getVKnot', 'getVKnots', 'getVMultiplicities', 'getVMultiplicity', 'getWeight', 'getWeights', 'hasExtensionOfName', 'hasExtensionOfType', 'increaseDegree', 'increaseUMultiplicity', 'increaseVMultiplicity', 'incrementUMultiplicity', 'incrementVMultiplicity', 'insertUKnot', 'insertUKnots', 'insertVKnot', 'insertVKnots', 'interpolate', 'intersect', 'intersectSS', 'isDerivedFrom', 'isPlanar', 'isUClosed', 'isUPeriodic', 'isURational', 'isUmbillic', 'isVClosed', 'isVPeriodic', 'isVRational', 'mirror', 'movePoint', 'normal', 'parameter', 'projectPoint', 'removeUKnot', 'removeVKnot', 'reparametrize', 'restoreContent', 'rotate', 'scale', 'segment', 'setExtension', 'setPole', 'setPoleCol', 'setPoleRow', 'setUKnot', 'setUKnots', 'setUNotPeriodic', 'setUOrigin', 'setUPeriodic', 'setVKnot', 'setVKnots', 'setVNotPeriodic', 'setVOrigin', 'setVPeriodic', 'setWeight', 'setWeightCol', 'setWeightRow', 'tangent', 'toBSpline', 'toShape', 'toShell', 'transform', 'translate', 'uIso', 'vIso', 'value']
20:24:39  Part::GeomBSplineSurface
20:24:39  False
20:24:39  False
keithsloan52
Veteran
Posts: 2394
Joined: Mon Feb 27, 2012 5:31 pm

Re: Help with computing shared face.

Post by keithsloan52 »

CommonFace function currently looks like

Code: Select all

def commonFace(self, shape0, shape1):
        print(f'Common Face : {len(shape0.Faces)} : {len(shape1.Faces)}')
        zero = FreeCAD.Vector(0.0, 0.0, 0.0)
        for i, face0 in enumerate(shape0.Faces):
            for j, face1 in enumerate(shape1.Faces):
               print('dir surface')
               print(dir(face0.Surface))
               print(face0.Surface.TypeId)
               print(isinstance(face0.Surface, Part.Plane))
               print(isinstance(face1.Surface, Part.Plane))
               if isinstance(face0.Surface, Part.Plane) and \
                  isinstance(face1.Surface, Part.Plane):
                  print('Both Flat')
And that outputs for the boxes :-(

Code: Select all

20:24:39  dir surface
20:24:39  ['Content', 'Continuity', 'FirstUKnotIndex', 'FirstVKnotIndex', 'LastUKnotIndex', 'LastVKnotIndex', 'MaxDegree', 'MemSize', 'Module', 'NbUKnots', 'NbUPoles', 'NbVKnots', 'NbVPoles', 'Rotation', 'Tag', 'TypeId', 'UDegree', 'UKnotSequence', 'UPeriod', 'VDegree', 'VKnotSequence', 'VPeriod', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'approximate', 'bounds', 'buildFromNSections', 'buildFromPolesMultsKnots', 'clone', 'copy', 'curvature', 'curvatureDirections', 'deleteExtensionOfName', 'deleteExtensionOfType', 'dumpContent', 'exchangeUV', 'getAllDerivedFrom', 'getD0', 'getDN', 'getExtensionOfName', 'getExtensionOfType', 'getExtensions', 'getPole', 'getPoles', 'getPolesAndWeights', 'getResolution', 'getUKnot', 'getUKnots', 'getUMultiplicities', 'getUMultiplicity', 'getVKnot', 'getVKnots', 'getVMultiplicities', 'getVMultiplicity', 'getWeight', 'getWeights', 'hasExtensionOfName', 'hasExtensionOfType', 'increaseDegree', 'increaseUMultiplicity', 'increaseVMultiplicity', 'incrementUMultiplicity', 'incrementVMultiplicity', 'insertUKnot', 'insertUKnots', 'insertVKnot', 'insertVKnots', 'interpolate', 'intersect', 'intersectSS', 'isDerivedFrom', 'isPlanar', 'isUClosed', 'isUPeriodic', 'isURational', 'isUmbillic', 'isVClosed', 'isVPeriodic', 'isVRational', 'mirror', 'movePoint', 'normal', 'parameter', 'projectPoint', 'removeUKnot', 'removeVKnot', 'reparametrize', 'restoreContent', 'rotate', 'scale', 'segment', 'setExtension', 'setPole', 'setPoleCol', 'setPoleRow', 'setUKnot', 'setUKnots', 'setUNotPeriodic', 'setUOrigin', 'setUPeriodic', 'setVKnot', 'setVKnots', 'setVNotPeriodic', 'setVOrigin', 'setVPeriodic', 'setWeight', 'setWeightCol', 'setWeightRow', 'tangent', 'toBSpline', 'toShape', 'toShell', 'transform', 'translate', 'uIso', 'vIso', 'value']
20:24:39  Part::GeomBSplineSurface
20:24:39  False
20:24:39  False
Boxes are created with this code

Code: Select all

def createGeometry(self, fp):
        # print('createGeometry')

        if all((fp.x, fp.y, fp.z)):
            currPlacement = fp.Placement

            # if (hasattr(fp,'x') and hasattr(fp,'y') and hasattr(fp,'z')) :
            mul = GDMLShared.getMult(fp)
            GDMLShared.trace('mul : '+str(mul))
            x = mul * fp.x
            y = mul * fp.y
            z = mul * fp.z
            box = Part.makeBox(x, y, z)
            base = FreeCAD.Vector(-x/2, -y/2, -z/2)
            fp.Shape = translate(box, base)
            fp.Placement = currPlacement
        if hasattr(fp, 'scale'):
            super().scale(fp)
edwilliams16
Veteran
Posts: 1358
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Help with computing shared face.

Post by edwilliams16 »

Some operations turn flat faces into B-Spline Objects. It depends on the history of your objects...

The idea of intersecting thickened faces appears to work. It would take a little effort to code it. Draft|Downgrade to make faces. Then Part|3DOffset to thicken them and then Part|Boolean Common. The latter works fine on solids, but not on the original faces, for presumably numerical reasons. Another Draft|Downgrade could make the common surface.

The example is a Cube partially intersecting a cylinder.
Screen Shot 2022-06-27 at 10.56.30 AM.png
Screen Shot 2022-06-27 at 10.56.30 AM.png (31.31 KiB) Viewed 377 times
Screen Shot 2022-06-27 at 11.07.08 AM.png
Screen Shot 2022-06-27 at 11.07.08 AM.png (28.66 KiB) Viewed 377 times
Attachments
commonfacevia3DOffset.FCStd
(20.72 KiB) Downloaded 3 times
keithsloan52
Veteran
Posts: 2394
Joined: Mon Feb 27, 2012 5:31 pm

Re: Help with computing shared face.

Post by keithsloan52 »

edwilliams16 wrote: Mon Jun 27, 2022 9:10 pm Some operations turn flat faces into B-Spline Objects. It depends on the history of your objects...

The idea of intersecting thickened faces appears to work. It would take a little effort to code it. Draft|Downgrade to make faces. Then Part|3DOffset to thicken them and then Part|Boolean Common. The latter works fine on solids, but not on the original faces, for presumably numerical reasons. Another Draft|Downgrade could make the common surface.

The example is a Cube partially intersecting a cylinder.

Screen Shot 2022-06-27 at 10.56.30 AM.pngScreen Shot 2022-06-27 at 11.07.08 AM.png
Sorry don't like that solution at all, will carry on trying to find a solution,
edwilliams16
Veteran
Posts: 1358
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Help with computing shared face.

Post by edwilliams16 »

keithsloan52 wrote: Tue Jun 28, 2022 1:08 am
Sorry don't like that solution at all, will carry on trying to find a solution,
Let us know what you find, that will work in general.
keithsloan52
Veteran
Posts: 2394
Joined: Mon Feb 27, 2012 5:31 pm

Re: Help with computing shared face.

Post by keithsloan52 »

edwilliams16 wrote: Mon Jun 27, 2022 9:10 pm Some operations turn flat faces into B-Spline Objects. It depends on the history of your objects...
So how would one check if a B-Spline Surface is Flat?
edwilliams16
Veteran
Posts: 1358
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Help with computing shared face.

Post by edwilliams16 »

keithsloan52 wrote: Tue Jun 28, 2022 6:52 am So how would one check if a B-Spline Surface is Flat?
@Chris_G is most likely to know.

What's the plan if it isn't flat?
keithsloan52
Veteran
Posts: 2394
Joined: Mon Feb 27, 2012 5:31 pm

Re: Help with computing shared face.

Post by keithsloan52 »

edwilliams16 wrote: Tue Jun 28, 2022 5:18 pm
keithsloan52 wrote: Tue Jun 28, 2022 6:52 am So how would one check if a B-Spline Surface is Flat?
@Chris_G is most likely to know.

What's the plan if it isn't flat?
If both Faces are Flat check for coplaner(?) same Plane

If both Faces are Curved somehow check if they are both part of the same curved surface. i.e. the same or the smaller one would be part of the larger.
edwilliams16
Veteran
Posts: 1358
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Help with computing shared face.

Post by edwilliams16 »

keithsloan52 wrote: Tue Jun 28, 2022 5:38 pm
If both Faces are Flat check for coplaner(?) same Plane

If both Faces are Curved somehow check if they are both part of the same curved surface. i.e. the same or the smaller one would be part of the larger.
So, given a method powerful enough to match curved surfaces, surely it could handle flat ones?
Given that even flat surfaces can end up being described by B-Splines, the method has to handle them. Then there's no need to test if they are actually flat, or actually cylindrical, or actually spherical or any other special case.
Post Reply