cq.Sketch vs. 3D solid cut/intersect/union

6 views
Skip to first unread message

neri-engineering

unread,
Jul 4, 2024, 7:32:57 AM (2 days ago) Jul 4
to CadQuery
This idea was inspired as a result of reading the replies in thread "Edge selector advanced example" which was started by me recently.

I have read [somewhere] that for optimum performance a simply-extruded object which lacks further complexity is best built in 2D and then extruded to 3D as the final step.

However I find myself sticking to the approach of creating 3D solids sooner rather than later, and then using the Workplane.cut(), intersect(), and union() methods.  This just feels more intuitive, more natural to me.

I had a look at the Sketch tutorial page: https://cadquery.readthedocs.io/en/latest/sketch.html .  There, upon first glances I didn't find explicit use of cut(), intersect(), and union(), presumably because those concepts only apply to 3D objects, namely things associated with a Workplane.

When I construct certain objects (good examples for that are straight-toothed involute spur gears or timing belt pulleys), I'd like to construct the 2D silhouette first by doing cut(), intersect() and union() in the 2D space, but because I have not learned how to do that intuitively using Sketch or other equivalent 2D concepts, I find myself extruding everything to 3D, with slight overlaps or overhangs to make cleaner operations, and then doing the boolean operations (cut/intersect/union) in the 3D space.

For example, to create my timing belt pulley, I first use Workplane.polygon() with circumscribed=True flag (is that flag even available for Sketch.regularPolygon()?).  I then create a cookie-cutter cavity for each belt tooth cutout, which essentially consists of a 2D shape defined as a Workplane (again) using the constructs moveTo(), threePointArc(), lineTo(), and close().

What would be neat is if I could iteratively rotate this "2D cookie cutter cavity" when it's offset from the origin, thereby cutting out sections of the 2D polygon defined initially, all in 2D.  Something like this.

However without biting my nails too much, without pulling my hair out too much, I've stuck to the method which I KNOW WORKS which is to extrude these objects to 3D and perform the boolean operations (cut/intersect/union) there.  I do this because the several times I tried to do the boolean operations in 2D, it failed for me (and I didn't persist too long in my attempts).  I'm sure that there is some "magic sauce" to this that I'm currently missing.

What are your thoughts on this?  Am I missing something obvious when working with 2D objects?  Or is my 3D approach "acceptable"?  The 3D approach certainly makes things much more intuitive FOR ME.

I am about to pull the changes made for edge selection to give it a go.

By the way I'm not sure that you realize how powerful CadQuery is for large projects - for one, you can track changes as "diffs" between text files in Subversion or Git, because all your objects are defined as code [Python].  You can define constant files of far-reaching distances and offsets, diameters and tolerances.  The actual code that generates your parts would then usually utilize formulas, directly in the code, by incorporating the various constants defined externally.  I'm really surprised that more "engineering schools" don't teach this method of doing things.  In a sense, I see CadQuery and such tools as a cross between engineering, mathematics, and computer programming/science, because all three skills are needed to be successful.  I think in the future engineering schools will require their students to learn computer programming; I know for certain (esp. here in Germany) that this currently is not the case.

I have also found that OpenCascade is a very powerful engine, but I find myself needing to "dance around" some broken aspects of it.  It's as if the engine was written by some very intelligent people who were a little bit impatient.  Maybe Russians?

Sent with Proton Mail secure email.

Jeremy Wright

unread,
Jul 4, 2024, 8:37:24 AM (2 days ago) Jul 4
to neri-engineering, CadQuery
Have a look at the "mode" parameter of the Sketch face API. 


--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/Vy8-st6aD8YTlB3U5nIMs7YTjuKdTvRqJ-_Wn5BolRvYmMq2SCok6PP1eBuWDperdR5PFShRxARH_91KbUt_qC49hCppMVcMy4IIWCSMeAc%3D%40protonmail.com.

neri-engineering

unread,
Jul 4, 2024, 9:03:27 AM (2 days ago) Jul 4
to Jeremy Wright, CadQuery
Ah, that makes sense.  I was wondering what that "mode" was for.  Finally explained.  Somehow I thought that 'c' was "circumscribed" but obviously I was way off - it a high-level flag that applies to all the operations.

I may have a go creating the timing belt pulley with Sketch.

But there are still two small problems, at least.  First, the Sketch.regularPolygon() does not have a circumscribed flag, but that's not a big deal because I already have the formulas for the affected diameter, just need to rotate the polygon by half a notch.

Second, I would need equivalents to moveTo(), threePointArc(), lineTo(), and close(), which I'm using as part of Workplane, to define the cavity which is being carved out of a regular polygon.

I have found Workplane easier to use, probably because the documentation/examples are more thorough.  Of course the caveat is that I'm doing all my boolean operations in 3D.  I started my CadQuery journey by using almost exclusively Workplane, and I am a creature of habits, mostly.

Is it worth the effort, to try to use Sketch?  Is it really bad practice to do what I am doing, which is creating little bits in 3D and then using the 3D boolean operations to carve, concatenate, and intersect?

BTW I just got the changes from PR 1514 from Lorenz, the addition of Workplane.filter().  Tried the example from his email and it works wonderfully.  So there is no longer any need for me to try Sketch, except maybe that it's "preferred" or "faster".

Sent with Proton Mail secure email.

Jeremy Wright

unread,
Jul 4, 2024, 9:18:41 AM (2 days ago) Jul 4
to neri-engineering, CadQuery
> Is it really bad practice to do what I am doing, which is creating little bits in 3D and then using the 3D boolean operations to carve, concatenate, and intersect?

It is typically discouraged to overuse a boolean (OpenSCAD) style of modelling with a B-Rep kernel since it is not designed to work that way. However, there are certainly many legitimate uses (i.e. creating molds), and if you are willing to accept things like performance issues, then use it the way you want. Part of it depends on the complexity of your models, but (in general) if you focus on using the B-Rep kernel in the way that it "thinks", you will probably be better off in the long-term.
Reply all
Reply to author
Forward
0 new messages