6
\documentclass[tikz,border=2pt]{standalone}
\begin{document}
\begin{tikzpicture}
   \node at (0,0) (O) {} ;
   \foreach \a in {0,10,...,360}
     {
     \draw (\a:0.25) to (O);
     }
\end{tikzpicture}

\end{document}

The example code above draws the following picture

lines

and you can see that the lines do not join the boundary of the node with a nice bevel. The effect is ragged.

I believe it would be possible, using a filled node and drawing lines to O.center on a background layer, to produce a smooth picture. But my question is can the lines be "joined" to the node in a smooth way?

Edited to clarify what is meant by "smooth"

This is a line joining a shape where the join is not smooth.

not smooth

This is a line joining a shape where the join is smooth.

smooth

Perhaps it's a case of joining two separate paths. I seem to recall that Adobe Illustrator has that capability.

pheon
  • 786

3 Answers3

15

You can clip it with a shape and a circle.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope}[] % clip is only valid inside this scope
\clip (-0.5,-0.5) rectangle (0.5,0.5) (0,0) circle(2);
\foreach\a in{0,10,...,350}{\draw[ultra thick] (0,0)--+(\a:1);}
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807
  • I tried \clip (O.south west) rectangle (O.north east) (0,0) circle(2); to exactly match the boundaries of the node, but it didn't quite work as expected. – pheon Apr 15 '18 at 21:57
  • @pheon For a node, you need to zero out the outer sep if you want a tight connection. And take the line width into account. – percusse Apr 16 '18 at 08:30
4

Very similar to percusse's answer except that I do not draw the rectangle explicitly, i.e. if the node size changes, one does not have to adjust the dimensions of the rectangle.

\documentclass[tikz,border=2pt]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
   \node[red,draw=white, line width=1mm] at (0,0) (O) {} ;
   \begin{scope}[on background layer]
   \foreach \a in {0,10,...,360}
     {
     \draw (O.{\a}) to (\a:0.25) ;
     }
   \end{scope}   
\end{tikzpicture}
\end{document}

enter image description here

2

If you use a circular node, you get some sort of a nicer output

\documentclass[tikz,border=2pt]{standalone}
\begin{document}
\begin{tikzpicture}
   \node[circle] at (0,0) (O) {} ;
   \foreach \a in {0,10,...,360}
     {
     \draw (\a:0.25) to (O);
     }
\end{tikzpicture}
\end{document}

enter image description here

EDIT: The thing is that you are exactly attaching the lines to the node box, see below the with the red lines connecting to the black box.

\documentclass[tikz,border=2pt]{standalone}
\begin{document}
\begin{tikzpicture}
   \node[draw=black,outer sep=0pt] at (0,0) (O) {} ;
   \foreach \a in {0,10,...,360}
     {
     \draw[red] (\a:0.25) -- (O);
     }
\end{tikzpicture}
\end{document}

enter image description here

BambOo
  • 8,801
  • 2
  • 20
  • 47
  • Sure. This smooths the node to match the direction of the lines. But my question was meant to be about smoothly attaching a line to a generically shaped node. Or indeed, another line, not in the same path. – pheon Apr 15 '18 at 13:47
  • To be sure, what exactly do you mean by smooth attach ? I edited my answer to show you that you lines exactly connect to the node box. Do you mean you'd like to have the lines connecting perpendicularly to the box ? Please clarify – BambOo Apr 15 '18 at 13:58