PDA

View Full Version : How to 'crop' a g-code



paulus.v
25-11-2016, 11:44 AM
Hi all,

I'm trying to figure out a way of cropping a g-code. There are only G1 lines, lot of them, and I need to eliminate the lines that are falling out of a given shape in the XY plane. I do not care about safeZ for the returning or any fancy features, just eliminating the unnecessary movement outside of the workpiece.
Generating a separate toolpath for each shape is time consuming... Not to be fooled by the simple appearance of the example, there is a lot of Z movement as well.

Any help is greatly appreciated!

Paul

19705

magicniner
25-11-2016, 01:10 PM
Generating a separate toolpath for each shape is time consuming

It shouldn't be, that is a really quick job in any competent CAM system, just use a tool path which supports a boundary or border to limit the cut area then add a boundary of the shape you need and POST the code for each shape,

- Nick

paulus.v
25-11-2016, 01:19 PM
if you remember, here (http://www.mycncuk.com/threads/9883-3D-contour-in-inventorCAM-%28solidCAM%29-or-other-CAM-software) is why it is so time consuming... Now I have to generate separate toolpath for each triangle separately. I already have the toolpath for a surface big enough to include every shape I need, but now I need to eliminate the unnecessary movement.

magicniner
25-11-2016, 03:10 PM
Yes, I guessed that it was related but generating the toolpath for a full surface then chopping up that toolpath simply isn't done, you chop up the surface then generate toolpaths for the parts or you cut the full surface then chop out the parts.
If your CAD/CAM isn't capable of the above you might need to cut two or more copies of your full surface to be able to machine out your parts

I don't think you realise just how complex a mathematical problem what you're asking for constitutes, it would need to

1 Recognise which paths needed to be truncated and where
and
2 Calculate which truncated paths then need linking
and
3 Would need access to the surface data in order to know how to link them without gouging your part
and
4 Generate the paths to link paths
and
5 Insert the links into the modified truncated code

The reason no one writes software to edit complex 3D toolpaths generated in another package within a boundary like this is because if they can do that they can write a CAM package that does the job properly in the first case and sell that to a mass market.

Simply buy a CAM package that can do what you need, or provide enough information about what you're trying to achieve so the guys can analyse the full problem, not just the problem as you see it after reaching your own dead end.

paulus.v
25-11-2016, 03:21 PM
I don't think you realise just how complex a mathematical problem what you're asking for constitutes, it would need to


I do not see where it is the complexity. My g-code is a list of points defined by XYZ. I need to look at the the XY coord. of every line and compare with my shape. If the point is inside the shape keep the line, if it is outside delete it. That simple.

To get an idea of what I'm doing, I have the shapes already cutout and I'm applying a surface texture on them. I need to eliminate the extra movement, cutting out air, around the shape.

magicniner
25-11-2016, 03:25 PM
I do not see where it is the complexity. My g-code is a list of points defined by XYZ. I need to look at the the XY coord. of every line and compare with my shape. If the point is inside the shape keep the line, if it is outside delete it. That simple.

To get an idea of what I'm doing, I have the shapes already cutout and I'm applying a surface texture on them. I need to eliminate the extra movement, cutting out air, around the shape.

Which leaves you with a set of moves which don't join up and aren't linked ;-)

paulus.v
25-11-2016, 03:30 PM
Which leaves you with a set of moves which don't join up and aren't linked ;-)

Doesn't matter. The moves are the dotted lines in my sketch. There will be a G1 move from the last point of one texture line to the first point of the next line. It will cut through air anyway.

magicniner
25-11-2016, 03:40 PM
Doesn't matter. The moves are the dotted lines in my sketch. There will be a G1 move from the last point of one texture line to the first point of the next line. It will cut through air anyway.

Sorry, I didn't realise it was so simple, I await your elegant software solution with bated breath, meanwhile the rest of the world does this in CAD/CAM :wink:

Greeny
25-11-2016, 07:31 PM
In geometry, the term for what you want to do is 'clipping'
Try a search for 'polygon clipping'
It seems like a simple task but is made difficult by lots of tricky edge cases.
If you can code in c++ or c# or Delphi i can recommend Angus Johnsons excellent freeware 'Clipper' http://www.angusj.com/delphi/clipper.php
Cheers

magicniner
26-11-2016, 12:13 AM
If you can code in c++ or c# or Delphi i can recommend Angus Johnsons excellent freeware 'Clipper' http://www.angusj.com/delphi/clipper.php
Cheers

That looks like a really useful bit of software written by someone with an understanding of the problems involved in truncating lines with a shape, but surely the problem with G Code is "Simple" ? :D

- Nick

paulus.v
13-08-2017, 01:59 AM
A late response on this problem...


In geometry, the term for what you want to do is 'clipping'
Try a search for 'polygon clipping'
It seems like a simple task but is made difficult by lots of tricky edge cases.
If you can code in c++ or c# or Delphi i can recommend Angus Johnsons excellent freeware 'Clipper' http://www.angusj.com/delphi/clipper.php
Cheers

First of all thanks a lot Greeny for pointing me in the right direction!

For a programmer it was a 5 minutes job. The solution was simpler than the clipper library (certainly included in the library as well), it is called ray casting algorithm (https://en.wikipedia.org/wiki/Point_in_polygon).
Here are code examples (https://rosettacode.org/wiki/Ray-casting_algorithm).



I don't think you realise just how complex a mathematical problem what you're asking for constitutes

Nick, I'm sorry to tell you that this complex mathematical problem is done by a computer in less than a second, by comparing 50k points against a 12 points defined polygon.

magicniner
13-08-2017, 10:06 PM
Nick, I'm sorry to tell you that this complex mathematical problem is done by a computer in less than a second, by comparing 50k points against a 12 points defined polygon.

Paulus,
I'm sorry to have to tell you that how quickly a computer runs a chink of code has no relationship to the complexity of the maths used by the programmer to address the problem or how smart the programmer had to be to write the code :D

Or could any dummy have done the job? ;-)