Paths - Cut/Intersect/Purge

Contour Scanner And Trimmer

Scanning

This tool helps you to find nasty contours which might bug you and prevent your work from being ready for production. It will find open contours, closed contours and self-intersecting contours and checks for a set of other attributes. Bentley-Ottmann algorithm is used to check for those intersections. The algorithm works with the accuracy of the selected paths (epsilons). Self-intersections usually happen if you just have large overlaps where the contour crosses itself like an 'eight' character for example. Using the highlighting it's easy to find contours with unproper path handles. While in a CAD system an area of of a surface can only be calculated if the contour is closed and clean, finding self intersections in Inkscape is not required to do so. SVG format allows to calculate areas on open contours and self-twisted curves. This "artwork behaviour" makes it harder for handling machinery-like drawings for laser cutting, vinyl cutting or whatever. That's why we need to have extra sanity checks but we also have the great freedom of InkScape.

Finding self-intersecting contours does only work for curves with straight line segments (polylines) because it just calculates with a set of given XY points. It does not respect bezier curve segments. Bezier curves have no regular points but special handles, which define the slope of the curve per handle side (left and right). To properly handle a bezier curve we need to split the bezier curve in a lot of small linear lines (acting like infinitessimal solution). We can use the tool Approximate Curves by Straight Lines (Flatten Beziers) to do this by hand or we use the built-in method if Contour Scanner and Trimmer (will make your curve looking edgy or ugly possible). If you want to leave the shape of the line clean (bezier type, no edgy approximation) we can also use Split Bezier (Subdivide Path) or Add Nodes instead. But remember that your calculated self-intersection points will only be an approximation then. The higher the subdivide count is the higher the precision of the calculated self-intersecting points coordinates will be.

After performing operations, which flatten or split the bezier curve, we we can or should use Chain Paths to put the pieces together again.

Trimming

By having a set of flattened straight line and finding global intersections we can also trim the paths using python library called "shapely". This allows to receive cut segments. Some basic tools to remove duplicates, are integrated.

The result

