[FIXED] FC#3006: PartDesign Mirrored bugs

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
kkremitzki
Veteran
Posts: 2511
Joined: Thu Mar 03, 2016 9:52 pm
Location: Illinois

[FIXED] FC#3006: PartDesign Mirrored bugs

Post by kkremitzki »

Hi, so I'm working on this issue and just wanted to create a thread to get some feedback.

First question:
what's up with this inversion? https://github.com/FreeCAD/FreeCAD/blob ... pp#L74-L77

I'm assuming it must be a mistake.

Anyway, I believe one of the core issues here may be an OCC bug, or at least a misuse of OCC, here and here.

Reference:
void gp_Trsf::SetMirror ( const gp_Ax2 & A2)

My test case is simple: I'm using a 1mm x 1mm square sketch, cornered at the origin and padded up 1mm, so a unit cube in the +X,+Y,+Z octant. So my gp_Pnt axbase is always (0, 0, 0).

If I reverse the inversion in my first link, I get the following results:
Mirror about vertical sketch axis (Y): axdir is (0, 1, 0). So, the mirror matrix should be [[-1, 0, 0], [0, 1, 0], [0, 0, 1]]. However the Z-direction ends up being negative.

Mirror about horizontal sketch axis (X): axdir is (1, 0, 0), ok. But the mirror matrix is [[1, 0, 0], [0, -1, 0], [0, 0,-1]] as above. The Z direction is negative when it shouldn't be.

Repeat this with sketches attached to the YZ and XZ planes, and always the corresponding normal is reversed. (So what should be X is -X, and what should be Y is -Y, respectively.)

So, this is obviously a problem. It got me thinking, though. Is this a problem with handedness/chirality of coordinate systems, and the fact that we're trying to mirror? In OCC, gp_Ax2 is a right-handed coordinate system only. There is a separate class, gp_Ax3, that can be left-handed, but then there is no gp_Trsf::SetMirror( const gp_Ax3& A3 )...
Last edited by Kunda1 on Wed Apr 27, 2022 9:17 pm, edited 1 time in total.
Reason: Added [Fixed] to thread title
Like my FreeCAD work? I'd appreciate any level of support via Patreon, Liberapay, or PayPal! Read more about what I do at my blog.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: FC#3006: PartDesign Mirrored bugs

Post by abdullah »

kkremitzki wrote:Hi, so I'm working on this issue and just wanted to create a thread to get some feedback.
Not a reply to your questions. Just a mutex/sync.

As part of "mirrored feature does not intersect support" error when touching, I am working on: Part::checkIntersection last section non-manyfold detection:

Code: Select all

    //non manifold condition. 1 has to be a face
    for (int index = 1; index < extrema.NbSolution() + 1; ++index)
    {
        if (extrema.SupportTypeShape1(index) == BRepExtrema_IsInFace || extrema.SupportTypeShape2(index) == BRepExtrema_IsInFace)
            return true;
        }
        
      return false;
    }
    else
      return false;
I will likely come to your questions later. I won't interfere in Mirrored Feature code.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: FC#3006: PartDesign Mirrored bugs

Post by abdullah »

kkremitzki wrote:what's up with this inversion? https://github.com/FreeCAD/FreeCAD/blob ... pp#L74-L77

I'm assuming it must be a mistake.
Definitely a mistake. It explains why I always have to select the axis I do not want to get what I want :)
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: FC#3006: PartDesign Mirrored bugs

Post by abdullah »

kkremitzki wrote: Thu Jun 01, 2017 5:34 am So, this is obviously a problem. It got me thinking, though. Is this a problem with handedness/chirality of coordinate systems, and the fact that we're trying to mirror? In OCC, gp_Ax2 is a right-handed coordinate system only. There is a separate class, gp_Ax3, that can be left-handed, but then there is no gp_Trsf::SetMirror( const gp_Ax3& A3 )...
It seems to be just a visualization problem in the mesh (the red thing the screenshoots).

