4

I want to draw the coil line in direction of the red points, but they shouldn't surpass the circle. Is it possible to just shorten the length of the arrow to the radius of the circle?

Example

My Code:

    \begin{tikzpicture}[]
    %Left
    \node (m_1) at (-3.5,1) [middle] {};
    \node (c_1) at (-3.5,1) [circle,draw=black, style=dashed, inner sep=0pt,minimum size=4cm] {};
    
    \node (sim1_1) at (-1,2) [sim] {};
    \node (sim2_1) at (-4,4) [sim] {};
    \node (sim3_1) at (-6,-0.5) [sim] {};
    \node (sim4_1) at (-1.5,-1) [sim] {};
    \node (dissim1_1) at (-4,-0.5) [dissim] {};
    \node (dissim2_1) at (-3,-1.5) [dissim] {};
    \node (dissim3_1) at (-4.5,2) [dissim] {};
    \node (dissim4_1) at (-3,2) [dissim] {};
    \node (dissim5_1) at (-1,0.5) [dissim] {};
    
    
    \node (m_2) at (3.5,1) [middle] {};
    \node (c_2) at (3.5,1) [circle,draw=black, style=dashed, inner sep=0pt,minimum size=4cm] {};
    
    \node (sim1_2) at (6,2) [sim] {};
    \node (sim2_2) at (3,4) [sim] {};
    \node (sim3_2) at (1,-0.5) [sim] {};
    \node (sim4_2) at (5.5,-1) [sim] {};
    \node (dissim1_2) at (7-4,-0.5) [dissim] {};
    \node (dissim2_2) at (7-3,-1.5) [dissim] {};
    \node (dissim3_2) at (7-4.5,2) [dissim] {};
    \node (dissim4_2) at (7-3,2) [dissim] {};
    \node (dissim5_2) at (7-1,0.5) [dissim] {};
    
    
    \draw[spring1] (m_1) -- (sim1_1);
    \draw[spring1] (m_1) -- (sim2_1);
    \draw[spring1] (m_1) -- (sim3_1);
    \draw[spring1] (m_1) -- (sim4_1);
    
    \draw[spring2] (m_2) -- (dissim1_2);
    \draw[spring2] (m_2) -- (dissim2_2);
    \draw[spring2] (m_2) -- (dissim3_2);
    \draw[spring2] (m_2) -- (dissim4_2);
    \draw[spring2] (m_2) -- (dissim5_2);
 
    \end{tikzpicture} 
2
  • 1
    Can you make the code compilable? Feb 22, 2021 at 1:56
  • Welcome to TeX.SE! Extend your code fragment to small but complete document. We need information about your document preamble.
    – Zarko
    Feb 22, 2021 at 3:10

1 Answer 1

6

One way is to use of the intersections TikkZ library and draw springs from circle center to intersections of paths from cener to selected nodes out of circle:

\documentclass[border=3mm]{standalone}%
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                decorations.pathmorphing,
                intersections}

 \begin{document}
    \begin{tikzpicture}[
            > = {Straight Barb[scale=0.8]},
   dot/.style = {circle, draw, fill=#1, inner sep=2pt,
                 node contents={}},
 dot/.default = green,
middle/.style = {dot=blue!50, inner sep=3pt, node contents={}},
   decoration = {coil, segment length=4pt, pre length=8pt, post length=8pt}
                        ]
%Left
\node (m) at (-3.5,1) [middle];
\node (c) at (-3.5,1) [circle, draw, dashed, inner sep=0pt, minimum size=4cm,
                         name path=C] {};

\node (sim1_1) at (-1,2)    [dot];
\node (sim2_1) at (-4,4)    [dot];
\node (sim3_1) at (-6,-0.5) [dot];
\node (sim4_1) at (-1.5,-1) [dot];
\node (dissim1_1) at (-4,-0.5)  [dot=red];
\node (dissim2_1) at (-4.5,2)   [dot=red];
\node (dissim3_1) at (-3,2)     [dot=red];
\node (dissim4_1) at (-3,-1.5)  [dot=red];
\node (dissim5_1) at (-1,0.5)   [dot=red];

    \foreach \i in {1,2,3} % nodes inside of circle
\draw[<->, decorate] (m) -- (dissim\i_1);

    \foreach \i [count=\j from 4] in {a,b} % nodes outside of circle
{
\path[name path=\i] (m) -- (dissim\j_1);
\draw[<->, decorate, name intersections={of=C and \i,by=s}] (m) -- (s);
}
    \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.