Complex Sections

Discussions about the development of the TechDraw workbench
User avatar
wandererfan
Veteran
Posts: 4972
Joined: Tue Nov 06, 2012 5:42 pm

Re: Complex Sections

Post by wandererfan »

aapo wrote: Wed Sep 21, 2022 1:32 pm What I mean is that your current code seems to project the view along the direction of the red lines in the following crude drawing. The standard convention is (or at least I believe it to be) to project the two sides, green and blue, separately into two different normal directions, and then join the two projections into the same drawing as if they would be in the same plane. So, it's kind of a pseudo-planar projection. If I read your code correctly, I think it calculates the red projection. I could be wrong, as I haven't yet had the time to actually test the code. Note that the red picture and green+blue picture are completely different, but there's a use case for both modes in different situations.
Ok, now I've caught up to you. Yes, when we project the cut shape it is one projection in one direction (the red projection). I'm not sure how to do green and blue off the top of my head, at least without asking the user a bunch of questions or putting restrictions on how the profile is formed.
aapo
Posts: 464
Joined: Mon Oct 29, 2018 6:41 pm

Re: Complex Sections

Post by aapo »

wandererfan wrote: Wed Sep 21, 2022 1:55 pm Ok, now I've caught up to you. Yes, when we project the cut shape it is one projection in one direction (the red projection). I'm not sure how to do green and blue off the top of my head, at least without asking the user a bunch of questions or putting restrictions on how the profile is formed.
Unfortunately, the green+blue method is known as the "aligned section view", and it seems to be the engineering standard (see. e.g. http://engineeringessentials.com/ege5/f ... e3_ex2.htm). I've noticed that in practice the aligned section view is used a lot in professional drawings for revolution objects (anything you make with a lathe).

I thought about that a bit, and the general case for flattening the projection is mathematically possible, as all the cut surfaces of a section are necessarily ruled surfaces (https://en.wikipedia.org/wiki/Ruled_surface). However, that's a bit complicated strategy, as can be seen from a FreeCAD Python macro for unrolling a ruled surface in general case https://wiki.freecadweb.org/Macro_Unroll_Ruled_Surface. In the case of Complex Sections it would be much more reasonable to use piecewise linear wires to cut the projections separately and then combine them. So, the pseudo algorithm would be, mimicking your current algorithm, to:

Code: Select all

take a wire consisting of line segments
loop through the line segments
   build a cutting face from the line segment
   build a cutting prism from the face (choose the face normal closer to the Section normal, cut away insides of this prism)
   build a 2nd cutting prism from the face (choose the opposite normal, cut away outsides of this prism)
   OCC-project the cut shape onto the cutting face plane
   rotate (not project) the resulting wires onto the paper plane
   add the result to the section edges, but translating the origin to the end of the previous iteration
It is complicated and probably error-prone, I have to admit :lol:

EDIT: When extruding the cutting prisms, one has to additionally compute the correct extrusion direction from the two opposite face normals, which I believe is the direction that is closer to the section normal (i.e. paper plane normal). Also, there needs to be an extra cut to exclude anything unwanted, i.e., cut away anything outside the prism made with the opposite of the normal.

Please note that your current algorithm is good for many cases, but it's not what people would expect for revolution objects. I think we'd need a property "ProjectionStrategy" with values "Single" and "Piecewise", of which "Single" would be mandatory for any non-linear cutting profiles.
aapo
Posts: 464
Joined: Mon Oct 29, 2018 6:41 pm

Re: Complex Sections

Post by aapo »

I noticed that user domad here https://forum.freecadweb.org/viewtopic.php?f=35&t=71906 has very recently manually implemented a very similar algorithm I proposed above for doing aligned section views with FreeCAD, but he seems to have used Facebinders. I must say that his final drawing result is exemplary, but unfortunately mimicking it programmatically is likely not easy, as it involves manual intervention and sketch-drawing.


domad wrote:<Pictures from domad's aligned section example>
20220921 TD section projections p02.png
20220921 TD section projections p02.png (35.3 KiB) Viewed 460 times
20220921 TD section projections p03.png
20220921 TD section projections p03.png (35.21 KiB) Viewed 460 times
User avatar
wandererfan
Veteran
Posts: 4972
Joined: Tue Nov 06, 2012 5:42 pm

Re: Complex Sections

Post by wandererfan »

aapo wrote: Wed Sep 21, 2022 2:21 pm the green+blue method is known as the "aligned section view"
I think I've sorted out the mechanics of a simple case. Does this look right?
complexSection_aligned.png
complexSection_aligned.png (40.93 KiB) Viewed 422 times
aapo
Posts: 464
Joined: Mon Oct 29, 2018 6:41 pm

Re: Complex Sections

Post by aapo »

wandererfan wrote: Wed Sep 21, 2022 6:29 pm I think I've sorted out the mechanics of a simple case. Does this look right?
Yes, that's exactly correct (I presume that the two extra lines on the blue side are cylinder seams, and are visible by choice). Wow, that was impressively fast! :shock: I hope this proof-of-concept of yours can be somehow added to your new tool, it would be really useful tool for people making rotating machinery drawings.
aapo
Posts: 464
Joined: Mon Oct 29, 2018 6:41 pm

Re: Complex Sections

Post by aapo »

I finally had time to compile your branch and test. I got somewhat mixed results, and there was something odd with the ComplexSection below, might be because the section line Sketch has splines. The left side of the ComplexSection looks correct to me, but then it goes haywire when I try to make all the hole structures visible in the same section. Btw, this is one of the use cases where it's preferable to use one projection direction, i.e. the original one-plane ComplexSection implementation is better.

As a side note, the input for the operation should be validated somehow. If I select the 3D body itself (instead of a body View) and the Sketch in the tree view, and press the ComplexSection button, the tool appears, but the whole FreeCAD crashes when I try to generate the bogus section view. I think it should validate that I have a View and a profile selected, and not some uncompatible objects.

The test file is attached.

20220921 TD ComplexSection test_p01.png
20220921 TD ComplexSection test_p01.png (43.3 KiB) Viewed 372 times


OS: Debian GNU/Linux bookworm/sid (KDE/plasma)
Word size of FreeCAD: 64-bit
Version: 0.21.30420 +1 (Git)
Build type: Release
Branch: (HEAD detached at WandererFan/ComplexSection)
Hash: 7447ed1a764989df09dc40534c5f9f1561e39278
Python 3.10.7, Qt 5.15.4, Coin 4.0.0, Vtk 7.1.1, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods:
* Assembly4
* Render
* fasteners
* FCGear
* Manipulator
* Curves
* sheetmetal
Attachments
20220921 TD ComplexSection test.FCStd
(58.66 KiB) Downloaded 5 times
User avatar
wandererfan
Veteran
Posts: 4972
Joined: Tue Nov 06, 2012 5:42 pm

Re: Complex Sections

Post by wandererfan »

aapo wrote: Wed Sep 21, 2022 9:08 pm I finally had time to compile your branch and test. I got somewhat mixed results, and there was something odd with the ComplexSection below, might be because the section line Sketch has splines. The left side of the ComplexSection looks correct to me, but then it goes haywire when I try to make all the hole structures visible in the same section.
Today's version is a little better.
20220921ComplexSectionTest.png
20220921ComplexSectionTest.png (33.14 KiB) Viewed 327 times
aapo wrote: Wed Sep 21, 2022 9:08 pmAs a side note, the input for the operation should be validated somehow. If I select the 3D body itself (instead of a body View) and the Sketch in the tree view, and press the ComplexSection button, the tool appears, but the whole FreeCAD crashes when I try to generate the bogus section view. I think it should validate that I have a View and a profile selected, and not some uncompatible objects.
It doesn't crash with today's version, but it doesn't produce a result either. The profile isn't getting extruded into face and everything goes downhill from there.

You're way ahead of me on input validation. I haven't given that any thought yet.

Thanks for the test file.
User avatar
FBXL5
Posts: 412
Joined: Sat Aug 03, 2019 8:45 pm

Re: Complex Sections

Post by FBXL5 »

aapo wrote: Wed Sep 21, 2022 7:09 pm I hope this proof-of-concept of yours can be somehow added to your new tool, it would be really useful tool for people making rotating machinery drawings.
+1
aapo
Posts: 464
Joined: Mon Oct 29, 2018 6:41 pm

Re: Complex Sections

Post by aapo »

wandererfan wrote: Wed Sep 21, 2022 10:36 pm Today's version is a little better.
Indeed. I changed my example file slightly to ensure that the spline portions of the section do not overlap the internal features, and got much improved results by setting all auxiliary and smooth lines to "false" with your new version. The resulting section is almost correct, the only problem is the non-continuous section hatching and thin vertical ghost lines (probably related to failed hatching), which show at the spline endpoint locations. Very curiously, if I choose to not use the automatic section hatching, but instead hatch the areas manually, the hatching works flawlessly and the ComplexSection looks perfect! What could be the reason for this?

20220922 TD ComplexSection test_p02.png
20220922 TD ComplexSection test_p02.png (52.03 KiB) Viewed 200 times
20220922 TD ComplexSection test_p03.png
20220922 TD ComplexSection test_p03.png (38.16 KiB) Viewed 200 times
Thanks for the test file.
You're most welcome! Thanks for the improved profile cutting in the new version, now it can already fulfill many new use cases by replacing the automatic section hatching by manual hatching of the faces. :D

Code: Select all

OS: Debian GNU/Linux bookworm/sid (KDE/plasma)
Word size of FreeCAD: 64-bit
Version: 0.21.30420 +2 (Git)
Build type: Release
Branch: (HEAD detached from 7447ed1a76)
Hash: d187a99e74ddae7bee3d2c6b86561cf12b89ba4a
Python 3.10.7, Qt 5.15.4, Coin 4.0.0, Vtk 7.1.1, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods: 
  * Assembly4
  * Render
  * fasteners
  * FCGear
  * Manipulator
  * Curves
  * sheetmetal
Attachments
20220922 TD ComplexSection test v2.FCStd
(60.79 KiB) Downloaded 5 times
user1234
Veteran
Posts: 1851
Joined: Mon Jul 11, 2016 5:08 pm

Re: Complex Sections

Post by user1234 »

A very good and needed feature, many thanks!

Greetings
user1234
Post Reply