Author Topic: Reverse functionality for entities other than Polyline  (Read 13720 times)

Offline earlgrey

  • Ewok
  • *
  • Posts: 9
    • View Profile
Reverse functionality for entities other than Polyline
« on: November 02, 2013, 01:59:54 am »
In order to change direction of a toolpath for an open POLYLINE, there is a menu entry "Menu/Edit/Polyline/Reverse".

We need the same reverse function for SPLINE. This should be easy to implement (just change the order of the control points)?

Same for ARC (swap start and end angles, and set it to "reversed"), is this possible (including writing back into DXF via Export / To DXF)?

Reason:
We need to machine irregular, curved shapes which are defined by a set of lines, arcs and splines.

Insise / Outside property of the Profile MOP does not work in such case - unless *all* entities of that shape have the same direction.

Please note that we do not want to convert the complete shape into one large polyline (Ctrl+A, Ctrl+J), for several reasons:

First, we would like to keep the original geometry for as long as possible (going back and forth from / to CAD and CAM).

Next, we aim to maintain highest precision for the curved parts, as we want to cut a smoothly curved shape. For splines, there is a line approximation during g-code generation (setting "spline to polyline tolerance" to a very small value). However, I am not sure which resolution is used during the "join" command - when all selected shapes are converted to one polyline.

For arcs, these are directly represented in G-code, so that the machine will follow the arc at its highest precision. Is my understanding correct?

Thank you!

Offline dwc

  • CNC Jedi
  • *****
  • Posts: 549
    • View Profile
    • corson.ch
Re: Reverse functionality for entities other than Polyline
« Reply #1 on: November 02, 2013, 08:56:20 am »
Hi Earl,
I would join the segments, you will loose nothing.
As I said in the other response as far as I know CB does not use splines internally.
All splines are turned into a multitude of straight segments. 
A polyline contains straight segments and curves and these are turned into g-code without and changes.
If you want to keep your original objects make copies on another layer and join them.
Best,
Don

Offline earlgrey

  • Ewok
  • *
  • Posts: 9
    • View Profile
Re: Reverse functionality for entities other than Polyline
« Reply #2 on: November 02, 2013, 12:14:28 pm »
"join the segments, you will loose nothing."
Don, that's exactly what I am trying to find out:

It is my impression that the resolution of Spline-> Polyline conversion during the Join operation is much lower than what the "spline to polyline tolerance" parameter enables for the spline -> G-code conversion. Just telling from the screen renderings, and how many line segments I get.

Could we have a qualified answer from the Cambam makers on this one? I think that the "spline to polyline tolerance" has been provided for exactly this reason: I can set it very low - in order to achieve a spline approximation for production much closer to what we get with the polyline conversion?

I will make tests with various setting and approaches during the next weeks, in order to see what the impact on the produced workpiece is.

Beautiful watches, btw!

Offline Jeff_Birt

  • CNC Jedi
  • *****
  • Posts: 821
    • View Profile
Re: Reverse functionality for entities other than Polyline
« Reply #3 on: November 02, 2013, 12:48:17 pm »
I think your likely chasing phantom precision. You will have far more inaccuracies in you final part due to tool deflection, tool wear, machining strategy, backlash, thermal expansion, etc., than you will get from converting spines to polylines.

Offline llaves

  • Droid
  • **
  • Posts: 51
    • View Profile
Re: Reverse functionality for entities other than Polyline
« Reply #4 on: July 08, 2024, 15:09:54 pm »
I know this thread is over 10 years old, but I just found it yesterday when I was looking to see if there was a way to reverse a spline.
DWC wrote:
     I would join the segments, you will loose nothing.
I don't find this to be true. If you join the segments the spline becomes a polyline and is no longer editable as a spline. You can't move the control points, or change the shape of the spline. You have a bunch of polyline points that edit in a completely different way.

The slightly unhelpful suggestion is to pay attention to the direction you draw your splines so they're oriented consistently when you go to create a toolpath.

Offline Bob La Londe

  • CNC Jedi
  • *****
  • Posts: 4522
  • ^ 8.5 pounds on my own hand poured bait.
    • View Profile
    • CNC Molds N Stuff
Re: Reverse functionality for entities other than Polyline
« Reply #5 on: July 08, 2024, 16:38:57 pm »
Quote
Could we have a qualified answer from the Cambam makers on this one?

Snerk!  Ten years later and this almost made me blow coffee out my nose. 
Getting started on CNC?  In or passing through my area?
If I have the time I'll be glad to show you a little in my shop. 

Some Stuff I Make with CamBam
http://www.CNCMOLDS.com

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 9024
    • View Profile
Re: Reverse functionality for entities other than Polyline
« Reply #6 on: July 08, 2024, 16:46:52 pm »
Hah!  Mine was beer!  I just finished mowing 4.5 acres in 94F weather.  I sat down and saw the dateline on this!  :D

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7482
    • View Profile
    • Cambam V1.0 French Doc
Re: Reverse functionality for entities other than Polyline
« Reply #7 on: July 08, 2024, 22:30:06 pm »
Hello

Quote
Could we have a qualified answer from the Cambam makers on this one? I think that the "spline to polyline tolerance" has been provided for exactly this reason: I can set it very low - in order to achieve a spline approximation for production much closer to what we get with the polyline conversion?

