Create arcs and circles from tessellated segments

This forum is for 'Work-in-Progress' QCAD user developed script Add Ons and Plug-ins.

Please use this forum to request/submit your script Add-Ons & Plug-in idea's.

Moderators: andrew, Husky, J-J

Post Reply
bergdesign
Newbie Member
Posts: 5
Joined: Sat May 25, 2019 4:23 pm

Create arcs and circles from tessellated segments

Post by bergdesign » Fri Oct 09, 2020 3:06 pm

I would love to have a feature/tool/script/plug-in added to QCAD. I work regularly with DXF files generated from SketchUp, and the problem is that SketchUp generates tessellated arc and circles in all 2D output. This tessellated output doesn't work well with CNC machines because the tool path generation can create stops and starts as it randomly sees fit, or the automatic conversion to smooth curves just flat out sucks and a perfect 24 segment circle gets converted to three or four bezier curves that are no longer accurate.

So it's common practice for me to use three-point arcs and two point circles to replace the tessellated geometry, which goes fairly quickly but the deletion of the existing line segments is the tedious and error prone part... Because there is now overlapping geometry, I find it best to drag a selection box across part of the arc/circle (without selecting the arc/circle) and delete those segments then drag a selection box across the remaining segments to delete them.

So, I have been mulling writing a plug-in to take a user selection of line segments, order the endpoints, pick the start and end points and one near the middle (depends on odd or even number of segments if you have a midpoint), then generate a three-point arc, delete the original selection and select the newly generated arc so the user has visual confirmation. If the points all share two entities, you have a complete circle and can generate a two point circle, again deleting the original selection and selecting the newly generated circle. Of course there are inaccuracies and edge-cases to automating anything, but 99% of the scenarios can be covered with really simlpe logic and minimal error checking. The tessellated geometry is always quite clean.

I'm an old-school developer, but this has been on my to-do list for waaayyyyyy too long because it's always hardest to jump into a framework and gain familiarity before you can actually be constructive, and I just haven't done that yet :/ I pulled the source and have browsed through many of the scripts for the native tools (like the ShapeAlgorithms class), but I haven't found a good example script to jump-off from that does something with a user selection of existing entities (can anyone suggest an appropriate existing script?) It looks like I would use queryContainedEntities() and then work with the returned set of entities, then create an RArcEntity or RCircleEntity and insert it into the document tree, deleting the original contained entities. Then write the other 99% of the code that makes it usable :)

If anyone with experience wants to go at this together, I'm all ears. I'd generate icons and psuedo-code the behavior logic I'd like to see, as well as handling edge cases and error conditions, and whatever else I can write.

Thanks,
Brock

CVH
Premier Member
Posts: 904
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Create arcs and circles from tessellated segments

Post by CVH » Fri Oct 09, 2020 7:41 pm

Hi,
You mean curved lines that are approximated with line segments.
Kind of interpolated.
Is that standard for SketchUp?
I would see 'to segments' as an optional output method for an old CNC setup.

3 scripts of mine in the open take a selection.
Encrypted by a completely uneducated idle starting with no knowledge of the language, the object oriented nature and the QCAD framework.
1- FlexPainter + there is a ton of do and don'ts in the script file itself.
2 - 3 can be found here:
viewtopic.php?f=30&t=7544
viewtopic.php?f=30&t=7497
1 is already for some time a part of a standard installation.

The fourth one is in development and is a different story on its own.
Tile2Hatch is an addon that converts a tile to a hatch pattern and it starts with approximating all to line segments. :wink:

It is the other way around that is quite another story.

A lot off scripts are included in compiled form.
A fairly complete source apart from PRO scripts is github : https://github.com/qcad/qcad

All the classes are documented here: https://www.qcad.org/doc/qcad/latest/de ... tated.html

Getting lists from the resources is usually "get" or "query".
Just key "query" in the classes search field will reveal a multitude of queries to choose from.

A file or different files, small and handy, with some example would be nice.
If there is indeed a pattern in it the way back to curved is much easier. :)

Regards,
CVH
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

bergdesign
Newbie Member
Posts: 5
Joined: Sat May 25, 2019 4:23 pm

Re: Create arcs and circles from tessellated segments

Post by bergdesign » Sat Oct 10, 2020 5:46 pm

