在“Stanli”中使用参考点

在“Stanli”中使用参考点

使用“Stanli”包时,为了绘制多个相互重叠的段落,我设置了偏移值。对于显示的 MWE,每个图表的原点设置如下:

  • \point{a-LD}{0}{22.5};
  • \point{a-FBD}{0}{22.5-6};
  • \point{a-SFD}{0}{22.5-14};

如图所示,每个图的原点的 X 坐标相同。但是,为了将它们放在彼此下方,我沿 Y 坐标设置了一个偏移量。第一个图的偏移值为 (-6),第二个图的偏移值为 (-14)。我如何在 tikz 环境中定义这 2 个偏移量,使它们仅位于此图的位置,我可以在其中输入点坐标,如下所示:

Y1=-6

Y2=-14

  • \point{a-LD}{0}{22.5};
  • \point{a-FBD}{0}{22.5-Y1};
  • \point{a-SFD}{0}{22.5-Y2};

因为我只需要输入一次偏移量并更改一次,因为我需要多次输入它们,所以在更改时我只需要更改一次而不是多次。

\documentclass{article}
\usepackage{amsmath} 
\usepackage{stanli}

\begin{document}

\begin{center}
\begin{tikzpicture}

\draw[help lines,step=0.5](0,0) grid(15,24);


%%%%%%%%%%%%%%%%%%%%%%%%Loading%%%%%%%%%%%%%%%%

\point{a-LD}{0}{22.5};
\point{b-LD}{10}{22.5};
\point{su-LD}{2}{22.5+1.5};
\point{s-LD}{2}{22.5};
\point{sl-LD}{2}{22.5-0.5};
\point{TL-LD}{10}{22.5+2};
\point{CAP-LD}{10/2}{22.5-2.5};

% Elements

\beam{4}{a-LD}{b-LD};

%Supports

\support {1}{a-LD};
\support {2}{b-LD};


%Loads

\lineload{1}{a-LD}{b-LD}[0][2][0.035]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%First diagram%%%%%%%%%%%%%%%%%%

\point{a-FBD}{0}{22.5-6};
\point{b-FBD}{10}{22.5-6};
\point{TL-FBD}{2*10/3}{22.5-6};
\point{TLA-FBD}{2*10/3}{22.5-6+1.75};
\point{HR}{0-1.5}{22.5-6};
\point{VRA}{0}{22.5-6-1};
\point{VRB}{10}{22.5-6-1};
\point{CAP-FBD}{10/2}{22.5-6-3.5};

% Elements

\beam{4}{a-FBD}{b-FBD};




%%%%%%%%%%%%%%%%%Second diagram%%%%%%%%%%%%%%%%%%

\internalforces{a-FBD}{b-FBD}{-3}{6}[0][red]%[0]


\point{a-SFD}{0}{22.5-14};
\point{b-SFD}{10}{22.5-14};
\point{TL-SFD}{2*10/3}{22.5-14};
\point{TLA-SFD}{2*10/3}{22.5-14+1.75};
\point{VRA}{0}{22.5-14-1};
\point{VRB}{10}{22.5-14-1};
\point{CAP-SFD}{10/2}{22.5-14-3.5};

% Elements

\beam{4}{a-SFD}{b-SFD};

\internalforces{a-SFD}{b-SFD}{-3}{6}[3][red]%[0]


\end{tikzpicture}
\end{center}

\end{document}

在此处输入图片描述

答案1

如果您希望Y1将它们声明Y2为常量,则可以\pgfmathdeclarefunction将它们声明为不处理任何参数并仅传递常量值的函数。

在下面的例子中,我用于\pgfkeys定义宏\DeclareConstant\DeclareConstants

\DeclareConstant{⟨name of constant⟩}{⟨value of constant⟩}用于声明单个常量。

可以通过以下方式声明几个常量\DeclareConstants

\DeclareConstants处理以逗号分隔的 -pairs 列表:⟨name of constant⟩=⟨value of constant⟩

\DeclareConstants{
                   ⟨name of constant 1⟩=⟨value of constant 1⟩,
                   ⟨name of constant 2⟩=⟨value of constant 2⟩,
                                      ...
                   ⟨name of constant k⟩=⟨value of constant k⟩,
                 }

如果常量本身的值包含逗号(例如,作为另一个 pgfmath 函数的参数/操作数的分隔符),则该值可以/需要嵌套在花括号中:

⟨name of constant 2⟩={⟨value of constant 2⟩},

foobar={mod(-100,30)},

(该常数的foobar值为 -10。后面的标记在分配值的过程中=被传递,而计算结果的标记构成了常数的值。这样,每当使用相关常数时,就不会重复计算。)\pgfmathparse\pgfmathparse

!!!!! 请注意,使用\DeclareConstant\DeclareConstants您可以轻松覆盖已经存在的 pgfmath 函数。!!!!!

因此请不要声明常量sincos类似的东西。;-)

章节“97 自定义数学引擎”手册.pdfTikZ 和 pgf 的手册中关于函数名称的说明:

函数名称可以由大写或小写字母、数字或下划线组成_。与许多编程语言一样, 函数名称不能以数字开头或包含任何空格

