loopspace / spath3

TikZ/PGF package for manipulating soft paths, includes the knots and calligraphy TikZ libraries.
16 stars 2 forks source link

Transparent Background at knots #7

Closed madsriisager closed 3 years ago

madsriisager commented 4 years ago

Hello

This package have been a tremendous help with line crossings. But a problem I found was, when you want transparent backgrounds, unfortunately you can see the white (or another color) lines, where the crossings are. Of course I can always change the background color for the knots, so it matches the current background color.

But if you export the picture, and want to use it everywhere, you have to export a picture for each background color, which can be time consuming.

So if a possible solution to this problem exists, it would be nice.

Best Regards Mads

And again thank you for a great usepackage!

loopspace commented 4 years ago

Thanks for using the package!

The background colour has always been an irritant to me. It's necessary because of how the package works in removing the undercrossing: it draws it, but then erases it to the background colour by drawing over it. Shortening the curves would be very heavy on the calculation as bezier curves aren't parametrised by arc length (but if it's of any use, the celtic knots package does work by shortening the curves because of the consistent structure of celtic knots).

So a perfect solution doesn't currently exist, and probably won't ever unless someone else steps in and figures out all the calculations. But I can offer two hacks that might be adequate.

  1. Use transparency groups. I think this ought to work, but I've only experimented with them once (https://tex.stackexchange.com/a/403963/86) so if you get something that works please let me know.

  2. Use colour-to-alpha when converting to an image. You don't say whether you're using the exported images as PDFs or converting them to another format, but if you use an image format that supports transparency, such as PNG, then there's often an option to make a specific colour transparent. I use pdftoppm and pnmtopng on a Unix command line for conversion and pnmtopng has this option.

kpym commented 4 years ago

Another idea (or may be not ?), you can use the node as fading pattern like this :

\documentclass[tikz,border=7pt]{standalone}

\usetikzlibrary{knots}
\usetikzlibrary{fadings}

\begin{tikzfadingfrompicture}[name=fade knot]
    \draw[thick,knot=white, background color=black] (-1,-1) -- (1,1);
    \draw[thick,knot=white, background color=black] (-1,1) -- (1,-1);
\end{tikzfadingfrompicture}

\begin{document}
\begin{tikzpicture}[knot gap=7]
    \fill[yellow, scale=1.1] (-1,-1) rectangle (1,1);
    \draw[help lines] (-1,-1) grid (1,1);
    \fill[path fading=fade knot,red] (-1,-1) rectangle (1,1);
\end{tikzpicture}
\end{document}

loopspace commented 3 years ago

I've been working on a new way of doing knots which is to detect the intersection point and then split the path at that place. The split path can then be shortened on either side to create the gap, meaning that it is a genuine gap.

Examples can be found in the examples directory, particularly the new_prime_knots.tex and trefoil_moves_new.tex files.

loopspace commented 3 years ago

This new method is now in the current version on CTAN, and has been updated and improved since then. See the documentation and examples to see how it works.

madsriisager commented 3 years ago

Hello Again

Thank you for this! It works wonderfully. Before I had just "fixed" it by manually seeing there every intersection was, and then using dash at that specific point. So a pain in the ass basically!

Great work!