我想沿着红点的方向绘制线圈线,但它们不应超出圆。是否可以将箭头的长度缩短为圆的半径?
我的代码:
\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}
答案1
一种方法是使用intersections
Ti钾kZ 库并从圆心到从中心到圆外选定节点的路径交点绘制弹簧:
\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}