Using Contour Scanner correctly, we get a planar graph style drawing, like the definition gives: "In graph theory, a planar graph is a graph that can be embedded in the plane, i.e., it can be drawn on the plane in such a way that its edges intersect only at their endpoints. In other words, it can be drawn in such a way that no edges cross each other. Such a drawing is called a plane graph or planar embedding of the graph. A plane graph can be defined as a planar graph with a mapping from every node to a point on a plane, and from every edge to a plane curve on that plane, such that the extreme points of each curve are the points mapped from its end nodes, and all curves are disjoint except on their extreme points. " (https://en.wikipedia.org/wiki/Planar_graph)

Tips

See also (similar extensions)

The user interface

grafik.png grafik.png grafik.png grafik.png grafik.png

Quick example

Using Contour Scanner and Trimmer we can check the different contours and their behaviour. Usually a contour can be open or closed and it can intersect with itself or not. This will give us 4 different combinations and we can use this information to find out where the intersections are using Bentley-Ottmann algorithm. Short examples:

4 different basic line "types" Marked paths by running the extension using colors and dot modifiers

grafik.png

grafik.png

Real example

Load sove graphic you want to fix

Depending on the steps you want to perform with the file maybe create some duplicate.

grafik.png

Run the extension

Configure the setting depending on what you want.

grafik.png

Fix the desired paths

Select the path to see the handles. The dot indicates that there might be something faulty. In the following example there are two handles at the same coordinate. We can pick one of them to drag it away from the other one. You can now delete the marking point

grafik.png grafik.png

After rerunning the extension the dot will not appear again:

grafik.png

Overlapping lines

Contour Scanner is powerful. It can find and merge overlapping lines in the set of flattened sub split lines. We find those line intersections between lines where the same slope exists and which cover each other fully or partially (collinear overlapping lines). See the graphic to understand the problem.

At the moment Contour Scanner cannot remove those overlaps in original paths.

grafik.png

From left to right:

Issues

Trimming bezier curves

There is no algorithm done to split the original bezier curve after finding intersection points and t parameters yet.

grafik.png

Create Links (Breakaway Connectors)

To create tabs in Inkscape, we cannot properly use the integrated eraser tool. It will clip only in a cosmetic fashion but we do not get the real paths we need. Creating links (also known as microtabs, tabs, bridges, breakaway connectors, links, perforations) is sometimes required for laser cutting or vinyl cutting. This extension allows to pinch paths to create according segments - no cosmetic one's, but real segments. It will split up open or closed contours with user defined rules. To get best output please try to close open paths before using. This extensions is ideal to cut cloth/textile stuff in the laser!

Also have a look at

grafik.png

Draw some contours

grafik.png

Run the extension and get result

grafik.png

Known issues

The path is not split up? Then please check if your path contains any connected Live Path Effect (LEP) which is associated with it. Like this:

grafik.png

You can remove it by using Apply Transformations extension for example.

Further development

See https://wiki.selfhtml.org/wiki/SVG/Farben/Kontur and https://svgwg.org/specs/strokes/#StrokeDashing

Destructive Clip

An Inkscape Extension which works like Object|Clip|Set except that the paths clipped are actually modified. Thus the clipping is included when exported, for example as a DXF file. Select two or more paths then choose Extensions|Modify path|Destructive clip. The topmost path will be used to clip the others.

Make some path and draw clipping border

Curves (including Arcs) in paths are not supported (use Extensions → Modify path → Flatten Beziers) and non-path objects in the selection will be ignored. Use Object → Ungroup.

Maybe you need to combine multiple contours with CTRL + K before running the extension

grafik.png

Run the extension and get the result

The order of selection defines what is clipped by which contour.

grafik.png

Filter By Length/Area

Paths with value smaller than the given threshold will be deleted. This extension might require to break up your object before.

Take some image

This is not a good example but shows the effect

grafik.png

Run the extension

grafik.png

Result

grafik.png

Incadiff

An Inkscape extension which applies successive difference operations on superimposed paths. Useful for plotter addicts as it removes hidden strokes. Incadiff works on paths and objects. It does not work for open paths. Incadiff does not operate like Contour Scanner And Trimmer and it does not remove duplicate lines if existing.

See also

Source: https://github.com/incaya/incadiff

grafik.png

Mutual Cut Line

This extension cuts exactly 2 (ideally straight) path segments and will create intersected elements. Depending on the path direction (which can be reversed) the ends are going to be cut against each other

Draw some paths

grafik.png

Duplicate the paths (CTRL + D) and give some different color

This step is optional but helps to understand what's going on here

grafik.png

Check the result

We repeat the previous step and this step for all variants to show the possible outputs. You can reverse the path using "Path → Reverse"


Two regular paths First and second path reversed First path reversed Second path reversed
Output with original as  overlap

grafik.png

grafik.png

grafik.png

grafik.png

Result only

grafik.png

grafik.png

grafik.png

grafik.png

Path Intersections

In case your resulting intersection markings are displaced please run Apply Transformations before running this.

Draw some example with intersecting paths

grafik.png

Run the extension

grafik.png

Check the intersections

grafik.png

Purge Duplicate Path Nodes

https://gitlab.com/EllenWasbo/inkscape-extension-removeduplicatenodes

grafik.png

Annotation belonging to the lines

This extension might turn straight lines into strange looking "d" content like the following

#using the extension will make
m 47.127583,101.78891 h 9.944022 z
 
#to
M 47.1276 101.789 C 47.1276 101.789 57.0716 101.789 57.0716 101.789 C 57.0716 101.789 47.1276 101.789 47.1276 101.789 Z
 
#selecting the line and moving it up/down/left/right will turn it into
m 47.1276,101.789 c 0,0 9.944,0 9.944,0 0,0 -9.944,0 -9.944,0 z

 

Purge Duplicate Path Segments

A common problem while laser cutting or vinyl cutting for example, is the problem with duplicating lines which are overlapping invisibly. Often you won't find them in your drawing. If you use graphics without filtered duplications you might run into issues like burnt edges, rough-cut edges, long running cutting processes, etc.

This plugin removes duplicates from paths with respect to their type (bezier or straight line segments). Please note that maybe you need to combine all lines/paths to one common path to make this work. So this plugin is ideal to remove common edges like professional nesting software is doing too.

Key phrases: remove overlapping lines, remove duplicated lines, purge redundant lines, purge doubled lines, remove common edges, remove occulted lines, hidden line removal, retrace edges, chain paths, clean paths

Annotation belonging to the lines

This extension also helps removing straight line duplications where start or end point is duplicated by using "z" or "Z" in "d" descriptor, which invokes a closing contour, like the following

#turns
m 47.127583,101.78891 h 9.944022 z
 
#into
M 47.1276 101.789 L 57.0716 101.789

Example on how to remove duplicates

Draw a line and copy/paste it

grafik.png

grafik.png

for each line a path 'd' is defined:

grafik.png

Make the paths overlapping  visually (to enforce having some example of duplicated, invisible path)

grafik.png

grafik.png

Combine the lines (Ctrl + K)

grafik.png

The path is now duplicated. See entry 'd' - this is repeated

Run the extension

Now check the XML element tree to see the cleaned up path

grafik.png

Real example and known limitation(s)

Get some parts you want to optimize by rearranging and removing common edges

grafik.png

Check the node count

Calculate the total number of nodes by clicking through XML tree and noting down the nodes count. We use this information to check how good we can reduce the duplicates in the drawing.

grafik.png

grafik.png

For this example we have 13 paths witha total of 38 * 5 + 21 *8 = 358 nodes

Check the total line length

We can also get a goodcomparison by measuring the total length of all paths before and after purging duplicate lines.

grafik.png

Rearrange and combine all paths

CTRL + K to combine the things. You might need to ungroup all items before.

grafik.png

Run the extension and get the result

grafik.png

Check the line length again

grafik.png

Known Limitation: We reduced the set by 8 nodes (only). The limitation can be found in detail: Duplicated paths are only removed if start and end point of the line segment are equal. It will not work if one line segment is shorter or longer because the X1Y1 or X2Y2 coordinate will be different. A more complicated algorithm is required to get optimal results. The following screenshots just shows one line segments moved to reveal the remaining underlying common edge. To avoid this problem we would need to intersect all lines with each other to receive the whole set of intersecting points. Then we proceed to remove duplicate segments.

grafik.png grafik.png

Check the total line length again

We reduced the line length from 2893.74 mm to 2882.45 mm. Not a great saving for this example, but still a reduction.

grafik.png

Purge Pointy Paths

This filter deletes paths which render as point only, like:

  • m 45.250809,91.692739 - this path contains onyl one command - a single point
  • m 45.250809,91.692739 z - this path contains two commands, but only one coordinate. It's a single point, the path is closed by a Z command

  • m 45.250809,91.692739 l 45.250809,91.692739 - this path contains two commands, but the first and second coordinate are the same. It will render als point

  • m 45.250809,91.692739 l 45.250809,91.692739 z - this path contains three commands, but the first and second coordinate are the same. It will render als point, the path is closed by a Z command

Remove Duplicate Line Segments

An Inkscape extension to remove duplicate line segments with an option to add a tolerance for regarding the segments as a match. See http://cutlings.wasbo.net/inkscape-extension-removeduplicatelines

grafik.png

See also

Split And Break Bezier At t

Allows better control over splitting than Add Nodes or Split Bezier (Subdivide Path).

Draw some path

grafik.png

Run the extension

grafik.png

Splitted path

grafik.png

Split Bezier (Subdivide Path)

Function is like Modify Path → Add Nodes but it provides additional features like

Please note that the plugin will sub-divide each path segment (from path handle to path handle). So it does not split the whole curve into given amount of piece like acting "as one item". Each bezier segment is it's own element.

Draw some example

grafik.png

Run the extension

grafik.png

Note that "Live preview" will only work if "Break apart" is not selected

grafik.png

Tip: Breaking apart the curve can also be done by ...

Selecting the path and show handles

grafik.png

Select all handles and break

grafik.png grafik.png

Break apart the path

SHIFT + CTRL + K

grafik.png

Tip: Splitted paths can be combined again nearly the same look like before by ...

Example for bezier path

Draw some curve and split it up running the extension

grafik.pnggrafik.png

Duplicate the path

CTRL + D to duplicate. We use this to check the quality of simplification

Run Path → Simplify

As you can see the result has other handles than before. The right image shows a black curve (curve before simplification), the green shows the simplified curve. You can see that the curve is not exactly the same. So we can say that simplification for bezier curves is not the best in all use cases, but it will work absolutely fine for straight line segments:

grafik.png

As you can see the result has other handles than before. The right image shows a black curve (curve before simplification), the green shows the simplified curve. You can see that the curve is not exactly the same. So we can say that simplification for bezier curves is not the best in all use cases, but it will work absolutely fine for straight line segments:grafik.png

Example for path with straight line segments only

Draw some curve and split it up running the extension

grafik.png

grafik.png

Run Path → Simplify

grafik.png