Polyline to spline

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
bergdesign
Junior Member
Posts: 13
Joined: Sat May 25, 2019 4:23 pm

Polyline to spline

Post by bergdesign » Sat May 25, 2019 5:01 pm

Is there a tool or script for converting a polyline to a fit-points-spline or a control-points-spline? have searched the docs, the ebook and the forums, and I haven't been able to find anything so maybe this should just be a suggested feature.

I do a lot of CNC routing, but I start with geometry from SketchUp which is of course polygonal. Most of the routing is straight lines so the polygonal nature of the 2D exported geometry is fine, but circles and curved edges pose a problem because most CAM software sucks at turning tesselated geometry into smooth machine movements. Circles are simple to reconstruct because a two-point circle is easily constructed from a polygon, but curved edges require a lot of clicking with the fit points spline tool to reconstruct. Because you already have the ability to construct a polyline from selected segments, it seems it would be easy to add two commands to then convert an existing polyline into either a fit-points-spline or a control-points-spline. I understand that this has cases where the behavior can be complicated since polylines may not be composed entirely of straight segments, but it seems that the internal functionality to convert a polyline's points into a set of usable spline points already exists, and it would save a lot of time compared to constructing a spline by clicking each point manually.

Thanks,
Brock Brandenberg

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Polyline to spline

Post by andrew » Mon May 27, 2019 10:55 am

There's no dedicated tool for that.

Here's a way to do it without clicking each point.

First, we have to set an undocumented preference in the QCAD3.ini file (we only have to do this once):
1. Misc > Development > Script Shell
2. In dialog click "Show ECMAScript Shell"
3. In the script shell, type:
RSettings.setValue("InfoStorePositions/PolylineNodes", true);
4. Press Enter

To draw a spline with fit points from polyline nodes:
1. Select the polyline
2. Misc > Information > Store Positions
3. Draw > Spline > Spline (Fit Points)
4. Misc > Information > Use Positions
5. Escape

More information about reusing drawing positions:
https://qcad.org/tutorial-reusing-drawing-positions
Attachments
Screen Shot 2019-05-27 at 10.51.11.png
Screen Shot 2019-05-27 at 10.51.11.png (49.09 KiB) Viewed 7671 times

bergdesign
Junior Member
Posts: 13
Joined: Sat May 25, 2019 4:23 pm

Re: Polyline to spline

Post by bergdesign » Tue May 28, 2019 12:24 am

Awesome workaround :) Thanks Andrew.

Brock

ubi_laptop
Newbie Member
Posts: 4
Joined: Mon Dec 12, 2016 11:59 am

Re: Polyline to spline

Post by ubi_laptop » Tue Aug 30, 2022 7:18 am

hi andrew,
Im trying to do the same process you described in five steps on a mac with pro versione 3.27.1.
As i give the command "use position" the program draws the FIRST point and then wait for the following, not using other point.
I can't guess what I'm missing.
thank you for your reply and this awesome program !
daniele
Schermata 2022-08-30 alle 08.16.07.jpg
Schermata 2022-08-30 alle 08.16.07.jpg (205.02 KiB) Viewed 5023 times

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Polyline to spline

Post by andrew » Tue Aug 30, 2022 7:29 am

This preference is now available under:

Edit > Application Preferences > Info > Store Positions > Polylines

Check the option Store Nodes.

Then proceed as before to draw a spline with fit points from polyline nodes:
1. Select the polyline
2. Misc > Information > Store Positions
3. Draw > Spline > Spline (Fit Points)
4. Misc > Information > Use Positions
5. Escape

ubi_laptop
Newbie Member
Posts: 4
Joined: Mon Dec 12, 2016 11:59 am

Re: Polyline to spline

Post by ubi_laptop » Tue Aug 30, 2022 12:19 pm

thank you. I did miss that !

CVH
Premier Member
Posts: 3416
Joined: Wed Sep 27, 2017 4:17 pm

Re: Polyline to spline

Post by CVH » Tue Aug 30, 2022 7:26 pm

Brock,
bergdesign wrote:
Sat May 25, 2019 5:01 pm
Most of the routing is straight lines so the polygonal nature of the 2D exported geometry is fine, but circles and curved edges pose a problem because most CAM software sucks at turning tesselated geometry into smooth machine movements.
It can't be smooth when it has hard corners, right.
Sorry to say but there is almost no way back from approximations by line-segments unless you really know the used algorithm and its parameters.
One can do a lot with a combination of a LAF and G64 ... But the rounding will always be arbitrary.

And, there is no certainty that nodes of a polyline with line segments are a match with the original fitpoints of a spline.
E.g. a spline with 4 fitpoints may be segmented in over 50 lines.
In the best case it will only look almost like the original spline but then with 51 fitpoints. :wink:
Still, in the absence of original data, I need to use this workaround more than I like.

Next, most CNC drivers can't handle splines, In QCAM these will be approximated by arc segments before exporting them as G-code.
See the tolerance setting for the Explode tool.
With a high fitpoints count one gets more tiny arc segments ... Even more with a minute tolerance. e_geek

Regards,
CVH

Post Reply

Return to “QCAD 'How Do I' Questions”