(手册中有一个位于短语“可以由……组成”后面的虚假逗号——我并没有为了准确引用而将其删除。)

因此,例如,您可以定义一个常量/函数Y1,但不能定义一个常量/函数1Y

\documentclass{article}
\usepackage{amsmath} 
\usepackage{stanli}

\newcommand\DeclareConstant[2]{%
  \pgfkeys{/MyStuff/declare constant={#1}{#2}}%
}%
\newcommand\DeclareConstants[1]{\pgfkeys{/MyStuff/.cd,#1,}}%
\newcommand\exchangeargs[2]{#2#1}%
\makeatletter
\pgfkeys{%
  /MyStuff/.unknown/.code=\pgfkeys{/MyStuff/declare constant={\pgfkeyscurrentname}{#1}},
  /MyStuff/declare constant/.code 2 args=%
  \begingroup
  \pgfmathparse{#2}%
  \ifcat$\detokenize{#1}$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
  {%
    \GenericError{\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces}%
                 {Constant declaration error: Name of constant not specified}%
                 {\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces You cannot declare a constant without\MessageBreak specifying its name.}%
                 {You need some sort of identifier for referencing the constant.}%
    \ifcat$\detokenize\expandafter{\pgfmathresult}$\expandafter\@firstofone\else\expandafter\@gobble\fi
    {%
      \GenericError{\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces}%
                   {Constant declaration error: Value of constant not specified}%
                   {\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces You cannot declare a constant without\MessageBreak specifying its value.}%
                   {Which aspect of a constant could be constant if not its value?\MessageBreak So there must be a value!}%
    }%
    \endgroup
  }{%
    \ifcat$\detokenize\expandafter{\pgfmathresult}$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
    {%
      \GenericError{\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces}%
                   {Constant declaration error: Value of constant not specified}%
                   {\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces You cannot declare a constant without\MessageBreak specifying its value.}%
                   {Which aspect of a constant could be constant if not its value?\MessageBreak So there must be a value!}%
      \endgroup
    }{%
      \expandafter\endgroup
      \expandafter\exchangeargs\expandafter{\expandafter{%
        \expandafter\def
        \expandafter\pgfmathresult
        \expandafter{\pgfmathresult}%
      }}{\pgfmathdeclarefunction*{#1}{0}}%
    }%
  },%
  /MyStuff/declare constant/.value required,%
}%
\makeatother


\begin{document}

\begin{center}
\begin{tikzpicture}

% \DeclareConstant{Y1}{-3-3};
% \DeclareConstant{Y2}{-14};
\DeclareConstants{
  Y1=-3-1-2,              % yields Y1=-6
  Y2={mod(-114,-100)},    % yields Y2=-14
  % Y3=...,
  % Y4=...,
  % foobar=...,
  % ...
};

\draw[help lines,step=0.5](0,0) grid(15,24);


%%%%%%%%%%%%%%%%%%%%%%%%Loading%%%%%%%%%%%%%%%%

\point{a-LD}{0}{22.5};
\point{b-LD}{10}{22.5};
\point{su-LD}{2}{22.5+1.5};
\point{s-LD}{2}{22.5};
\point{sl-LD}{2}{22.5-0.5};
\point{TL-LD}{10}{22.5+2};
\point{CAP-LD}{10/2}{22.5-2.5};

% Elements

\beam{4}{a-LD}{b-LD};

%Supports

\support {1}{a-LD};
\support {2}{b-LD};


%Loads

\lineload{1}{a-LD}{b-LD}[0][2][0.035]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%First diagram%%%%%%%%%%%%%%%%%%

\point{a-FBD}{0}{22.5+Y1};
\point{b-FBD}{10}{22.5+Y1};
\point{TL-FBD}{2*10/3}{22.5+Y1};
\point{TLA-FBD}{2*10/3}{22.5+Y1+1.75};
\point{HR}{0-1.5}{22.5+Y1};
\point{VRA}{0}{22.5+Y1-1};
\point{VRB}{10}{22.5+Y1-1};
\point{CAP-FBD}{10/2}{22.5+Y1-3.5};

% Elements

\beam{4}{a-FBD}{b-FBD};




%%%%%%%%%%%%%%%%%Second diagram%%%%%%%%%%%%%%%%%%

\internalforces{a-FBD}{b-FBD}{-3}{6}[0][red]%[0]


\point{a-SFD}{0}{22.5+Y2};
\point{b-SFD}{10}{22.5+Y2};
\point{TL-SFD}{2*10/3}{22.5+Y2};
\point{TLA-SFD}{2*10/3}{22.5+Y2+1.75};
\point{VRA}{0}{22.5+Y2-1};
\point{VRB}{10}{22.5+Y2-1};
\point{CAP-SFD}{10/2}{22.5+Y2-3.5};

% Elements

\beam{4}{a-SFD}{b-SFD};

\internalforces{a-SFD}{b-SFD}{-3}{6}[3][red]%[0]


\end{tikzpicture}
\end{center}

\end{document}

在此处输入图片描述

相关内容