[Issue #3541] Hole feature does not work correct if sketch is not parallel to main planes

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
babaroga
Posts: 178
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

[Issue #3541] Hole feature does not work correct if sketch is not parallel to main planes

Post by babaroga »

Hello,

I was drawing some model recently and find a bug with Hole feature. If sketch is not parallel with one of main planes, diameter of hole is calculated wrong.

I made sketch with one corner at 30 degrees and another on 45 degrees compared to ZX plane.
Screenshot_20180714_124733.png
Screenshot_20180714_124733.png (113.87 KiB) Viewed 3343 times

Then I made a 20mm pad and apply sketches at three sides. I made used a Hole feature on all of them with same parameters. Diameter 10mm and depth 25mm. You can see result on following screenshot. Sketches are visible to show how much they defer. All circle diameters on sketches are 10mm.
Screenshot_20180714_124652.png
Screenshot_20180714_124652.png (90.82 KiB) Viewed 3343 times

On following screenshot you can see dimensions I get.

Screenshot_20180714_131313.png
Screenshot_20180714_131313.png (84.98 KiB) Viewed 3343 times

As you can see, dimensions of holes are calculated as
sin(angle)*diameter

sin(45)*10 = 7,0710
sin(30)*10 = 5


Same behavior I noticed on two Windows boxes with 0.17.13522 and 0.18.13976 from download section

My freecad is :

Code: Select all

OS: "Manjaro Linux"
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.14083 (Git)
Build type: Release
Branch: master
Hash: 07d1abb387c6b62093375fa7df99c92f2aaacda0
Python version: 2.7.15
Qt version: 5.11.1
Coin version: 3.1.3
OCC version: 7.2.0
Locale: English/UnitedStates (en_US)
Attachments
Hole feature bug.FCStd
(35.59 KiB) Downloaded 66 times
Last edited by babaroga on Wed Jul 18, 2018 8:48 pm, edited 1 time in total.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Hole feature does not work correct if sketch is not parallel to main planes

Post by DeepSOIC »

Confirmed...

OS: Windows 8
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.13935 (Git)
Build type: Release
Branch: master
Hash: cb133767464337e4b5c8589a1fe33b4d7dad7721
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: Russian/RussianFederation (ru_RU)
eivindkvedalen wrote:ping
chrisb
Veteran
Posts: 53924
Joined: Tue Mar 17, 2015 9:14 am

Re: Hole feature does not work correct if sketch is not parallel to main planes

Post by chrisb »

Confirmed on MacOS as well. Surprisingly the length is not affected:
Attachments
Bildschirmfoto 2018-07-14 um 13.48.42.png
Bildschirmfoto 2018-07-14 um 13.48.42.png (26.04 KiB) Viewed 3336 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
babaroga
Posts: 178
Joined: Sun Aug 14, 2016 6:52 pm
Location: Banja Luka, Republic of Srpska, Bosnia and Herzegovina

Re: Hole feature does not work correct if sketch is not parallel to main planes

Post by babaroga »

Should I file a Bug on tracker?
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Hole feature does not work correct if sketch is not parallel to main planes

Post by DeepSOIC »

Had a quick glance through the code. It looks like the problem might be somewhere here:
https://github.com/FreeCAD/FreeCAD/blob ... e.cpp#L980

Code: Select all

        /* Compute xDir normal to zDir */
        if (std::abs(zDir.Z() - zDir.X()) > Precision::Confusion())
            xDir = gp_Vec(zDir.Z(), 0, -zDir.X());
        else if (std::abs(zDir.Z() - zDir.Y()) > Precision::Confusion())
            xDir = gp_Vec(zDir.Y(), -zDir.X(), 0);
        else
            xDir = gp_Vec(0, -zDir.Z(), zDir.Y());
The comment says xDir vector is being constructed, perpendicularly to zDir vector. That doesn't look like a valid way of constructing one.
User avatar
tanderson69
Veteran
Posts: 1626
Joined: Thu Feb 18, 2010 1:07 am

Re: Hole feature does not work correct if sketch is not parallel to main planes

Post by tanderson69 »

DeepSOIC wrote: Sat Jul 14, 2018 12:20 pm The comment says xDir vector is being constructed, perpendicularly to zDir vector. That doesn't look like a valid way of constructing one.
I think it is valid, as I have seen something like this inside occ code. I agree it looks ugly. I have done it using dot and cross products, but the code isn't much better if at all.

My guess is the output vector just needs to be normalized.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Hole feature does not work correct if sketch is not parallel to main planes

Post by DeepSOIC »

tanderson69 wrote: Sat Jul 14, 2018 2:59 pm
DeepSOIC wrote: Sat Jul 14, 2018 12:20 pm The comment says xDir vector is being constructed, perpendicularly to zDir vector. That doesn't look like a valid way of constructing one.
I think it is valid, as I have seen something like this inside occ code.
My guess is the output vector just needs to be normalized.
Did some tests, the result is indeed perpendicular. So I guess we have a fix proposal?
User avatar
tanderson69
Veteran
Posts: 1626
Joined: Thu Feb 18, 2010 1:07 am

Re: Hole feature does not work correct if sketch is not parallel to main planes

Post by tanderson69 »

DeepSOIC wrote: Sat Jul 14, 2018 3:31 pm So I guess we have a fix proposal?
I didn't test anything, I was just giving an idea to someone who stays up with freecad development.
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Hole feature does not work correct if sketch is not parallel to main planes

Post by eivindkvedalen »

DeepSOIC wrote: Sat Jul 14, 2018 12:20 pm Had a quick glance through the code. It looks like the problem might be somewhere here:
https://github.com/FreeCAD/FreeCAD/blob ... e.cpp#L980

Code: Select all

        /* Compute xDir normal to zDir */
        if (std::abs(zDir.Z() - zDir.X()) > Precision::Confusion())
            xDir = gp_Vec(zDir.Z(), 0, -zDir.X());
        else if (std::abs(zDir.Z() - zDir.Y()) > Precision::Confusion())
            xDir = gp_Vec(zDir.Y(), -zDir.X(), 0);
        else
            xDir = gp_Vec(0, -zDir.Z(), zDir.Y());
The comment says xDir vector is being constructed, perpendicularly to zDir vector. That doesn't look like a valid way of constructing one.
This code works, but I'm unsure if this is the right thing to do. Could you please try to hard-code xDir to be (1, 0, 0), and see if that helps?

Eivind
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Hole feature does not work correct if sketch is not parallel to main planes

Post by eivindkvedalen »

babaroga wrote: Sat Jul 14, 2018 11:58 am Should I file a Bug on tracker?
Yes, please file a bug report, so we don't forget about this. Please also refer to this thread in the report.

Eivind
Post Reply