Использование ориентиров в «Станли»
При использовании пакета "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) для второй диаграммы. Как я могу определить эти 2 смещения в среде tikz, чтобы они были локальными только для этого рисунка? Где мне можно разрешить вводить координаты точки следующим образом:
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}
Ответы
Если вы хотите Y1и Y2должны быть константами, вы можете использовать их \pgfmathdeclarefunctionдля объявления их как функций, которые не обрабатывают никаких аргументов и просто доставляют значение константы.
В приведенном ниже примере я использовал \pgfkeysдля определения макросов \DeclareConstantи \DeclareConstants.
\DeclareConstant{⟨name of constant⟩}{⟨value of constant⟩} используется для объявления единственной константы.
Несколько констант можно объявить через \DeclareConstants:
\DeclareConstantsобрабатывает список пар, разделенных запятыми :⟨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-functions. !!!!!
Поэтому , пожалуйста , не объявить константу sinили cosили тому подобное. ;-)
Раздел «97 Настройка математического механизма» pgfmanual.pdf , руководства для TikZ и 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}