如何旋转带有矩形的锚点以获得更好的连接

如何旋转带有矩形的锚点以获得更好的连接

矩形在旋转时不会旋转锚点。在我的代码示例中,

\documentclass[border=2mm]{standalone}
\usepackage    {tikz}
\usepackage    {siunitx} % SI units, \SI and \ang commands    
\usetikzlibrary{babel}   % There are issues with some babel packages
\usetikzlibrary{calc}    % Computing some coordinates 
%
\usetikzlibrary{fadings,decorations.pathreplacing, arrows}
\usetikzlibrary{decorations.markings}
\tikzset{fieldout/.pic={
  \fill circle(0.1);
  \draw [thick] circle(0.25);
  }
}

%----

% To make \rectangle to behave as a \node 
\usetikzlibrary{fit}
\makeatletter
\tikzset{
  fitting node/.style={
    inner sep=0pt,
    fill=none,
    draw=none,
    reset transform,
    fit={(\pgf@pathminx,\pgf@pathminy) (\pgf@pathmaxx,\pgf@pathmaxy)}
  },
  reset transform/.code={\pgftransformreset}
}
\makeatother
%---

\begin{document}
\begin{tikzpicture}[scale=1, 
    every node/.style={font=\Large,  } 
    ]
% some dimensions
\def\hhub{4} % height of I2C hub
\def\whub{2} % width of I2C hub
\def\nconn{4} % num connections in hub
\def\wbeagle{5.5} % width Beagle
\def\hbeagle{9} % height Beagle
\def\lpin{0.14} % side of GPIO square pin
\def\hacc{2} % height of accelerometer detail
\def\wacc{4} % width of  accelerometer detail

% % THE 3 CIRCLE SECTIONS
\begin{scope}[x={(1.5cm,0cm)},y={(0cm,1.5cm)},shift={(0,0)},  thick]
    \foreach[count=\xk] \k in {6.5, 0, -6.5}
    {%
       \draw[dashed, thin,-latex] (-3,\k) -- (4,\k);
       \begin{scope}[shift={(0,\k)}]
           \draw[] (0,0) circle (3);
           \foreach[count=\xi, evaluate={\kk={ifthenelse(\k>-1, \i, \i+60)}}, ]\i in {60,180,300}
           {%
           \begin{scope}[rotate=\kk]
               \draw[gray,dotted] (0,0) -- (3,0);
               \draw[red, opacity=0.85, fill=white,fill opacity=1,] (1.3,-0.27) rectangle (2.3,0.27) node [fitting node] (acc\xk\xi) {};
               \draw[black,semithick] (1.4,-0.23) rectangle (1.6,0.23) ;
               \draw[black,, yshift=1.1cm] (1.4,-0.24) rectangle (1.6,0.24) node[fitting node,] (I\xk\xi) {};
               \foreach[evaluate={\jj={0.46*\j/(\nconn+1) }}] \j in {1, 2,3, 4}
               {
                  \draw[black,fill=black, ] (1.5, -0.23+\jj) circle (0.01); 
                  \draw[black, yshift=1.1cm, semithick] (1.5, -0.23+\jj) circle (0.03); 
               }
              \draw[thin,blue!50, fill=blue!50] (1.8,-0.1) rectangle (2,-0.22)  node[fitting node] (G\xk\xi) {};
           \end{scope}         
           }%
      \end{scope}
   }%
   \draw[black,<->,shift={(0,0)},semithick] (-180:0.5) arc (-180:-60:0.5) node [midway,below, xshift=-0.4cm] {\ang{120}}; % ARC 120º
\end{scope}

% The 4 x I2C HUBs
\foreach[count=\cx,  ] \tx/\ty in {1/-6.8,1/0, 1/6.8, 1.75/0}
{%
  \begin{scope}[x={(1cm,0cm)},y={(0cm,1cm)},shift={(-10*\tx,\ty)},  thick]
    \draw[black] (-\whub/2,-\hhub/2) rectangle (\whub/2,\hhub/2);
    % \draw[black] (-1cm,-2cm) rectangle (1cm,2cm);
    \foreach[count=\xi, evaluate={\kk={\hhub*\i/(\nconn+1) }}, evaluate={\sx={ifthenelse(\i<2,0cm, 2cm ) }},
                                                              evaluate={\sy={ifthenelse(\i<2,-1.25cm, 0cm ) }}] \i in {1,2,3,4} 
    {%
      % into I2C hub with connections
      \draw[black] (-0.75,-\hhub/2+\kk-0.3) rectangle (0.75,-\hhub/2+\kk+0.3) ; 
      \foreach[evaluate={\j={1.5*\i/(\nconn+1) }}] \i in {1,2,3,4} % (1.5 = 0.75-(-0.75)) %los punticos
      {%
         \draw[black,fill=black,  ] (-0.75+\j,-\hhub/2+\kk) circle (0.05); 
      }%
      % out I2C hub with connections
      \begin{scope}[xshift=\sx , yshift=\sy]
          \draw[black,] (-0.75,-\hhub/2+\kk-0.225) rectangle (0.75,-\hhub/2+\kk+0.225) node[fitting node] (II\cx\xi) {};
          \foreach[evaluate={\j={1.5*\i/(\nconn+1) }}] \i in {1,2,3,4} % (1.5 = 0.75-(-0.75)) %los agujericos
          {%
             \draw[black,semithick,  ] (-0.75+\j,-\hhub/2+\kk) circle (0.075);
           }%
      \end{scope}
    }%
  \end{scope}
}%
% Dimensions of the I2C Hub and text
\begin{scope}[xshift=-17.5cm]
    \draw[black,dashed,] (-\whub/2-0.75, -\hhub/2) --++ (0.75,0); 
    \draw[black,dashed,] (-\whub/2-0.75, \hhub/2) --++ (0.75,0); 
    \draw[black,<->,] (-\whub/2-0.5, -\hhub/2) --++ (0, \hhub) node [midway,above,rotate=90] {\SI{4}{cm}}; % vertical dim line
    \draw[black,dashed,] (-\whub/2, \hhub/2) --++ (0,0.75);
    \draw[black,dashed,] (\whub/2, \hhub/2) --++ (0,0.75);
    \draw[black,<->,] (-\whub/2, \hhub/2+0.5) --++ (\whub,0) node [midway,above] {\SI{2}{cm}};
    \draw[black,latex-,] (-90:-\hhub/2-1.3) -- (0, 5.5) node (T) [above, align=left] {Grove I2C Hub\\ACC53133P};
    \draw[black,latex-,] (50:8) -- (T);
