Sử dụng các điểm tham chiếu trong “Stanli”
Khi sử dụng gói "Stanli", inorder để vẽ một số paragram áp đảo nhau, tôi đặt giá trị bù đắp. Đối với MWE được hiển thị, Điểm gốc cho mỗi sơ đồ được đặt như sau:
- \ point {a-LD} {0} {22.5};
- \ point {a-FBD} {0} {22,5-6};
- \ point {a-SFD} {0} {22.5-14};
Như được minh họa, tọa độ X giống nhau đối với điểm gốc của mỗi sơ đồ. Tuy nhiên, để đặt chúng bên dưới nhau, tôi đặt một khoảng lệch dọc theo tọa độ Y. Các giá trị bù đắp là (-6) cho sơ đồ đầu tiên và (-14) cho sơ đồ thứ hai. Làm thế nào tôi có thể xác định 2 hiệu số đó trong môi trường tikz sao cho chúng chỉ giống với hình này Trong đó tôi có thể được phép nhập tọa độ điểm như sau:
Y1 = -6
Y2 = -14
- \ point {a-LD} {0} {22.5};
- \ point {a-FBD} {0} {22,5-Y1};
- \ point {a-SFD} {0} {22,5-Y2};
Vì tôi chỉ cần nhập bù đắp một lần và thay đổi chúng một lần vì tôi cần nhập chúng nhiều lần, nên khi thay đổi, tôi cần phải thay đổi chúng một lần chứ không phải nhiều lần.
\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}
Trả lời
Nếu bạn muốn Y1và Y2là hằng, bạn có thể sử dụng \pgfmathdeclarefunctionđể khai báo chúng dưới dạng hàm không xử lý bất kỳ đối số nào và chỉ cung cấp giá trị của hằng.
Trong ví dụ dưới đây, tôi đã sử dụng \pgfkeysđể xác định macro \DeclareConstantvà \DeclareConstants.
\DeclareConstant{⟨name of constant⟩}{⟨value of constant⟩} được sử dụng để khai báo một hằng số.
Một số hằng số có thể được khai báo qua \DeclareConstants:
\DeclareConstantsxử lý danh sách các cặp được phân tách bằng dấu phẩy :⟨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⟩,
}
Trong trường hợp bản thân giá trị của một hằng số có chứa dấu phẩy, chẳng hạn như dấu phân tách các đối số / toán hạng của một hàm pgfmath khác, giá trị đó có thể / cần được lồng trong dấu ngoặc nhọn:
⟨name of constant 2⟩={⟨value of constant 2⟩},
foobar={mod(-100,30)},
(Hằng số foobarsẽ có giá trị -10. Các mã thông báo sau =được chuyển đến \pgfmathparsetrong quá trình gán giá trị và các mã thông báo kết quả từ phép \pgfmathparsetính tạo thành giá trị của hằng số. Bằng cách này, các phép tính không được lặp lại bất cứ khi nào hằng số trong câu hỏi được sử dụng.)
!!!!! Lưu ý rằng với \DeclareConstantvà \DeclareConstantsbạn có thể dễ dàng ghi đè các hàm pgfmath hiện có. !!!!!
Vì vậy, vui lòng không khai báo một hằng số sinhoặc costương tự. ;-)
Phần "97 Tùy chỉnh công cụ toán học" của pgfmanual.pdf , sách hướng dẫn cho TikZ và pgf, nói về tên của các hàm:
Tên của hàm có thể bao gồm, chữ hoa hoặc chữ thường, số hoặc dấu gạch dưới
_. Phù hợp với nhiều ngôn ngữ lập trình, tên hàm không được bắt đầu bằng số hoặc chứa bất kỳ khoảng trắng nào .
(Dấu phẩy giả ngay sau cụm từ "có thể bao gồm" có trong sách hướng dẫn — tôi đã không xóa nó vì mục đích trích dẫn chính xác.)
Vì vậy, bạn có thể, ví dụ, xác định một hằng số / hàm Y1, nhưng bạn không thể định nghĩa một hằng số / hàm 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}