Strange behaviour - GetIdenticalBodies

Strange behaviour - GetIdenticalBodies

laszlo_nagy
Contributor Contributor
321 Views
3 Replies
Message 1 of 4

Strange behaviour - GetIdenticalBodies

laszlo_nagy
Contributor
Contributor

Hello,
(sorry I'm not native english speaker)

When I use the GetIdenticalBodies command it returns as many ObjectCollections, as many identical solids have been found (and each ObjectCollection contain  the SurfaceBody object and a Matrix object )

I made an example,I draw 3 solids and mirrored them (picture included), and run my code and here is the output I got

Case#1 Red boxes
They are in the same collection ->OK
(the determinant of result matrix equals +1)
Case#2 Green bodies
They are in the same collection, but they are not identical (mirror-symetric)
the determinant of result matrix equals -1 <- I think this value means they are mirror-symetric??
Case#3 Blue cylinders
They are in the same collection, and they are  identical 
the determinant of result matrix equals -1 <- WHY???

According to my experiences, this function recognizes the mirror-symetric bodies as identical, and in this case the determinant of result matrix is -1. 

But this logic fails with the 3rd case, because these cylinders are identical, however, the determinant is -1

Does anyone have more experience with this function? And can explain the Results
Thank you

Sub testIdentical()

    Dim oObjColl As ObjectCollection
    Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim oPart As PartDocument
    Set oPart = ThisApplication.ActiveDocument
    
    Dim oPartDef As PartComponentDefinition
    Set oPartDef = oPart.ComponentDefinition
    
    Dim oSolid As SurfaceBody

    For Each oSolid In oPartDef.SurfaceBodies
        Call oObjColl.Add(oSolid)
    Next

    Dim identicalBodies As ObjectCollection
    Set identicalBodies = ThisApplication.TransientBRep.GetIdenticalBodies(oObjColl)
    
    '//Print Output
    For Each el In identicalBodies
        
        i = i + 1
        Debug.Print "------------"
        Debug.Print "GROUP #" & i
        
        For Each el2 In el
            Debug.Print "    " & el2.Item(1).Name & " # Determinant = " & el2.Item(2).Determinant
        Next
        
    Next
    
End Sub


test_identicalBodies.jpg
my results
------------
GROUP #1
Solid1 # Determinant = 1
Solid4 # Determinant = 1
------------
GROUP #2
Solid2 # Determinant = 1
Solid5 # Determinant = -1
------------
GROUP #3
Solid3 # Determinant = 1
Solid6 # Determinant = -1

0 Likes
322 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor

The short answer is that the determinant does not tell you if an object is mirrored. My knowledge of linear algebra is not good enough to explain what it suppose to tell you. If you want to know more I would recommend that you watch this youtube series "Essence of linear algebra". Part 6 is about the determinant.

 

How an object is mirrored and all other transformations that are done to an object are encoded in a transformation matrix. (I like this image that shows you all transformations and their matrixes in 2D space)

In your code, you have that transformation matrix in the variable "el2.Item(2)". Im not sure if it's possible to extract the individual transformations that are encoded in the matrix (like the mirror transformation). Because you would need to reverse the multiplication of all transformations. But maybe in your case, there is some way to extract the information.

Anyway I have updated your VBa code to show the matrices of all objects. (And because I don't use VBa I have transformed it to iLogic code)

Public Sub Main()

    Dim oObjColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

    Dim oPart As PartDocument = ThisApplication.ActiveDocument

    Dim oPartDef As PartComponentDefinition = oPart.ComponentDefinition

    For Each oSolid As SurfaceBody In oPartDef.SurfaceBodies
        Call oObjColl.Add(oSolid)
    Next

    Dim identicalBodies As ObjectCollection = ThisApplication.TransientBRep.GetIdenticalBodies(oObjColl)

    '//Print Output
    Dim i = 0
    For Each el In identicalBodies

        i = i + 1

        Logger.Info("------------")
        Logger.Info("GROUP #" & i)

        For Each el2 In el
            Dim t As Matrix = el2.Item(2)

            Logger.Info(String.Format("{0}, {1}, {2}, {3}", v(t, 1, 1), v(t, 1, 2), v(t, 1, 3), v(t, 1, 4)))
            Logger.Info(String.Format("{0}, {1}, {2}, {3}", v(t, 2, 1), v(t, 2, 2), v(t, 2, 3), v(t, 2, 4)))
            Logger.Info(String.Format("{0}, {1}, {2}, {3}", v(t, 3, 1), v(t, 3, 2), v(t, 3, 3), v(t, 3, 4)))
            Logger.Info(String.Format("{0}, {1}, {2}, {3}", v(t, 4, 1), v(t, 4, 2), v(t, 4, 3), v(t, 4, 4)))

            Logger.Info("    " & el2.Item(1).Name & " # Determinant = " & el2.Item(2).Determinant)
        Next

    Next

End Sub

Private Function v(matrix As Matrix, row As Integer, column As Integer) As Double
    Return Math.Round(matrix.Cell(row, column))
End Function

 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

laszlo_nagy
Contributor
Contributor

Hello,
Thank you for your answer, I try to describe my problem differently 
I made the exact the same transformation all the bodies (mirrored them on the same plane)
but i've got different results, I tried to make a sketch for it below

the real world problem is , I have a multibody skeleton model, and i want to count the identical bodies
#1. My first attempt was to use just the .GetIdenticalBodies function, but it says the mirrored part are identical(but in real, they aren't)
#2. Second, I sorted the result collections by their determinants, which looks good at first, but then I faced this phenomenon (same transformation gives different results(different matrices))


as i interpret it  when the determinant is -1 the orientation is reveresed, (if i transfrom all of the points of the solid by this way that means I will got a mirrored solid, right?)
http://15462.courses.cs.cmu.edu/fall2018content/lectures/03_vectorcalc/images/slide_017.jpg 

Identical_pic2.png

0 Likes
Message 4 of 4

laszlo_nagy
Contributor
Contributor

 

I exported the sample files to different CAD formats, It turned out if I export it to IGES and import it again then I got good result

I've only done a few tests but I've come to this conclusion somehow Inventor interprets its own circular surfaces differently than the imported ones(IGES OK, STEP also not OK)

laszlonagy_1-1656656443215.png

 

 

0 Likes