\end{scope}


%% -- CONNECTIONS --
\begin{scope}[black,very thick]
    % CONNECTIONS BETWEEN I2C HUBS, AND BEAGLE
    \draw[] (II42.south) --++(0,-9.9) -| (II11.south);
    \draw[] (II43.south) --++(0,-0.175) --++(2,0) --++(0,-3.5) -| (II21.south);
    \draw[] (II44.north) --++(0,2)  -| (II31.south);

    % CONNECTIONS BETWEEN I2C HUBS AND ACCELEROMETERS 
    % To the TOP Circle
    \draw[] (II34.north) |- (I12.west);
    \draw[] (II33.north) --++(0,0.15) --++(5.5,0) --++(30:2) -- (I11.south);
    \draw[] (II32.north) --++(0,0.15) --++(5.5,0) --++(30:4.7) -- (I13.north);

    % To the MIDDLE Circle
    % \draw[] (II24.north) --++(0,0.5) -++(5,0) to[out=0,in=-120] (I21.south);
    \draw[] (II24.north) --++(0,0.5) -++(7.8,0) -- (I21.south);
    \draw[] (II23.north) --++(0,0.15) --++(9,0) -- (I23.north);
    \draw[] (II22.south) |- (I22.west);

    % To the SOUTH Circle
    \draw[] (II14.north) --++(0,0.5) --++(6.75,0) --++(-60:4.37) |- (I33.west);
    \draw[] (II13.north) --++(0,0.15) --++(4.5,0) -- (I31.north);
    \draw[] (II12.south) --++(0,-0.5)  --++(4.5,0) --++ (-45:5) -- (I32.north);
\end{scope}

%% -- GPIO BLUE LINE CONNECTIONS

\begin{scope}[blue,very thick]
    % Upper Circle section
    \draw[] (G11) --++ (-60:6) node[right] {\sf{P8\_42}}; 
    \draw[] (G12) --++ (0,0.5) --++(4.7,0) --++(-60:5.5) node[right] {\sf{P8\_46}};
    \draw[] (G13.east) --++ (30:1.5) --++ (-60:4) node[right] {\sf{P8\_43}};
    % Middle Circle section
    \draw[] (G21.east) --++ (-30:0.5) --++(-60:5) node[right] {\sf{P8\_43}};
    \draw[] (G22.north) --++ (0,0.25) --++(5.1,0) --++(-60:5) node[right] {\sf{P8\_35}};
    \draw[] (G23.east) --++ (30:1.6) --++(-60:4) node[right] {\sf{P8\_39}};
    % Bottom Circle Section
    \draw[] (G31.east) --++ (30:0.5) --++ (-60:10.7) node[right] {\sf{P8\_34}};
    \draw[] (G32.east) --++ (-30:2) --++ (2,0) --++(-60:5) node[right] {\sf{P8\_31}};
    \draw[] (G33.south) --++ (0,-1.5) --++(-60:3.8) node[right] {\sf{P8\_30}};
\end{scope}

\end{tikzpicture}
\end{document}

在此处输入图片描述

将 I2C 集线器与矩形连接成圆形部分的线在旋转时不会与这些矩形底部的中间连接。我在先前的帖子中使用了解决方案如何在(tikz)矩形路径上建立节点锚点......

在矩形中设置锚点,因为它们是节点。

连接不合适的问题也出现在P8_XX右侧带有标签的“蓝色”线中。

答案1

我看不出这fitting node为你做了什么。你设置了复杂的\foreach循环来绘制具有索引名称的节点,然后手动绘制线条。我认为这不值得。在这里我说明了如何使用它来\pic在图表中绘制重复元素。-显然你会想要使用你自己的正确极坐标。

\documentclass[tikz, border=2mm]{standalone}
\begin{document}
\tikzset{
    myHub/.pic = {
    \draw[fill=white] (-1.25,-0.4) rectangle (1.25,0.4);
    \draw (-0.75,0) circle[radius=0.1] (-0.25,0) circle[radius=0.1] (0.25,0) circle[radius=0.1] (0.75,0) circle[radius=0.1];
    }}
\begin{tikzpicture}[ultra thick]
\draw (0,0) circle[radius=10];
\draw (-20,-5) pic[scale=1.5]{myHub} |- (-4,-3) pic[rotate=90]{myHub};
\draw (-20,-7) pic[scale=1.5]{myHub} |- (-5,-6) -- (-1,-3) -- (0,5) pic[rotate=-30]{myHub};
\draw (-20,-9) pic[scale=1.5]{myHub}  |- (-5,-8) -- (3,-2) -- (5,-3) pic[rotate=30]{myHub};
\end{tikzpicture}
\end{document}

原图部分

相关内容