Tikz 中支撑尖端/夹点处的节点

Tikz 中支撑尖端/夹点处的节点

我尝试在图形中添加一些解释性括号,但发现遇到了一些小困难/不便。

[编辑]:在得知问题的主要内容(关于牙套偏心尖端)已在如何在 TikZ 中绘制不平衡的花括号?,我删除了那部分。[\编辑]

我想知道是否有内置方法可以根据所有给定的参数确定支架尖端的位置并自动在那里放置一个节点。现在我必须计算横跨支架的正交向量,这很繁琐,尤其是对于许多支架而言。我尝试测试了一些选项https://tex.stackexchange.com/a/95144/42225(手册中没有列出PGF),但无济于事。

underext此外,我认为将(我的实现)作为键会更清楚decoration={...};有没有办法设置它,例如decoration/underext/.style={pre=moveto,pre length=#1,post=moveto,post length=#1}

梅威瑟:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}[scale=1.5,%
    underext/.style={decoration={pre=moveto,pre length=#1,post=moveto,post length=#1}}]
\pgfmathsetmacro\ang{asin(1/6)}
\clip (-\ang:6) arc (-\ang:90+\ang:6) -- (-1,-1) -- cycle;

\foreach \r / \i [evaluate=\r as \ang using 90/\r] in {8/4} % radius and number of slice
{
\begin{scope}[rotate={(\i-1)*\ang}]
    \foreach \m in {2}
    {
    % Minkowski sum
    \filldraw [fill=black!5,draw=black] ($(-\ang:\r/2)+(-\ang-90:\m)$) arc (-\ang-90:-\ang-180:\m)
    arc (-\ang:\ang:\r/2-\m) arc (\ang+180:\ang+90:\m)
    -- ($(\ang:2*\r)+(\ang+90:\m)$) arc (\ang+90:\ang:\m)
    arc (\ang:-\ang:2*\r+\m) arc (-\ang:-\ang-90:\m) -- cycle;

    % support
    \filldraw[draw=black,fill=black!20] (-\ang:\r/2) arc (-\ang:\ang:\r/2) -- (\ang:2*\r) arc (\ang:-\ang:2*\r) -- cycle;

    % axis of cone
    \draw[very thin] (0,0) coordinate (A) -- (0:\r/2) coordinate (B);
    \draw[decorate,decoration={brace,mirror,amplitude=10pt,raise=3pt,aspect=0.6},underext=1.5pt,very thin] (A)--(B);
    \coordinate (base) at ($(A)!0.6!(B)$);
    \coordinate (ortho) at ($(0,0)!1!90:($(B)-(A)$)$);
    \node[inner sep=2pt] at ($(base)!-15pt!($(base)+(ortho)$)$) {$2^{j-1}$};
    };
\end{scope}
\begin{scope}[very thin,<->]
    \draw (-1,0) -- (6,0);
    \draw (0,-1) -- (0,6);
\end{scope}
};
\end{tikzpicture}
\end{document}

在此处输入图片描述

而我想要的是类似这样的内容:

\draw[very thin] (0,0) node[shape=coordinate](A){} -- (0:\r/2) node[shape=coordinate](B){};
\draw[decorate,decoration={brace,mirror,amplitude=10pt,raise=3pt,aspect=0.6,underext=1.5pt,
    node at tip=node name},very thin] (A)--(B);
\node[below=2pt] at (node name) {$2^{j-1}$};

答案1

underext此外,我认为将(我的实现)作为键会更清楚decoration={...};有没有办法设置它,例如decoration/underext/.style={pre=moveto,pre length=#1,post=moveto,post length=#1}

几乎,因为整个decoration过程都是由 PGF 完成的,所以键实际上位于/pgf命名空间中。因此,您需要执行以下任一操作

\pgfset{decoration/underext/.style={…}}

或者

\tikzset{/pgf/decoration/underext/.style={…}}

这个答案提供了两个新auto功能:

  • left with offset
  • right with offset

它们的工作原理与left和类似,right但它们将节点(或坐标)正交地推向长度约为 的一侧/tikz/auto offset
请记住,这些与八个罗盘锚点对齐。

该值键用振幅值和升高值进行初始化。

进行了很多类似的计算,但这是我区分倾斜节点和非倾斜节点的唯一方法。变换到处都是,非常令人困惑!

如果你查看draw节点,你会看到它们仅接触尖端:
在此处输入图片描述


every brace node风格设置了适当的auto功能和正确的pos设置。

举个sloped例子,我在旋转之外使用了相同的路径,scope因为否则会很奇怪

代码

\documentclass[tikz]{standalone}
\usetikzlibrary{calc, decorations.pathreplacing}
\pgfset{decoration/raise/.append code=% Ugh!
  \pgfkeyssetevalue{/pgf/decoration/raise}{#1}}%
\pgfkeyssetvalue{/pgf/decoration/raise}{0pt}
\makeatletter
\tikzset{% https://tex.stackexchange.com/a/665784/16595
  swap/.style={swap auto/.expand once=\tikz@auto@anchor@direction},
  swap auto/.is choice,
  /utils/temp/.style args={#1=#2}{
    /utils/exec=\pgfutil@namedef{tikz@install@auto@anchor@#1}{%
                \let\tikz@do@auto@anchor\tikz@auto@anchor@on
                \def\tikz@auto@anchor@direction{#1}},
    swap auto/#1/.code=\def\tikz@auto@anchor@direction{#2}},
  /utils/temp/.list={left=right, right=left,
    left with offset=right with offset, right with offset=left with offset},
  % which side → mirror/reverse path → auto
  % where      → reverse path/aspect → pos
  every brace node/.style={
    auto=% Ugh?
      \ifx\tikz@dec@mirror\relax
        \ifpgf@decorate@inputsegmentobjects@reverse right\else left\fi
      \else
        \ifpgf@decorate@inputsegmentobjects@reverse left\else right\fi
      \fi\space with offset,
    pos=\ifpgf@decorate@inputsegmentobjects@reverse
          1-\fi(\pgfdecorationsegmentaspect)},
  auto offset/.initial=% doesn't need to be used with decoration,
                       % can just be a fixed distance
    \pgfdecorationsegmentamplitude+(\pgfkeysvalueof{/pgf/decoration/raise})}
\pgfutil@namedef{tikz@auto@anchor@left with offset}{%
  \tikz@auto@pre\tikz@auto@anchor
  \xdef\tikz@marshal{%
      \pgf@process{%
        \noexpand\pgftransformreset
        \noexpand\pgftransformrotate{+90}%
        \noexpand\pgfpointtransformed{%
          \noexpand\pgfpointscale{\noexpand\pgfkeysvalueof{/tikz/auto offset}}
                                 {\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}}%
      \advance\pgf@pt@x\pgf@x
      \advance\pgf@pt@y\pgf@y}%
  \tikz@auto@post
  \ifpgfslopedattime
    \pgf@xb=\pgf@x
    \pgf@yb=\pgf@y
    \pgf@process{%
      \pgftransformreset
      \pgftransformrotate{90}%
      \pgfpointtransformed{%
        \pgf@process{%
          \tikz@timer%
          \pgf@x=\pgf@pt@aa pt
          \pgf@y=\pgf@pt@ab pt
          \pgfpointnormalised{}%
          \pgfpointscale{\pgfkeysvalueof{/tikz/auto offset}}{}}}}%
    \advance\pgf@pt@x\pgf@x
    \advance\pgf@pt@y\pgf@y
    \pgf@x=\pgf@xb
    \pgf@y=\pgf@yb
  \else
    \tikz@marshal
  \fi}
\pgfutil@namedef{tikz@auto@anchor@right with offset}{%
  \tikz@auto@pre\tikz@auto@anchor@prime
  \xdef\tikz@marshal{%
    \pgf@process{%
      \noexpand\pgftransformreset
      \noexpand\pgftransformrotate{-90}%
      \noexpand\pgfpointtransformed{%
        \noexpand\pgfpointscale{\noexpand\pgfkeysvalueof{/tikz/auto offset}}
                               {\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}}%
    \advance\pgf@pt@x\pgf@x
    \advance\pgf@pt@y\pgf@y}%
  \tikz@auto@post
  \ifpgfslopedattime
    \pgf@xb=\pgf@x
    \pgf@yb=\pgf@y
    \pgf@process{%
      \pgftransformreset
      \pgftransformrotate{-90}%
      \pgfpointtransformed{%
        \pgf@process{%
          \tikz@timer%
          \pgf@x=\pgf@pt@aa pt
          \pgf@y=\pgf@pt@ab pt
          \pgfpointnormalised{}%
          \pgfpointscale{\pgfkeysvalueof{/tikz/auto offset}}{}}}}%
    \advance\pgf@pt@x\pgf@x
    \advance\pgf@pt@y\pgf@y
    \pgf@x=\pgf@xb
    \pgf@y=\pgf@yb
  \else
    \tikz@marshal
  \fi}
\makeatother
\begin{document}
\begin{tikzpicture}[
  scale=1.5,
  /pgf/decoration/underext/.style={
    pre=moveto, pre length={#1}, post=moveto, post length={#1}}]
\pgfmathsetmacro\ang{asin(1/6)}
\clip (-\ang:6) arc [start angle=-\ang, end angle=90+\ang, radius=6] -- (-1,-1) -- cycle;

\foreach \r / \i [evaluate=\r as \ang using 90/\r] in {8/4}{ % radius and number of slice
  \begin{scope}[rotate={(\i-1)*\ang}]
  \foreach \m in {2}{
    % Minkowski sum
    \filldraw [fill=black!5, draw=black, delta angle=-90, radius=\m]
      ($(-\ang:\r/2)+(-\ang-90:\m)$)
      arc [start angle=-\ang-90]
      arc [start angle=-\ang, end angle=\ang, radius=\r/2-\m]
      arc [start angle=\ang+180]
      -- ($(\ang:2*\r)+(\ang+90:\m)$)
      arc [start angle=\ang+90]
      arc [start angle=\ang, end angle=-\ang, radius=2*\r+\m]
      arc [start angle=-\ang] -- cycle;

    % support
    \filldraw[draw=black,fill=black!20]
      (-\ang:\r/2)
      arc [start angle=-\ang, end angle=\ang, radius=\r/2] coordinate[midway] (B)
      -- (\ang:2*\r)
      arc [start angle=\ang, end angle=-\ang, radius=2*\r] -- cycle;

    % axis of cone
    \draw[very thin] (0,0) coordinate (A) -- (B);
    \draw[
      decorate,
      decoration={
        brace, mirror,
        amplitude=10pt, raise=3pt, aspect=0.6
      },
      very thin] (A)-- node[every brace node]{$2^{j-1}$} (B);
    \coordinate (base) at ($(A)!0.6!(B)$);
    \coordinate (ortho) at ($(0,0)!1!90:($(B)-(A)$)$);
    \node[inner sep=2pt,gray] at ($(base)!-15pt!($(base)+(ortho)$)$) {$2^{j-1}$};
  }
  \end{scope}
  \draw[decorate, decoration={brace, reverse path, mirror,
    amplitude=10pt, raise=3pt, aspect=0.6}, very thin]
    (A)-- node[every brace node,sloped]{$2^{j-1}$} (B);
}
\path[very thin, <->] (-1,0) edge (6,0) (0,-1) edge (0,6);
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容