The result is exactly the same ; you can verify this way:

1 ) Create a spline,and duplicate it (white layer)

2 ) convert one of the spline to polyline using CTRL P (blue layer)

3 ) define an engrave mop for the polyline and for the spline

4 ) generate the toolpaths for both

5 ) for both mop, convert Toolpath to geometry (right clic on the mop > Toolpath to geometry) and offset the toolpath to the right (purple layer)

6 ) select the polyline (the one that you get by converting the spline to polyline), and the 2 polylines obtained by toolpath to geometry) and enter in edit mode.

You can see that the toolpaths obtained with the spline is the same than the toolpath obtained with the spline converted to polyline.

If you want to start the cut at the other end of a spline, just change the machining direction (climb/conventional) OR set machining direction to mixed and define the machining start point at the end you want (the red circle)

In case of engraving mop, there is no climb/conventional, so define the machining start point at the end you want.

Of course, this works also for arcs.

++
David
« Last Edit: July 08, 2024, 22:58:16 pm by dh42 »

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1983
    • View Profile
    • pixelmaker
Re: Reverse functionality for entities other than Polyline
« Reply #8 on: July 09, 2024, 11:52:35 am »

You can see that the toolpaths obtained with the spline is the same than the toolpath obtained with the spline converted to polyline.

++
David

Hello
I don't think this is the starting point for this feature request.
In difference to a polyline, the contour of a spline follows a formula. It determines the arc between two nodes.
The formulas for the start and end points cannot simply be exchanged to change the direction of a spline. By dragging the handles of the spline, you can change the course of the entire line between two nodes. The line of a spline is a linear function.

In difference, a polyline is made up of a series of symmetrical arcs.
The advantage of a spline over polylines is that very complex geometries can be mapped with a minimum of geometric definition data.
The disadvantage is that size calculations are complicated. Not even Autocad can calculate dimensions on splines. This is why all splines are converted into polylines each time they are edited. The resolution is set with the "Spline to polyline tolerance"

If you draw arcs from polylines, they can no longer be edited afterwards. You cannot deform groups of arc segments in polylines at once.
This is why the TE ask for a function 10 years ago in which polylines are converted back into splines.

This processing option for splines, especially when natural shapes are involved, ends in CamBam with the first edit operation. CamBam always works internally in polylines. If you edit a spline, it becomes a polyline.
This is a dead end for editing a line.

In such a case, I export the drawing back to Illustrator. This converts all the arcs back into splines/Bézier curves. I then make any necessary edits in Illu.If I export the drawing back to CamBam, I have splines again.I think there should be a similar way using Inkscape, as this software also works with Bézier curves.

CamBam just can't do everything.


ralf
« Last Edit: July 09, 2024, 12:16:20 pm by pixelmaker »

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7482
    • View Profile
    • Cambam V1.0 French Doc
Re: Reverse functionality for entities other than Polyline
« Reply #9 on: July 09, 2024, 16:17:32 pm »
Hello

There is a way to convert Polyline to Spline, but this not exactly revert to the original spline ; see on the picture 1, the spline at the bottom is the top spline that have been converted to polyline then converted to spline.

You can use this python script to convert polyline to spline.

Code: [Select]
# New CamBam Python Script

pline = Polyline()

for ent in view.Selection:
  if ent.GetType().Name == "Polyline":
    pline = Polyline(ent)
   

    spline = Spline(pline,0)

    doc.Add(spline)


This code is more useful if you want to "smooth" a polyline with sharp angles as on picture 2

play with the value in: spline = Spline(pline,0)

for the example in picture 2, I used a value of 100 instead 0 (0 = closest to original shape)

++
David

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1983
    • View Profile
    • pixelmaker
Re: Reverse functionality for entities other than Polyline
« Reply #10 on: July 10, 2024, 10:48:39 am »
Hello David
thank you very much for this script. I have done some tests with it.
Contrary to my usual way of working, with this script it is necessary to have many nodes in the polyline. Then the spline will be most accurate in the result. So accurate that you can work very well with it. It always amazes me how little programming is needed to achieve such good results.


I have done two series of tests with:
CamBam plus [1.0] x64
Copyright © 2020 HexRay Ltd
CamBam.CAD : 1.0.7389.20585
CamBam : 1.0.7389.20589



1st test series with spline to polyline tolerance of 0.01
2nd test series with Spline to polyline Tolerance of 0.001
I have saved the settings and restarted CB.
You can clearly see that the setting Spline to polyline Tolerance of 0.001 generates significantly more nodes and contradicts your bug report from 2016. The setting has an effect on the number of nodes, i.e. also on the precision when converting splines into polylines.
This is how I proceeded with the tests.
I drew two splines. I copied these to keep the originals.
I joined both splines on a new layer (CTRL J).
I did this once with spline to polyline tolerance 0.01 and once with tolerance 0.001. The difference is so clear that I don't see a bug. See the attached screenshots or the attached CamBam file

I then converted the polylines back into splines on two new layers using your script.
On the polyline that I converted with the low tolerance, I hardly see any differences from the original spline.
As the Spline to polyline tolerance setting works perfectly, you can create many nodes with lower values (0.001). This is really important here because the script does not generate precise splines with just a few nodes.
Thanks again for the script

ralf


« Last Edit: July 10, 2024, 11:07:27 am by pixelmaker »