When the transformation succeeds, there is no inversion (but then you do not see the red mesh, because that is only when it fails). When it fails (for other reasons, like misdetection by Part::CheckIntersection), this inverted red thing appears, making you think the inversion is causing the transformation to fail. However, in my tests the transformation fails for other reasons (at least in some of my examples).

If you want to test this, you can do this:

Code: Select all

bool Part::checkIntersection(const TopoDS_Shape& first, const TopoDS_Shape& second,
                             const bool quick, const bool touch_is_intersection) {
        
        return true;
}
If you confirm my findings. Then the thing to fix is the ViewProvider...
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: FC#3006: PartDesign Mirrored bugs

Post by abdullah »

I want to document this problem:

A point on object constraint in the sketcher, in a first solve, reaches a precision of 2E-7, whereas precision::confusion is 1e-7. The mirroring feature fails. See case:
example_sketcher_confusion.png
example_sketcher_confusion.png (2.62 KiB) Viewed 3564 times
I just open the sketcher and try to drag the point (the one with the Point on object constraint) to the -x axis (so as to try to make it closer from the mirroring feature that would be done). Close sketch and the mirroring feature success.

Problem: The Sketcher should increase its precision (we know it is not straight-forward, but still).
pdn_mirror_failure1.png
pdn_mirror_failure1.png (9.25 KiB) Viewed 3564 times
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: FC#3006: PartDesign Mirrored bugs

Post by abdullah »

Definitely, the culprit of Mirroring not working properly is Part::checkIntersection. The red mesh is wrongly represented in the ViewProvider ("inverted" and if the mistake Kurt identified is corrected, then also it makes the horizontal mirror when asking for the vertical mirror and vice versa).
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: FC#3006: PartDesign Mirrored bugs

Post by abdullah »

checkIntersection is also the only reason why a multitransform can not be used to make a full part from a quarter:
multitransform_mirror_mirror.png
multitransform_mirror_mirror.png (10.41 KiB) Viewed 3561 times
bypassing it:
pdn_mirror_mirror_success.png
pdn_mirror_mirror_success.png (14.06 KiB) Viewed 3561 times
Note: The in the first image the "non-manifold" test was already by passed. For the second, the whole checkIntersection was bypassed (it was giving a minimum distance of "7" mm?, probably was not measuring the right "shapes" as there are two original and two results).
User avatar
kkremitzki
Veteran
Posts: 2511
Joined: Thu Mar 03, 2016 9:52 pm
Location: Illinois

Re: FC#3006: PartDesign Mirrored bugs

Post by kkremitzki »

Here's my test case btw:
Attachments
pdtest1.fcstd
(7.59 KiB) Downloaded 83 times
Like my FreeCAD work? I'd appreciate any level of support via Patreon, Liberapay, or PayPal! Read more about what I do at my blog.
User avatar
kkremitzki
Veteran
Posts: 2511
Joined: Thu Mar 03, 2016 9:52 pm
Location: Illinois

Re: FC#3006: PartDesign Mirrored bugs

Post by kkremitzki »

The unit test I added BTW should be failing when checkIntersection is set to return true, but it isn't.

This needs to be changed to be >= 1.0
https://github.com/FreeCAD/FreeCAD/blob ... pp.py#L164
Like my FreeCAD work? I'd appreciate any level of support via Patreon, Liberapay, or PayPal! Read more about what I do at my blog.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: FC#3006: PartDesign Mirrored bugs

Post by abdullah »

Your test case Kurt:
sketch_kk.png
sketch_kk.png (4.87 KiB) Viewed 3558 times
sketch_kk1_t1.png
sketch_kk1_t1.png (3.59 KiB) Viewed 3558 times
sketch_kk1_t2.png
sketch_kk1_t2.png (3.59 KiB) Viewed 3558 times
Post Reply