Hi CVH.
CVH wrote:
Fri Oct 09, 2020 7:41 pm
You mean curved lines that are approximated with line segments. Kind of interpolated. Is that standard for SketchUp?
Unfortunately, that is the standard for SketchUp. It's a polygonal modeler, and while it maintains some internal data about each curve which allows you to change the number of segments used to represent each curve inside your 3D model, SketchUp's 2D output to DXF is always the segmented representation. If the 2D DXF is not subsequently edited to change the segments to smooth curves, the CAM software typically stops and starts at the endpoints of each segment causing wasted machine time and excessive tool wear :/

I appreciate the tips for additional scripts to look at. It's always hardest getting familiar with the "domain" that is being programmed, so it helps a lot to have more code samples when learning how to accomplish specific tasks. The logic of my feature is the easy part, once I know how to speak QCAD's language. It's all the supporting code that integrates it into QCAD that I need to get familiar with.

Thanks,
Brock

CVH
Premier Member
Posts: 904
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Create arcs and circles from tessellated segments

Post by CVH » Sat Oct 10, 2020 7:27 pm

bergdesign wrote:
Sat Oct 10, 2020 5:46 pm
causing wasted machine time and excessive tool wear :/
Tell me what ... I am an engraver, engraving points down to the sub 0.1 mm.
A simple 0.05 plunge down in non-ferro can ruin it.
Sharp dead end corners will rip it apart.
Re-dressing is the hardest endeavor and take the longest.

Continuous motion within a narrow margin is the key to increase standing time.
I have the luck that my CNC driver has a look ahead feed algorithm.
Simply because the guy who is marketing it has real life know how.
Look up: Eding CNC ... it is no longer a hobby tool.

Happy reading the resources,
CVH
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

bergdesign
Newbie Member
Posts: 5
Joined: Sat May 25, 2019 4:23 pm

Re: Create arcs and circles from tessellated segments

Post by bergdesign » Sun Oct 11, 2020 3:15 pm

I'm at the opposite end of the scale, running a 5ft x 10ft CNC router :) It's a older machine by a Canadian company AXYZ that started by making CNC controllers, and while it uses its own DNC software that does some optimization when downloading g-code to the machine, it relies on 3rd party software like Enroute or VCarve to do the initial tool path generation. Unfortunately, the DNC software doesn't seem to do any look-ahead X-Y optimizations because it will happily allow the head to dwell at the end of a straight segment even if the next straight segment is only a fraction of a degree off... So if you leave a tessellated curve as, for example, ten (10) separate straight segments, the machine will dwell at the end of every segment. If you instead combine the ten separate segments into a polyline in the CAM software, you will get continuous motion but will have a ten-sided "curve" cut in your material. So to make the router bit stay cool and sharp and make the curves nice and smooth, I convert all tessellated curves into true arcs that cut smoothly and continuously.

So my problem isn't that it breaks bits or ruins material, it's that the dwelling at corners causes rubbing and heating of the bit which shortens its lifespan. I have to keep it moving and keep the chip size up to make it happy.

Interesting stuff at Eding - thanks. I have a friend that manufactures 3D printers that may be interested in their controllers, so I'll pass the info along. My older CNC router could be retrofitted with a newer controller, but the task would be a monumental undertaking so I'll just upgrade to one of AXYZ' newer modern machines some day so that I can spend my time designing and making things :)

Thanks,
Brock

CVH
Premier Member
Posts: 904
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Create arcs and circles from tessellated segments

Post by CVH » Mon Oct 12, 2020 9:42 am

Brock,

The method you need is quite similar as on my wish list.
> The inverse of "Arc to line segments"

I think that we are speaking of closed contours mostly.
Select All >> Polyline from Selection
This creates logically closed polylines with closed contours.
My Eding CAM handles these but that is not certain for all.
>> Logically open Polylines

At that point one can check the selection:
if NOT a poly >> Reject
else Collect to process for arc's

Now we can step the segments of each collected poly:
When fewer vertexes (left) as 3 >> skip to next collected
Circle from the 3 first vertexes 1/2/3
Circle2 from vertex 1/2/4
When Circle equals Circle2 >> check vertex 1/2/5
NOT equals >> try next set of 3
When the former circle fitted over a wider span as N/N+1/N+2
>> replace segments by a single segment with a proper bulge.
>> start next set at N+2

When the poly ends up to be a full circle arc what is a fault condition for the bulge >> replace by circle

Quite rude I know, but I think it is a valid approach.
Bad thing is that any regular polygon and quite a lot specific polygons ends up as a circle.

Regards,
CVH
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

Post Reply

Return to “QCAD 'Script Add-On & Plug-in challenge' - Work in Progress”